angular - Angular 8 canActivate on refresh
问题描述
我试图canActivate
在 angular 8 上使用(过去 2 年我一直在使用),但我似乎无法让它工作。
在刷新/f5 上,我什至看不到网络上的请求,当它进入响应时,它给了我“无法读取未定义的属性长度”
这是代码:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
const user = this.cookieSerivce.getUserCookie();
if (!this.userService.getUserIfExists().Authorization && user) {
this.userService.setUser(user);
}
return this.usersEndpointService.validateUserToken().pipe(
map((res) => {
if (!res.code) return true;
this.wrongToken();
return false;
},
}));
}
const routes: Routes = [
{path: '', component: LoginComponent},
{path: 'forgot-password', component: ForgotPasswordComponent},
{path: 'reset-password', component: ResetPasswordComponent},
{path: 'dashboard', component: DashboardComponent, canActivate: [ValidTokenService]},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
我错过了什么?我确定它甚至没有发送请求,在网络上看不到它,也没有在后端得到它,为什么?
解决方案
推荐阅读
- c# - 如何将匿名对象传递给具有多种泛型类型的泛型方法?
- r - 找出 R 中数据中的前 10 个 corr 特征
- xcode - RN ios 使用 Xcode 构建:为什么我收到这么多警告(构建时间)?
- reactjs - 我如何在反应原生输入中进行计算?
- abstract-syntax-tree - 如何表示抽象树中替换的 kleisli 组合
- javascript - 为什么要对 Symbol.iterator 使用方括号?
- google-sheets - 带有复选框的另一张工作表的条件格式
- django - 在 django 信号中,如何将发送者的类变量(模型字段)传递给接收者(management.call_command 函数)并使用它
- python - 在 grafana 中为新创建的组织获取“常规”文件夹 ID
- angularjs - “$save 不是函数”调用工作正常,但不执行 .then()