我有一个流星应用程序和软件包iron-router
,我试图阻止所有的页面,如果用户没有连接,除了fews页面。如果没有具体说明,我们就进入登陆页面。所以在router.js文件中,我有:
Router.onBeforeAction(function() {
if (!Meteor.userId()) {
Router.go('login');
} else {
this.next();
}
}, {
except: [
"login", "landing", "register", "forgotPassword"
]
});
Router.route('/', function () {
Router.go('landing');
});
但是当我使用localhost:3000/
时,我被重定向到登录页面,而不是登陆页面。
如果我删除了onBeforeAction函数,我将重定向到登陆页面。所以这两个函数肯定有问题,但我不知道在哪里。也许我需要在例外情况下精确说明"/“,但它不起作用。你有什么主意吗?
发布于 2017-02-22 10:44:36
您也需要在异常中定义路由'/'
,否则这将被onBeforeAction
捕获。
尝试重新定义如下
Router.onBeforeAction(function() {
if (!Meteor.userId()) {
Router.go('login');
} else {
this.next();
}
}, {
except: [
"default", "login", "landing", "register", "forgotPassword"
]
});
Router.route('/', function () {
Router.go('landing');
}, {
name: "default"
} );
在这种情况下,您可以命名路由,然后将其添加到异常列表中。
https://stackoverflow.com/questions/42396259
复制