angular - 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。我怎样才能做到这一点?
解决方案
推荐阅读
- typescript - 如何在 d3 中给组元素一个唯一的 id
- javascript - 如何在另一个 javascript 文件中调用一个 javascript 文件 React js
- c++ - 打印函数中的 for(auto) 循环抛出错误,为什么?
- qt - ListView B 内的 ListView A 未在使用加载程序 qml 加载的窗口中定义
- rust - map/reduce 的交错生命周期要求
- reactjs - 如何在条件渲染中只渲染一次元素?
- kotlin - KafkaCache io.kcache.exceptions.CacheInitializationException:尝试创建或验证主题 my-topic 失败
- json - 使用 jq 作为非 json 格式化程序
- node.js - 在 npm 6 中工作的 npm 脚本在 npm 7 中失败
- java - RecyclerView 项目单击正在模拟器上工作,但在 kotlin 中的物理上却没有