在 URL 中,当在 Angular 中路由时使用 queryParams 时,`%` 被替换为 `%25`

In URL `%` is replaced by `%25` when using `queryParams` while routing in Angular

我想在 Angular 中使用 queryParams 导航到 URL。

<a routerLink='/master' [queryParams]="{query:'%US',mode:'text'}"><li (click)="search()">Search</li></a>

我想导航的 URL 是:

http://localhost:4200/master?query=%US&mode=text

但是当我点击搜索时,它会将我导航到:

http://localhost:4200/master?query=%25US&mode=text

不知道为什么在%符号后加了25。谁能告诉我更简洁的正确导航方式。

在网址中,百分号具有特殊的含义,用于对特殊字符进行编码。例如,= 被编码为 %3D.

url 中不允许使用某些特殊字符。如果你想在 url 中使用它们,你必须使用 encodeURIComponent javascript 函数对它们进行编码。 %25 实际上是 % 字符的编码版本。此处浏览器自行编码。

当尝试从 url 获取 queryParams 时,您可以使用 decodeURIComponent 对其进行解码。

更多信息请查看:https://support.microsoft.com/en-in/help/969869/certain-special-characters-are-not-allowed-in-the-url-entered-into-the

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent