I have a canActivate guard on one of my route.
canActivate(): boolean {
if(this.isLogged()) {
return true
}
else {
this._router.navigate(['/login'])
return false
}
}
So, I can only activate it if I am logged in. If I am not, I do want to navigate back to the login page. So I did add : this._router.navigate(['/login'])
It seems to work, but I am not sure if this is the right way to proceed. I have seen a couple of stuff using injectors (Redirect to a different component inside @CanActivate in Angular2) but these are pretty old posts. I am in Angular 2.4.1.