访问 Angular 2 应用程序的路由时如何在 URL 中保留查询字符串参数? [英] How to keep query string parameters in URL when accessing a route of an Angular 2 app?
问题描述
我有一个运行最新 alpha (37) 的 Angular 2 测试应用程序.只有三个路线,看起来像这样:
I have an Angular 2 test app running the latest alpha (37). There are just three routes, that look like this:
@RouteConfig([
{ path: '/', component: Home, as: 'home' },
{ path: '/errors', component: Errors, as: 'errors' },
{ path: '/about', component: About, as: 'about' }
])
我可以访问路由,当我在 URL 中放置查询字符串参数时,我可以很好地读取它们.但是,在我读取参数后不久,我注意到路由加载正常并且 URL 刷新,删除了查询字符串参数.
I can access the routes, and when I place query string params in the URL I can read them just fine. However, a few instants after I read the parameters, I noticed that the route loads fine and the URL refreshes, removing the query string parameters.
换句话说,访问这条路线:
In other words, accessing this route:
http://localhost:5555/errors?test=abc强>
加载 /errors
路由,但在应用程序加载后,URL 变为:
Loads the /errors
route, but right after the application loads the URL turns into:
这会让用户感到困惑.我想在 URL 中保留查询字符串参数.
That would be confusing to a user. I would like to keep the query string parameters in the URL.
我知道,它是 alpha 版,但这是一个错误还是我忘记在路由器上设置一些东西?如何在 URL 中保留任何查询字符串参数?
I know, it's in alpha, but is this a bug or I forgot to set something up on the router? How can I keep whatever query string parameters in the URL?
谢谢!
推荐答案
此问题已在 Alpha 41 中修复.查询字符串现在已保留.
This is fixed in Alpha 41. The query string is now persisted.
这篇关于访问 Angular 2 应用程序的路由时如何在 URL 中保留查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!