javascript - Angular Router usehash:导航不保留hastag之前的url
问题描述
我有以下网址:
https://localhost:4200/example/#/
当我没有像以下示例所示那样导航其他角度路线时,/example
将从 URL 中删除。生成的 URLhttps://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",
...
}
...
推荐阅读
- python - 有没有更好的方法来跟踪 Python 中的浮点输入?
- function - Powershell 函数复制项错误异常与 2 个参数
- node.js - NodeJS HTTPS 模块可以通过它的 get 方法同时发出 http 和 https 请求吗?
- python - Pytorch - 如何为 DataLoader 手动规范化/转换数据
- mysql - 通过将今天凌晨 4 点到第二天凌晨 4 点视为这一天来分组(我的 SQL)
- d3.js - d3.js - 插入到组元素时表格部分可见
- nginx - NGINX Proxy by Path AND Retain Payload & QueryString
- jquery - 使用 JQuery 查找国家/地区首选日期格式
- ios - 如何通过nexus代理代理存储在gitlab中的ios依赖项
- javascript - 使用嵌套级别的对象和数组动态更新状态