Reputation: 1648
In my component, when I try
this.router.navigate([`/courses/`, course.id], {queryParams:{description: course.description}});
After navigation, URL has description
query parameter.
But, when I try this one,
this.router.navigateByUrl(`/courses/${course.id}`, {queryParams:{description: course.description}});
URL does not have description
query parameter inside it.
Do I need to make changes to reflect my query parameter inside the URL while using navigateByUrl
? (But, Angular Documentation says that NavigationExtras
object is same for both navigate
and navigateByUrl
.)
Upvotes: 0
Views: 1271
Reputation: 2274
It seems query params are ignored by navigateByUrl
method and documentation is not clear enough. Take a look at those links for more info: link 1 link 2.
As a workaround you can try this
this.router.navigateByUrl(
this.router.createUrlTree(
['some/route'], {queryParams: myParamObject}
);
);
Upvotes: 1