How to set query parameters to url Angular2?

心已入冬 提交于 2019-12-03 01:23:51

You can pass them as item in the router, but outside the commands array:

[routerLink]="["/Questions"], {queryParams: {id:1234, pageid:0}}"

this generates what you want: /Questions?id=1234&pageid=0

Or you can use it programmaticaly:

this.router.navigate(['/Questions'], { queryParams: {id:1234, pageid:0} })

with router being an instance of @angular/router's Router

amit_chauhan

I found one solution by giving router-link and query-parameters separate, like below:

<a [routerLink]="['/Questions']" [queryParams]="{id:1234,page:1}"></a>

This is working fine for me.

You can pass them as items in the router commands array:

[routerLink]="['/Questions'] [queryParams]="{id:1234, pageid:0}} ]"

See also https://angular.io/docs/ts/latest/guide/router.html#!#query-parameters

Volodymyr Khmil

You need to update your router.navigate

this.router.navigate(['/Questions', {id: 1234, pageid: 0}]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!