Can "canActivate" received data?
Asked Answered
M

1

7

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!

Morisco answered 9/9, 2016 at 10:46 Comment(0)
F
8
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
  console.log(route.data)
}
Footcandle answered 9/9, 2016 at 10:51 Comment(1)
Yes, it works. OMG I spent lots of time but the answer it so simple. Thank you very much!Morisco

© 2022 - 2024 — McMap. All rights reserved.