Angular 如何在刷新浏览器后保持在相同的角度页面上

Angular 如何在刷新浏览器后保持在相同的角度页面上,angular,angular6,angular7,angular2-routing,angular8,Angular,Angular6,Angular7,Angular2 Routing,Angular8,我正在开发angular应用程序。每次刷新浏览器时,应用程序都会移动到主页。有没有办法保持一致 更新:以下是应用程序的路线 export const secureRoutes: Routes = [ {path: '', component: DashboardComponent, pathMatch: 'full'}, { path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }, { path:

我正在开发angular应用程序。每次刷新浏览器时,应用程序都会移动到主页。有没有办法保持一致

更新:以下是应用程序的路线

export const secureRoutes: Routes = [
{path: '', component: DashboardComponent,  pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
{ path: 'user', component: UserComponent, canActivate: [AuthGuard] },
{ path: 'table', component: TableComponent, canActivate: [AuthGuard] },
{ path: 'typography', component: TypographyComponent, canActivate: [AuthGuard] },
{ path: 'icons', component: IconsComponent, canActivate: [AuthGuard] },
{ path: 'maps', component: MapsComponent, canActivate: [AuthGuard] },
{ path: 'notifications', component: NotificationsComponent, canActivate: [AuthGuard] },
{ path: 'upgrade', component: UpgradeComponent, canActivate: [AuthGuard] },
{ path: 'categories/new', component: AddEditCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories/view/:id', component: ViewCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories/edit/:id', component: AddEditCategoryComponent, canActivate: [AuthGuard] },
{ path: 'categories', component: CategoriesComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/view_product/:product_id',
        component: ViewProductComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/new_product', component: AddEditProductComponent, canActivate: [AuthGuard] },
{ path: 'categories/:category_id/edit_product/:product_id',
      component: AddEditProductComponent, canActivate: [AuthGuard] },
{ path: 'settings', component: SettingsComponent, canActivate: [AuthGuard] },
{ path: 'settings/edit', component: EditSettingsComponent, canActivate: [AuthGuard] },
{ path: 'users', component: UsersComponent, canActivate: [AuthGuard] },
{ path: 'users/view_client/:id', component: ClientComponent, canActivate: [AuthGuard] },
{ path: 'orders', component: OrdersComponent, canActivate: [AuthGuard], },
{ path: 'orders/:type/:id', component: OrderComponent, canActivate: [AuthGuard] },
{ path: 'adgroups', component: AdGroupsComponent, canActivate: [AuthGuard] },
{ path: 'adgroups/new', component: AddEditAdGroupComponent, canActivate: [AuthGuard] },
{ path: 'adgroups/view/:id', component: ViewAdGroupComponent, canActivate: [AuthGuard] },
{
    path: '**',
    component: PageNotFoundComponent
}
])

这也是在上述路由中使用的AuthGuard

    @Injectable()
    export class AuthGuard implements CanActivate {
      constructor(
        private router: Router,
        public afAuth: AngularFireAuth
      ) {
      }
      canActivate(): Observable<boolean> {
        return this.afAuth.authState.pipe(map((user) => {
          if (user) {
            return true;
          }
          this.router.navigate(['/login'])
          return false;
        }))
      }
    }
@Injectable()
导出类AuthGuard实现了CanActivate{
建造师(
专用路由器:路由器,
公共授权:AngularFireAuth
) {
}
canActivate():可观察的{
返回此.afAuth.authState.pipe(映射((用户)=>{
如果(用户){
返回true;
}
this.router.navigate(['/login'])
返回false;
}))
}
}

我解决了这个问题。路线还可以,但我有一个导航栏,带有语言切换功能。调用此语言开关是为了检查语言,在某些情况下,它会导航到主页


谢谢大家。

您是如何为您的应用程序提供服务的?您是从页面还是组件刷新?如果您正在从组件刷新,那么这只是一个模式,它将加载您的上一个页面,在您的案例主页中。您的路由配置是什么样子的?我更新了帖子并包含了应用程序的路由您的身份验证卫士在做什么?是否在失败时重新路由到另一个页面?