I have these lines in my router:
..
canActivate: [MyGuard],
path: "search",
component: SearchComponent,
data: {
accessRoles: [roleAdmin, roleUser]
}
..
I want to limit access to SearchComponent by canActivate of MyGuard.
Is it possible to get this data array from canActivate?
Thank you in advance!
CanActivatelink If any guard returns false , navigation is cancelled. If any guard returns a UrlTree , the current navigation is cancelled and a new navigation begins to the UrlTree returned from the guard.
CanActivateChild - Decides if children routes of a route can be activated. CanDeactivate - Decides if a route can be deactivated.
The canActivate guard checks if the user can visit the specific route or we have to prevent access to that specific route. We use the this guard when we have to check some condition and based on that users have the access to reach that specific route or not, before activating the component or showing it to the user.
CanActivate. Guards are implemented as services that need to be provided so we typically create them as @Injectable classes. Guards return either true if the user can access a route or false if they can't.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
console.log(route.data)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With