Ember Query Params unset Query Parameter

I am using the new Ember query parameters and have problems "canceling" the query parameter.

I have a scenario where I need to switch from something like :? game = 13 to? question = 14. This means that I have two query parameters on my router: game, question. Unfortunately, this transition (outgoing from the game = 13):

this.transitionToRoute({queryParams: {question: 14}} ); 

Unfortunately, this leads to:

?

game = 13 &. Question = 14

I also tried:

 this.transitionToRoute({queryParams: {question: 14, game: null}} ); 

that leads to:

?

game = zero & question = 14

Because for some reason everything is converted to a string.

How can I upgrade to? question = 14 and remove the game request parameter?

+6
source share
3 answers

Initialize your properties by storing the query parameters to a value. Bring them back to this initial value to remove them from your URL later:

 App.SomeController = Ember.Controller.extend({ queryParams: ['myParam'], myParam: "initial", ... ); 

Further...

 controller.set('myParam', "initial"); 
+2
source

Try setting the default value for the query parameter in the controller. After that you can:

 this.transitionToRoute({queryParams: {question: 14, game: <the default value that you set in the controller>}} ); 
0
source
 var params = {}; if(this.get('controller.question') params.question = this.get('controller.question'); if(this.get('controller.game') params.game = this.get('controller.game'); this.transitionToRoute({queryParams: params} ); 
0
source

Source: https://habr.com/ru/post/973197/


All Articles