error in return value of canActivated guard

前端 未结 1 1997
温柔的废话
温柔的废话 2021-01-28 08:15

i write below code as my main page guard that use checkTokenValidation() to valid authentication token from user but my IDE show this error :A function whose declar

1条回答
  •  没有蜡笔的小新
    2021-01-28 08:59

    By subscribing you are returning a Subscription instead of an Observable. You should map to the desired values and return an Observable:

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean {
        return this.authService.checkTokenValidation().pipe(
          map( (data) => {
           if (data['ok']) {
             this.router.navigate(['/overview']);
             return false;
           } else {
             return true;
           }
         })
       );
    }
    

    0 讨论(0)
提交回复
热议问题