I have a component registered at /contacts
, which displays a list of contacts. I've added an <input [value]="searchString">
for filtering the displayed list.
Now I'd like to display the searchString
within the URL in form of a Query Param. (Using the New Router 3.0.0 RC2)
The official docs ( https://angular.io/docs/ts/latest/guide/router.html#!#query-parameters ) show how to use router.navigate
for changing the queryParams
. But this seems awkward, because I just want to change the queryParams
without having to know which route I'm currently at: router.navigate(['/contacts'], {queryParams:{foo:42}})
(I know that it doesn't reload the component if I'm just changing the queryParams
, but still this doesn't feel right to write)
After some attempts I figured out that router.navigate([], {queryParams:{foo:42}})
works. This feels way better.
But I'm still not sure if that's the right way. Or if I missed some method for this.
How do you change your queryParams
?