Angular 2 get current route in guard

后端 未结 3 936
北海茫月
北海茫月 2020-12-25 12:16

I have an AccessGuard class in my project which its work is to determine if user can access to the route or not. I used the router.url to get the current route

3条回答
  •  有刺的猬
    2020-12-25 12:29

    You need to use the method parameters to see the target route:

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      console.log(state.url);//'candidates'
    }
    
    canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot)
    

提交回复
热议问题