Here is an example from the doc: Query Parameters - Routing - Ember Guides
// if you want to transition the query parameters without changing the route
this.transitionTo({ queryParams: { direction: 'asc' }});
I am in my application
route and have query-params defined in its controller. To make things more concrete, let’s say they are city
and state
, and that I have specified their default values to be an empty string: ‘’.
The route I want to end up in is a few levels down, but I am putting the logic in the application
’s beforeModel
hook. (Don’t think any of this makes a difference, but we’ve all been bitten by thinking that from time to time.)
Let’s say the q-p’s are {city: 'Boston', state: 'MA'}
. I want to remove them from the browser’s address bar.
The doc says:
If you wish to reset a query param, you have two options:
1) explicitly pass in the default value for that query param into link-to or transitionTo.
So at the end of my beforeModel
hook I set them to the default values like so:
this.transitionTo( { queryParms: { city: '', state: ''} } );
I end up on the right page, but unfortunately the query params are still in the URL. And when I do something like this: this.transitionTo( { queryParms: { city: 'New York', state: 'NY'} } );
the original query params {city: 'Boston', state: 'MA}
are still in the URL.
Also, the console shows an error on the transitionTo
statement. In Firefox it’s:
TypeError: routeInfos[(routeInfoLength - 1)] is undefined
,
while Chrome spits out:
Uncaught (in promise) TypeError: Cannot read property 'name' of undefined
at Class._queryParamsFor (router.js:835)
at Class.finalizeQueryParamChange (route.js:2128)
at Class.triggerEvent (router.js:1290)
at PrivateRouter.triggerEvent (router.js:175)
at PrivateRouter.finalizeQueryParamChange (router_js.js:1933)
at PrivateRouter.queryParamsTransition (router_js.js:1427)
at PrivateRouter.getTransitionByIntent (router_js.js:1496)
at PrivateRouter.transitionByIntent (router_js.js:1445)
at PrivateRouter.doTransition (router_js.js:1579)
at PrivateRouter.transitionTo (router_js.js:2057)
If I comment out the transitionTo
statement the error messages disappear.
It seems like this should be a simple thing to do, yet I have spent hours trying to figure out how to get rid of the query params in the browser’s address bar. Am I doing something wrong, or do the console error messages indicate some kind of problem?