简体   繁体   English

设置路由器以担任不同角色Meteor Js

[英]Set router for different roles Meteor Js

How can I set router for different roles. 如何设置路由器的不同角色。 This is my code. 这是我的代码。 Can someone help me out. 有人可以帮我吗。

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

Assuming you use iron:router , you can achieve this several ways. 假设您使用iron:router ,则可以通过几种方法来实现。 You can set a onBeforeAction hook on a route which will redirect to the appropriate route/template with Router.go , check Hooks on the doc . 您可以在路由上设置onBeforeAction钩子,该路由将通过Router.go重定向到适当的路由/模板, 在doc上检查钩子 You should also be able to render a different template depending on your conditions: 您还应该能够根据情况呈现其他模板:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM