Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';What’meteor.startup和not_Meteor_Iron Router - Fatal编程技术网

什么';What’meteor.startup和not

什么';What’meteor.startup和not,meteor,iron-router,Meteor,Iron Router,我注意到望远镜在Meteor.startup函数中写入路由。 Meteor.startup(函数(){ Router.route('/comments/:_id'{ 名称:“评论和回复”, 模板:getTemplate('comment\u reply'), 控制器:控制器, onAfterAction:函数(){ window.queueComments=false; } }); }); 但是我只是写路由,没有使用启动函数包装。 有什么影响吗?使用Iron Router时,您应该确保您的路

我注意到望远镜在Meteor.startup函数中写入路由。

Meteor.startup(函数(){
Router.route('/comments/:_id'{
名称:“评论和回复”,
模板:getTemplate('comment\u reply'),
控制器:控制器,
onAfterAction:函数(){
window.queueComments=false;
}
});
});
但是我只是写路由,没有使用启动函数包装。

有什么影响吗?

使用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'
})

我将我的路线放在全球范围内的Meteor.startup之外。对我来说似乎是个合适的地方;在应用程序启动之前创建路由。但不知道它们之间是否有任何区别。在
启动
回调中包装代码可能是一种黑客行为,以确保在所有非启动代码之后对其进行评估。我怀疑这就是这里发生的事情。