我正在尝试为登录实现身份验证并获得以下错误:
A function whose declared type is neither 'void' nor 'any' must return a value.
代码:
this.isLoggedIn = false;
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean>{
let url: string = state.url;
return this.checkLogin(url);
}
checkLogin(url: string): Observable<boolean> {
this.authService.isUserLoggedIn()
.map(
data => {
// getting true or false as loggedIn value
this.isLoggedIn = data.loggedIn;
if (this.isLoggedIn) {
return true;
}
// Redirect on home page with login popup.
this.router.navigate(['/']);
return false;
});
}
无法弄清问题是什么。