Angular 2 pass array to router queryString

杀马特。学长 韩版系。学妹 提交于 2019-12-22 12:23:30

问题


I would like pass array ids: [1, 2, 3] to router query string like this: http://...some-url?ids=1&ids=2&ids=3, but when I try to use

const queryParams = { ids: [1, 2, 3] };
this.router.navigate(['/some-route'], { queryParams });

the result is http://...some-url/some-route?ids=1%2C2%2C3

Is there way to add query params with same key?


回答1:


Looks like there is a bug in the router. Please, check this answer: https://stackoverflow.com/a/42505212/7634393




回答2:


router.navigate is waiting for a named 'queryParams' value.

So, this should work.

const queryParams = { ids: [1, 2, 3] };
this.router.navigate(['/some-route'], { queryParams: queryParams });

Or,

const extras = { queryParams: { ids: [1, 2, 3] }};
this.router.navigate(['/some-route'], extras);


来源:https://stackoverflow.com/questions/42110820/angular-2-pass-array-to-router-querystring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!