Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Guard, get ID Route Params

Tags:

angular

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.

like image 683
cagliostro Avatar asked Sep 03 '25 09:09

cagliostro


1 Answers

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'));
}
like image 176
funkizer Avatar answered Sep 04 '25 22:09

funkizer