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

时间:2015-12-23 07:32:32

标签: javascript meteor router

如何为不同的角色设置路由器。这是我的代码。有人可以帮助我。

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

1 个答案:

答案 0 :(得分:0)

假设您使用iron:router,您可以通过以下几种方式实现。 您可以在路线上设置onBeforeAction挂钩,该挂机将使用Router.gocheck Hooks on the doc重定向到相应的路线/模板。 您还应该能够根据您的条件渲染不同的模板:

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