[英]Angular Router usehash: navigate is not preserve the url before the hastag
I have the following URL:我有以下网址:
https://localhost:4200/example/#/
When I navigate no another angular route like the following example shows, the /example
is erased from the URL.当我没有像以下示例所示那样导航其他角度路线时,
/example
将从 URL 中删除。 The resulting URL is https://localhost:4200/#/firstSegment/secondSegment
instead of https://localhost:4200/example/#/firstSegment/secondSegment
生成的 URL 是
https://localhost:4200/#/firstSegment/secondSegment
而不是https://localhost:4200/example/#/firstSegment/secondSegment
...
constructor(private router: Router) {}
....
navigate() {
this.router.navigate([`/firstSegment/secondSegment`]);
}
There is a way that I could preserve the URL part before the #
each time I perform the navigation?有一种方法可以在每次执行导航时保留
#
之前的 URL 部分?
Follows my router config:遵循我的路由器配置:
@NgModule({
.....
imports: [
.....
RouterModule.forRoot(
appRoutes,
{
enableTracing: false, // <-- debugging purposes only
useHash: true,
initialNavigation: false
}
.....
]
})
For the default route, you need to set the prefix to angular.json对于默认路由,您需要将前缀设置为angular.json
...
"projects": {
"app-name": {
"prefix": "example",
...
}
...
More details https://angular.io/guide/workspace-config更多细节https://angular.io/guide/workspace-config
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.