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?
/contacts/:search-queryin your router file and observe it in your component for changes?queryParamsas well, that's not the problem....My current component has about 20 search parameters, most of them are optional and some of them exclude each other. When the user changes any parameter, the displayed list will get filtered, and additionally I want to reflect these parameter changes within the URL....The question was just about "What's the right way to set thequeryParams?" or "Isrouter.navigate([], ...)the only/correct way?"