【发布时间】:2014-08-29 22:41:07
【问题描述】:
我有一个使用 Iron 路由器的流星应用程序。每次我刷新浏览器或输入像http://localhost:3000/gigs 这样的网址时,我的应用程序都会刷新回http://localhost:3000 的基本网址
这是我的 router.js 代码
var requireLogin = function() {
if (!Meteor.user() && !Meteor.loggingIn()) {
Router.go('signIn');
this.stop();
}
};
Router.configure({ loadingTemplate: 'loading' });
Router.before(requireLogin, {only: ['tasks', 'gigs']});
Router.map(function() {
this.route('tasks', {
path: '/',
waitOn: function() { return [ Meteor.subscribe('projects'), Meteor.subscribe('tasks') ] },
layoutTemplate: 'twoColMenuLayout',
template: 'tasksList',
yieldTemplates: {l
'taskDetail': {to: 'rightTemplate'}
},
data: {
moduleName: 'projects'
}
});
this.route('gigs', {
path: '/gigs',
waitOn: function() { return [ Meteor.subscribe('gigs') ] },
layoutTemplate: 'twoColMenuLayout',
template: 'gigsList',
yieldTemplates: {
'gigDetail': {to: 'rightTemplate'}
},
data: {
moduleName: 'gigs'
}
});
this.route('gigSubmit', {
path: '/gig-submit',
layoutTemplate: 'oneColMenuLayout',
template: 'gigSubmit',
data: {
pageTitle: 'New Gig'
}
});
this.route('signIn', {
path: '/signIn',
layoutTemplate: 'blankLayout',
template: 'signIn'
});
});
奇怪的是,如果我将“tasks”路径更改为“/tasks”而不是“/”,则不会出现此问题,并且可以正常工作。但是,当我这样做时,我会收到一条控制台错误消息,指出未定义“/”。它似乎没有破坏任何东西,但我讨厌控制台中出现错误。
我还尝试将“任务”地图移到底部,以防它首先匹配到这个地图并且总是去那里,但这并没有什么不同。
知道为什么会这样吗?
谢谢!
【问题讨论】:
-
我认为 layoutTemplate 应该只在 .map() 函数中。
-
Iron Router 文档显示 layoutTemplate 可以像在我的示例中一样使用 github.com/EventedMind/iron-router#using-a-layout-with-yields 所以我认为这不是问题。
-
我也遇到了同样的问题,你解决了吗?
标签: meteor iron-router