我有以下路线路径:
{
path: 'teacher',
component: DashboardTeacher, canActivate: [AccessGuardTeacher('Teacher')]
}
如您所见,我试图在类中传递参数'Teacher' AccessGuardTeacher
:
export class AccessGuardTeacher implements CanActivate {
constructor(private role: string) {
}
}
怎么做对?
您的路线应配置为:
{
path: 'teacher',
component: DashboardTeacherComponent,
canActivate: [AccessGuardTeacher],
data: {
role: 'teacher'
}
}
在您的CanActivate Guard中获取路线数据
export class AccessGuardTeacher implements CanActivate {
constructor() {
}
canActivate(route: ActivatedRouteSnapshot): boolean {
const role = route.data.role;
return true; //based on your condition
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句