3

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?

3
  • Have you tried this.router.navigate(['/some-route'], queryParams ); (remove the {}) Commented Feb 8, 2017 at 10:45
  • I shouldn't do this, because of router navigate parameters: navigate(commands: any[], extras?: NavigationExtras), and extras is object witch can contains queryParams object. I can write this.router.navigate(['/some-route'], { queryParams: {ids: [1, 2, 3]} });, but I like short form. (I tried this.router.navigate(['/some-route'], queryParams ), it doesn't work) Commented Feb 8, 2017 at 10:55
  • @qweasd Please, see this one. stackoverflow.com/questions/41264722/… It is solved there. Commented Sep 8, 2017 at 15:12

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

This works the same as my case: generated params like this: ids=1%2C2%2C3. And you can write this.router.navigate(['/some-route'], { queryParams }); it is property shorthand feature and typescript support this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.