canActivate错误的大小写在Chrome / Safari中浏览了多次

时间:2019-02-22 15:01:31

标签: angular outlook-addin office-js

我们有一个Angular 5.5 Outlook加载项(使用office.js),其路由如下:

const routes: Routes = [
  { path: 'about', component: AboutComponent, canActivate: [AuthGuardService] },
  { path: 'accounts', component: AccountsComponent, canActivate: [AuthGuardService] },
  { path: 'editInvite/:type', component: EditInviteComponent, canActivate: [AuthGuardService] },
  { path: 'login/:reason', component: LoginComponent },
  { path: 'meetings/start', component: MeetingsComponent, canActivate: [AuthGuardService] },
  { path: 'offline', component: OfflineComponent },
  { path: 'redirect/:id/noag', component: RedirectComponent },
  { path: 'redirect/:id', component: RedirectComponent, canActivate: [AuthGuardService] },
  { path: 'settings', component: SettingsComponent, canActivate: [AuthGuardService] }
];

我们的canActivate如下:

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    let hasAccount: boolean = this.credentialService.hasAccount();

    let hasData: boolean = this.clientDataService.hasData();

    if (hasAccount && hasData) {          
      return true;
    } else {
      let redirect: string = "";
      if (hasAccount) { //attempt auto-login
        redirect = "/redirect/login/noag";
      } else {
        redirect = "/login/firstLogin";
      }
      this.sharedDataService.returnToUrl = state.url;
      this.router.navigate([redirect]);

      return false;
    }
  }

在Chrome和Safari中,导航到“ / redirect / login / noag”(noag表示没有身份验证保护)会导致RedirectComponent的ngOnInit触发多次。请注意,hasAccount()和hasData()是简单的检查,不是异步的。该代码也可以在IE中完美运行。

有人对我可能会发生的事情或测试有一个猜测,我可以设法帮助我弄清楚这一点吗?

谢谢!

编辑:

将导航呼叫更改为:

this.router.navigate([redirect], { skipLocationChange: true });

导致ngOnInit()仅被调用一次,但它导致RedirectComponent(进度消息和微调框)的UI空白。

这可能与旧的Word Online加载项issue有关,但在这种情况下是Outlook加载项吗?我想到了尝试从该帖子的评论之一中跳过skipLocationChange的想法。

0 个答案:

没有答案