繁体   English   中英

Angular Router usehash:navigate 不保留hastag之前的url

[英]Angular Router usehash: navigate is not preserve the url before the hastag

我有以下网址:

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
      }
     .....
   ]

})

对于默认路由,您需要将前缀设置为angular.json

...
"projects": {
    "app-name": {
      "prefix": "example",
    ...
}
...

更多细节https://angular.io/guide/workspace-config

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM