0

We have an Angular 5.5 Outlook add-in (uses office.js) with routes as follows:

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] }
];

Our canActivate is as follows:

  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;
    }
  }

In Chrome and Safari the navigate to "/redirect/login/noag" (noag stands for no auth guard) causes the ngOnInit of the RedirectComponent to trigger multiple times. Note that hasAccount() and hasData() are simple checks and are not async. Also the code works perfectly in IE.

Does anyone have a guess about what could be happening or tests I can try to help me figure this out?

Thanks!

EDIT:

Changing the navigate call to:

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

results in the ngOnInit() to be called just once, but it causes the UI for the RedirectComponent (A progress message and a spinner) to be blank.

Could this be related to this old Word Online add-in issue but in this case occurring for an Outlook add-in? I got the idea to try skipLocationChange from one of the comments for that post.

Carbo
  • 319
  • 3
  • 13

0 Answers0