I want to get boolean for canActivate() method but nothing is working. My code is:
login() {
return this.http.get<any>('http://localhost/auth');
}
and I want to do somthing like this:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.authenticationService.login().subscribe(
() => true,
() => false
);
}
What is the correct way to do this?
You don't need to subscribe in a
canActivate
method from a route Guard : In fact, Guard can return Observable and Angular will subscribe to it.Just use rxjs
map
operator, such as :See more here