I am using the new Ember Query Parameters and having issues "unsetting" a query parameter.
I have a scenario where I need to navigate from something like: ?game=13 to ?question=14. This means that I have 2 query parameters on my router: game, question. Unfortunately this transition (coming from ?game=13):
this.transitionToRoute({queryParams: {question: 14}} );
This unfortunately leads to :
?game=13&question=14.
I have also tried:
this.transitionToRoute({queryParams: {question: 14, game: null}} );
which leads to:
?game=null&question=14
Because somehow everything is stringtransformed.
How can I transition to ?question=14 and remove the game query parameter?
Common use cases for query params include representing the current page number in a paginated collection, filter criteria, or sorting criteria. In web development, query parameters are used within a URL as described above but can also be used in API requests that retrieve data. Ember treats these as two different concepts.
Query parameters are optional key-value pairs that appear to the right of the ? in a URL. For example, the following URL has two query params, sort and page, with respective values ASC and 2:
When you change query params through a transition ( transitionTo and <LinkTo /> ), it is not considered a full transition. This means that the controller properties associated with the query params will be updated, as will the URL, but no Route method hook like model or setupController will be called.
When a controller's query param property is currently set to its default value, this value won't be serialized into the URL. So in the above example, if page is 1, the URL might look like /articles , but once someone sets the controller's page value to 2, the URL will become /articles?page=2.
Initialize your properties storing query params to some value. Set them back to this initial value to remove them from your URL later:
App.SomeController = Ember.Controller.extend({
queryParams: ['myParam'],
myParam: "initial",
...
);
Later...
controller.set('myParam', "initial");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With