Note Edit with relevant code snippets
I have run into an odd issue where I get into a infinite redirect loop when issuing a router.navigate.
Setup
- I use the hash location strategy and the app is used as an Outlook plugin.
- I have three routing rules
- "" redirect to "/login"
- "/login" mapped to LoginViewComponent
- "/foo" mapped to FooViewComponent
The LoginViewComponent has two behaviours:
- If the user's identity cannot be verified the user will be prompted for credentials
- If not redirect is issued to the FooViewComponent
The redirect is simply issued with the following bit of logic:
this.router.navigate(["foo"])
- The routes are registered as follows:
const routes: Routes = [
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "login",
component: LoginViewComponent
},
{
path: "foo",
component: FooComponentView
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true})],
exports: [RouterModule]
})
export class AppRoutingModule { }
Problem
- When I issue a redirect in the ngOnInit function of the LoginViewComponent I get into an infinite redirect loop.
- It first navigates to the FooViewComponent but then does a redirect back to the LoginViewComponent.
- As far as I can understand the redirect to the LoginViewComponent can only be made if there is a call to router.navigate([" "]) or router.navigate(["login"]). However, neither of these navigate commands are present in the FooViewComponent.