我想要保護像這樣的路線: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'});
}
});