Wondering if we can get the :id of a route in the guard.
Example :
{path: ':id/admin', component: AdminComponent, canActivate: [AdminGuard], data:{restricted: x}}
if User Reload I need to instantiate before some params to know if he is admin or not and de facto need the :id of this route URL I would like also to come back to url/:id if he is not allowed.
Yes, first argument of canActivate is a snapshot of the route you're currently checking.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
console.log(route.paramMap.get('id'));
}
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