Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 627
CodyBugstein Avatar asked Nov 16 '17 21:11

CodyBugstein


1 Answers

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.

like image 113
CodyBugstein Avatar answered Sep 20 '22 13:09

CodyBugstein