我想要保护像这样的路线:1). loggedin user group routes 2.) admin routes, 3.) student routes, 4.) public routes
。 LoggedInUser
按预期工作,但其他两种路线 - schooladmin
和students
不按需要工作。以管理员或学生身份登录后,根据预期,各个用户应该能够访问允许的URL,但无论何时,例如,如果学生管理员转到http://localhost/students,它会自动重定向回仪表板,并且同样为学生。我要做的是对的?谢谢。FlowRouter默认重定向到着陆页
此路线组仅允许登录的用户。
var LoggedInUser = FlowRouter.group({
name: 'currentUser', triggersEnter: [function (context, redirect) {
if (Meteor.loggingIn() || Meteor.userId()) {
FlowRouter.watchPathChange();
let currentRoute = FlowRouter.current();
if (!currentRoute.path) {
FlowRouter.go('/dashboard');
} else {
FlowRouter.go(currentRoute.path);
}
} else {
redirect('/');
}
}]
});
这是学校管理员路由组
var schooladmin = LoggedInUser.group({
name: 'schooladmins', triggersEnter: [function (context, redirect) {
FlowRouter.watchPathChange();
let currentRoute = FlowRouter.current();
if (Roles.userIsInRole(Meteor.userId(), ['super-admin', 'admin'])) {
console.log(currentRoute.path);
FlowRouter.go(currentRoute.path);
} else {
redirect('dashboard');
}
}]
});
这是为学生的路线
var students = LoggedInUser.group({
name: 'students', triggersEnter:[function (context, redirect) {
FlowRouter.watchPathChange();
let currentRoute = FlowRouter.current();
if (Roles.userIsInRole(Meteor.userId(), ['manage-team', 'student-page'])) {
FlowRouter.go(currentRoute.path);
} else {
redirect('dashboard');
}
}]
});
样品路由组连接到 这样的路由是学校管理员仅限访问
schooladmin.route('/students', {
name: 'students', action(){
BlazeLayout.render('formrender', {formrend: 'student'});
}
});
这条路线是学生访问
students.route('/student/dashboard', {
name: 'students-dashboard', action(){
BlazeLayout.render('studentlayout', {studentrender: 'studentdashboard'});
}
});