问题描述
用户使用参数调用应用程序的 url 并使用我的应用程序.在不同路由之间切换时,url 参数应该在浏览器的地址栏中保持可见.
The user calls the app's url with the parameters and uses my app. While switching between different routes the url parameters should be kept visible in the browser's address bar.
我必须在我的应用程序的每个路由上保留查询参数.这意味着如果我有网址
I have to keep the query parameters on each route of my app. That means if I have the url
www.example.com/app/test?id=326748798342&state=1
并调用带有 [routerLink]="['/login']"
的链接我必须得到这个网址:
and call a link with [routerLink]="['/login']"
I have to get this url:
www.example.com/app/login?id=326748798342&state=1
.
默认情况下,我获得不带参数的登录路由.我找到了一种解决方案,说要设置 queryParamsHandling='merge'
.但这是一个非常糟糕的解决方案,因为这意味着要更改模板中的所有链接和所有 navigate() 调用.
On default I get the login route without the parameters. I found one solution that says to set queryParamsHandling='merge'
. But this is a very bad solution because that would mean to change all links in templates and all navigate() calls.
默认情况下有没有更简洁的方法来解决这个问题?在应用程序的路由数组中设置 queryParamsHandling 之类的东西还是其他什么?
Is there a cleaner way to solve this problem on default? Something such setting queryParamsHandling in the routes array for the app or something else?
推荐答案
目前没有办法全局设置.使用 queryParamsHandling
似乎是唯一的选择:
Currently there is no way to set it globally. Using queryParamsHandling
seems to be the only option:
<a [routerLink]="['/login']" queryParamsHandling="preserve"></a>
或者当使用路由器时:
router.navigate('/login', { queryParamsHandling: "preserve" })
queryParamsHandling
的另一个可能选项是 merge
.
The other possible option for queryParamsHandling
is merge
.
这篇关于默认情况下,如何在所有路由上将查询参数保持在 5 角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!