【发布时间】:2020-11-22 13:08:52
【问题描述】:
“AuthGuardService”类型中的属性“canActivate”不能分配给基类型“CanActivate”中的相同属性
export class AuthGuardService implements CanActivate {
constructor(public authService: AuthService, public router: Router) {}
async canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
Promise<boolean | UrlTree | Observable<boolean | UrlTree>> {
if (!await this.authService.chechAuthenticated()) {
this.router.navigate(['login']);
return false;
}
return true;
}
}
给出错误:
“AuthGuardService”类型中的属性“canActivate”不能分配给基类型“CanActivate”中的相同属性。
【问题讨论】:
-
不,实际上在那个问题中它不是在处理异步函数,但我的是异步
async canActivate,这就是问题所在。
标签: angular async-await