we can put a console.log in the canActivate Method, to monitor the ActivateRouteSnapshot in Angular 9
console.log("the name of route: " + destination.routeConfig.component.name);
in Angular 6
you can access it from route.component.name
here is the sample code
import { Injectable } from "@angular/core";
import { CanActivate, Router, ActivatedRouteSnapshot,
RouterStateSnapshot } from '@angular/router';
@Injectable()
export class longinGuard implements CanActivate{
constructor(private router: Router){
}
canActivate(destination: ActivatedRouteSnapshot, state: RouterStateSnapshot){
console.log("the name of route navigate to: " +
destination.routeConfig.component.name);
}
}
No comments:
Post a Comment