I want to create a route guard with canActive method and response after a few seconds. I use this:
export class GuardService implements CanActivate {
constructor(private router: Router,
private UserInfo: UserInfoService) { }
canActivate(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
setTimeout(() => {
this.router.navigate(['/']);
return false;
}, 2000);
}
}
So this function is returning a false after 2 seconds. I expect to work properly but angular didn't compile the code and return the following error:
ERROR in src/app/services/guard.service.ts(14,44): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
it says the canActive should return a boolean, not in setTimeOut, But my guard is an async guard and responding with delay is ok.