Angular Router usehash:导航不保留hastag之前的URL

问题描述

我有以下网址:

id

当我不导航其他有角度的路线时(如以下示例所示),https://localhost:4200/example/#/ 从URL中删除生成的URL是/example而不是https://localhost:4200/#/firstSegment/secondSegment

https://localhost:4200/example/#/firstSegment/secondSegment

有一种方法可以在每次执行导航时在... constructor(private router: Router) {} .... navigate() { this.router.navigate([`/firstSegment/secondSegment`]); } 之前保留URL部分吗?

按照我的路由器配置:

#

解决方法

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

function reverseNumberFormat(num) {
  return num.replace(/,/g,"");  // => Nb: conversion not necessary
}

更多详细信息 https://angular.io/guide/workspace-config