我有一个使用铁路由器的流星应用程序。每次我刷新浏览器或输入一个 url 就像http://localhost:3000/gigs
我的应用程序刷新回刚刚的基本 urlhttp://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' 而不是 '/',则不会发生此问题,并且它可以按我的预期工作。但是,当我这样做时,我会收到一条控制台错误消息,指出未定义“/”。它似乎没有破坏任何东西,但我讨厌控制台中出现错误。
我还尝试将“任务”地图移动到底部,以防它首先匹配这个地图并且总是去那里,但这并没有什么不同。
知道为什么会这样吗?
谢谢!