The angular2 documentation about Route Guards left me unclear about when it is appropriate to use a CanActivate guards vs. a CanActivateChild guard
I also confused the angular2's documentation about routeGuard.
what's the difference between the CanActivate guard and
CanActivateChild guard.
I have some findings,I hope this will help you.
in the auth-guard.service.ts file
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let url: string = state.url;
return this.checkLogin(url);
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(route, state);
}
because the canActivate method is called in the canActivateChild function. you can write a snippet of code that don't call the canActivate method in the canActivateChild function.