I am trying to reset query parameters for a search page in my app, but navigation to the page is caching query params. I understand this is the default behavior, and it can be reset in various ways (this Github issue which poses a possible solution, as well as the guide page). However, the existing solutions I have found are leaving a lot to be desired.
My search page takes a large number of parameters (?address=xx&city=xx&state=xx…), therefore resetting the query params in every link-to
is out of the question. I have global navigation links which shouldn’t use the cached query params. For example, clicking the “Search” link should give you a blank search page, which is pretty common functionality on the web.
I tried resetting each query param property in the resetController
hook on the route, but I end up with a bunch of blank query params (?address=&city=&state=…) in my url, which works, but is ugly. Clearing the query params with a transitionTo
results in the same long url with blank params.
Ideally, calling transitionTo({ queryParams: { address: 'foo' } })
should clear all other query params, and set only address, but it is instead just updating the address param, and leaving the rest as-is. Am I the only one who finds this very unintuitive and undesireable?
I don’t doubt that this behavior helps some scenarios. However, this is an area where Ember is making it difficult to do something that was once trivial, and seems to go against typical behavior of web applications.
Ideally, I’m looking for the following:
-
An explanation of why this behavior (caching query params) was implemented as the default. A link to an existing discussion would be great.
-
A solution that will give me clean URLs with only query params that are provided.
-
A simple way to clear query params when clicking a link to the route I am currently on.