我有一个带有编辑器页面的 Meteor 应用程序,只有编辑器才能访问。我正在使用 Iron-Router,我的 Router.map 如下所示。然而,这并不是以一种奇怪的方式工作。如果我提供了编辑器页面的链接,那么一切都很好,但是如果我尝试输入 /editor url,那么即使用户角色设置正确,它也会始终重定向到主页。
(我排除的一件事是如果 Meteor.userId() 在之前调用 Roles.userIsInRole 之前没有设置。)
有谁知道为什么会这样?
Router.map(function() {
...
this.route('editor', {
path: '/editor',
waitOn: function() {
//handle subscriptions
},
data: function() {
//handle data
},
before: function() {
if ( !Roles.userIsInRole(Meteor.userId(), 'editor') ) {
this.redirect('home');
}
}
});
...
});