为不同角色设置路由器 Meteor Js

Set router for different roles Meteor Js

如何为不同的角色设置路由器。这是我的代码。谁能帮帮我。

if (Roles.userIsInRole(['admin'])) {
    Router.go('/addItem');
}
else {
    Roles.userIsInRole(['admin-category'])
    Router.go('/AddCategory');
}

假设您使用 iron:router,您可以通过多种方式实现。 您可以在路由上设置一个 onBeforeAction 挂钩,它将使用 Router.gocheck Hooks on the doc 重定向到适当的 route/template。 您还应该能够根据您的条件呈现不同的模板:

if (Roles.userIsInRole(Meteor.userId(), ['admin'])) {
    this.render('addItem');
} else if Roles.userIsInRole(Meteor.userId(), ['admin-category']) {
    this.render('addCategory');
} else {
    this.render('defaultRoute');
}