【发布时间】:2020-09-08 15:53:37
【问题描述】:
我有以下网址:
https://localhost:4200/example/#/
当我没有像以下示例所示那样导航其他角度路线时,/example 将从 URL 中删除。生成的 URL 是 https://localhost:4200/#/firstSegment/secondSegment 而不是 https://localhost:4200/example/#/firstSegment/secondSegment
...
constructor(private router: Router) {}
....
navigate() {
this.router.navigate([`/firstSegment/secondSegment`]);
}
有一种方法可以在每次执行导航时保留# 之前的 URL 部分?
遵循我的路由器配置:
@NgModule({
.....
imports: [
.....
RouterModule.forRoot(
appRoutes,
{
enableTracing: false, // <-- debugging purposes only
useHash: true,
initialNavigation: false
}
.....
]
})
【问题讨论】:
-
哪个角版本?
-
@RafaelPizao Angular 8.
-
从 Angular 6.1 开始,可以使用片段滚动页面。您使用页面滚动还是“第二段”是一条新路线?
-
@RafaelPizao 我想一直维护的第一部分。第二部分表示 appRoutes 中定义的角度死记硬背,它将加载给定的角度组件。第一部分是对运行应用程序很重要的信息。
-
在 index.html 中设置
。
标签: javascript angular typescript angular-router