1

I am trying to use this syntax to navigate with queryParams following the accepted answer in here: Sending data with route.navigate in Angular 2

this.router.navigate(['add', { queryParams: { type: $event.value } }], { relativeTo: this.route });

However instead of: .../add?type=someEventValue

this results in the optional parameters (aka matrix notation)

.../add;queryParams=%5Bobject%20Object%5D

What am I doing wrong? Is there a way to enforce the old style of search parameters in Angular 4.3.x router?

user776686
  • 7,933
  • 14
  • 71
  • 124

2 Answers2

0

If you add optional parameters to the root route, you'll get ?param=value, if you add it to a child route, you'll get ;param=value.

Angular needs this to distinguish which route params belong to.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

The queryParams object should be a part of the second argument that you pass when you call the navigate function.

What you should do is the following:

this.router.navigate(['add'], { queryParams: { type: $event.value }, relativeTo: this.route });