qwe asd
qwe asd

Reputation: 1658

Angular 2 pass array to router queryString

I would like to pass an 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 a way to add query params with the same key?

Upvotes: 3

Views: 4885

Answers (2)

Alexander Pisarev
Alexander Pisarev

Reputation: 46

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

Upvotes: 1

Jan
Jan

Reputation: 330

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);

Upvotes: 0

Related Questions