Search code examples
angularangular-routingangular-routerangular-router-guards

When refreshing Angular app, it ignores current URL and goes back to root URl


If my Angular app, if I navigate (via explicitly typing in the URL or clicking a page link to it) to http://localhost:4200/#/sign-in the page loads fine and shows my sign in form. If I then click Refresh in my browser, I am taken back to the root page http://localhost:4200/#/.

My router is simple:

export const routes: Route[] = [
  { path: 'sign-up', component: SignUpComponent},
  { path: 'sign-in', component: SignInComponent},
  { path: 'admin', loadChildren: 'app/admin/admin.module#AdminModule'},
  { path: 'dashboard', loadChildren: 'app/user/user.module#UserModule', canActivate: [ UserLoggedInGuard ]},
  { path: '', pathMatch: 'full', component: HomeComponent},
  { path: '**', pathMatch: 'full', component: PageNotFoundComponent},
]

I am using

  • Windows 8
  • Chrome 62
  • @angular/core": "^4.2.4
  • @angular/router": "^4.2.4

Any ideas why this is happening?


Solution

  • The problem ended up being some code I had in my app.component.ts that checked if the user was logged in and if not, navigated to the home page.