访问Angular 2应用的路由时如何在URL中保留查询字符串参数? [英] How to keep query string parameters in URL when accessing a route of an Angular 2 app?

查看:98
本文介绍了访问Angular 2应用的路由时如何在URL中保留查询字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行最新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

http://localhost:5555/errors?test=abc

加载/errors路由,但是在应用程序加载URL之后立即变为:

Loads the /errors route, but right after the application loads the URL turns into:

http://localhost:5555/errors

http://localhost:5555/errors

这会使用户感到困惑.我想将查询字符串参数保留在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆