2

I'm trying to navigate including query params:

this.router.navigate(['/forum/topic/1', { queryParams: { reply: 5 } }]);

But it redirect me to /forum/topic/1;queryParams=%5Bobject%20Object%5D

Expected behavior:

/forum/topic/1?reply=5

Looking at the document I see they edit the params because I see it's separate with ;

localhost:4200/heroes;id=15;foo=foo

What are they doing ?

1) How can I fix the redirection, I think the function is fine...

2) I don't want ;, I want classic ? and &, is it possible ?

5
  • just use this.router.navigate(['/forum/topic/1?reply=5']);? it worked when i tried it in angular 4 i believe, so it should still work in 6 and 7, whichever youre using Commented Mar 5, 2019 at 15:51
  • I tryed but I get forum/topic/1%3Freply%3D5 Commented Mar 5, 2019 at 15:52
  • in which case, its encoding it for some reason Commented Mar 5, 2019 at 15:54
  • Possible duplicate of How to pass query parameters with a routerLink in the new Router V 3 alpha (vladivostok) Commented Mar 5, 2019 at 16:13
  • Possible duplicate of router.navigate with query params Angular 5 Commented Mar 5, 2019 at 16:14

1 Answer 1

3

I think you have a typo. Look at parenthesis. Try this:

this.router.navigate(['/forum/topic/1'], { queryParams: { reply: 5 } });
Sign up to request clarification or add additional context in comments.

Comments

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.