首页 > 解决方案 > Angular - 重定向到 index.html

问题描述

我有 Angular 7 应用程序,我想在超时后重定向到登录页面(但在 URL 中显示 /index.html 而不是 /login)。

在整个应用程序中,我不想在 URL 中显示相对路径,而只是在所有页面的重定向上显示 /index.html(由于应用程序的设计)。

所以,我正在使用skipLocationChange: true这个。

app.routing.ts:

const appRoutes: Routes = [
  { path: 'login', component: LoginComponent },
  { path: 'reset-password', component: ResetPasswordComponent },
  {
    path: 'dashBoard',
    component: DashboardComponent,
    children: [
      { path: 'profile', component: ProfileComponent },
      { path: 'account', component: AccountComponent },
    ]
  },
  { path: '**', redirectTo: 'login' },
];

我使用以下方法从 Login 组件重定向到 ProfileComponent:

this.router.navigate(['dashBoard/profile'], { skipLocationChange: true })

在个人资料和帐户组件中,计时器到期后,我正在执行以下操作:

this.router.navigate(['/login'], { skipLocationChange: true });

这使应用程序重定向到登录页面,但在 URL 中显示 /dashBoard/profile。

那么,首先,当我提到 skipLocationChange: true 时,为什么 URL 会更改为 /dashBoard/profile ?

然后我尝试了:

this.router.navigate(['/index.html'], { replaceUrl: true });

这使应用程序重定向到登录页面,但在 URL 中显示 /login。

从 /dashBoard/profile 重定向后,我想在 URL 中显示 /index.html。我怎样才能做到这一点?

标签: angularroutingangular-router

解决方案


推荐阅读