Search code examples
angularangular2-routingangular2-guards

Can "canActivate" received data?


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!


Solution

  • canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      console.log(route.data)
    }