刷新 Angular 应用程序时,它会忽略当前 URL 并返回根目录 URl

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

如果我的 Angular 应用程序,如果我导航(通过明确输入 URL 或单击页面 link )到 http://localhost:4200/#/sign-in 页面加载正常并显示我的登录表格。如果我随后在浏览器中单击 刷新,我将返回到根页面 http://localhost:4200/#/

我的路由器很简单:

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

我正在使用

知道为什么会这样吗?

问题最终出在我 app.component.ts 中的一些代码,这些代码检查用户是否已登录,如果没有,则导航到主页。