管理员登录后如何访问其他页面。单击其他链接时始终显示仪表板页面。你能检查一下我的代码吗?
Router.onBeforeAction(function() {
if (!Meteor.user()) {
this.render('login');
} else {
this.render('dashboard');
}
});
Router.route('users', function() {
this.render('users');
});
Router.route('orders', function() {
this.render('orders');
});
注意:当我单击用户和订单的链接时,它会显示仪表板。
最佳答案
因为它被 onBeforeAction
拦截,所以你应该这样做:
编辑:使用https://github.com/alanning/meteor-roles你需要:
Router.onBeforeAction(function() {
if (!Roles.userIsInRole(Meteor.user(), ['admin'])) {
if (!Meteor.user()) {
this.render('login');
} else {
this.render('dashboard');
}
}
});
因此,如果用户是管理员,它将传递 onBeforeAction
并获取下一个有效路由
关于javascript - 管理员登录后如何访问网站的其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32066645/