由于jwt检查,AngularCLI重复重新加载主页

由于jwt检查,AngularCLI重复重新加载主页,angular,authentication,jwt,Angular,Authentication,Jwt,我有一个结合了多个应用程序登录的应用程序,所以在检查jwt时,我需要指向autologin以路由到特定的应用程序 第一次启动应用程序时,localStorage中没有jwt。这是应用程序需要重定向到后端登录url的信号。但是,此jwt检查仅在NgInit之后执行,此时页面已经加载,并且第二次加载。我需要确保在输入url后尽快验证本地存储中的jwt,如果jwt不存在,则重定向到另一个页面以防止再次加载该页面 const jwt = this.authenticationService.getJwt

我有一个结合了多个应用程序登录的应用程序,所以在检查jwt时,我需要指向autologin以路由到特定的应用程序

第一次启动应用程序时,localStorage中没有jwt。这是应用程序需要重定向到后端登录url的信号。但是,此jwt检查仅在NgInit之后执行,此时页面已经加载,并且第二次加载。我需要确保在输入url后尽快验证本地存储中的jwt,如果jwt不存在,则重定向到另一个页面以防止再次加载该页面

const jwt = this.authenticationService.getJwt();
if (jwt !== null && jwt !== undefined && jwt !== '' && jwt.length > 10) {
  // jwt is set, we can redirect to private part
  this.router.navigate(['/private']).then();
} else if (jwt === null || jwt === undefined) {
  // jwt is not available
  window.location.href = environment.loginApiUrl + '/autologin/' + environment.appUuid + '?ref=' + this.router.url.substr(1);
}
我尝试使用app_初始值设定项,但路由在那里不起作用