Angular 2 get current route in guard

后端 未结 3 965
北海茫月
北海茫月 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:47

    Current URL can be returned from RouterStateSnapshot as shown below,

        import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';    
    
        canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot){
          console.log(state.url);  
          ...
        }
    

提交回复
热议问题