Issue
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?
Solution
Angular 14+ Solution
{
path: 'edit',
component: Cmp,
canActivate: [
() =>
inject(Service).hasUserPermissions(['WRITE_SOMETHING'])
? true
: inject(Router).parseUrl('/goSomewhere'),
],
},
Answered By - Valentin Bossi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.