I have the following route path:
{
path: 'teacher',
component: DashboardTeacher, canActivate: [AccessGuardTeacher('Teacher')]
}
As you can see I tried to pass parameter 'Teacher' in class AccessGuardTeacher
:
export class AccessGuardTeacher implements CanActivate {
constructor(private role: string) {
}
}
How to do that right?
Angular 14+ Solution
{
path: 'edit',
component: Cmp,
canActivate: [
() =>
inject(Service).hasUserPermissions(['WRITE_SOMETHING'])
? true
: inject(Router).parseUrl('/goSomewhere'),
],
},