Search code examples
angularwebpackangular2-routing

How to get current route in canActive route?


I want to restrict route as per role. I want to check whether navigated route does have permission to access page or not in my canActivate method. But, this.router.url this giving me previous route instead of current navigated route.


Solution

  • Using route: ActivatedRouteSnapshot can solve you problem:

    canActivate(route: ActivatedRouteSnapshot) {
          console.log(route.url);
    
          ...
    }
    

    You can see full spec here for the ActivatedRouteSnapshot object: