【问题标题】:What's the difference between writing routes in meteor.startup and not在meteor.startup和not中写路由有什么区别
【发布时间】:2014-12-20 03:19:07
【问题描述】:

我注意到 Telescope 在 Meteor.startup 函数中写入路由。 Meteor.startup( function () { Router.route('/comments/:_id', { name: 'comment_reply', template: getTemplate('comment_reply'), controller: CommentPageController, onAfterAction: function() { window.queueComments = false; } }); }); 但是我只是写了路由,没有使用封装的启动函数。
有影响吗?

【问题讨论】:

  • 我把我的路线放在Meteor.startup之外的全局范围内。对我来说似乎是正确的地方;在应用程序启动之前创建路由。不过不知道有没有区别。
  • startup 回调中包装代码可以确保在所有非启动代码之后对其进行评估。我怀疑这就是这里发生的事情。

标签: meteor iron-router


【解决方案1】:

使用 Iron-Router 时,您应该确保您的路线始终可用。因此,您可以将它们包装到启动函数中或将它们放入 /lib。 将它们放入 /lib 时,两个环境都可以使用路由。

最佳实践(根据 Discover Meteor)是 lib 文件夹中名为 router.js 的文件:

/lib/router.js:

Router.configure({
  layoutTemplate: 'layout' //the layoutTemplate for all routes will be 'layout'
  //options for every route
});

Router.route('/home', {
  //options for the route with the path '/home'
})

More Information

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 2020-11-06
    • 2019-04-16
    • 2016-07-17
    • 2011-05-09
    • 2014-06-29
    • 2011-01-21
    相关资源
    最近更新 更多