问题描述
我需要使用查询参数(例如/Questions?id=1234&pageid=0
)设置网址.我已经尝试通过router.Navigate['/Questions?id=1234&pageid=0']
来做到这一点,但是没有运气.
I have a requirement to set a url with query parameters like /Questions?id=1234&pageid=0
. I have tried to do it via router.Navigate['/Questions?id=1234&pageid=0']
but no luck.
导航后,浏览器显示为/Questions%3Fid%3D1234%26pageid%3D0
.
After navigation browser shows like /Questions%3Fid%3D1234%26pageid%3D0
.
我也尝试了设置routerLink="/Questions?id=1234&pageid=0"
的方法,但结果相同.
I have also tried it with setting routerLink="/Questions?id=1234&pageid=0"
, but same result.
请提出解决方案的建议.我正在对 angular2 使用 rc5 .
Please suggest any solution to do it.I am using rc5 for angular2.
推荐答案
我找到了一种解决方案,将路由器链接和查询参数分开,如下所示:
I found one solution by giving router-link and query-parameters separate, like below:
<a [routerLink]="['/Questions']" [queryParams]="{id:1234,page:1}"></a>
这对我来说很好.
这篇关于如何设置查询参数到URL Angular2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!