问题
I'm writing an action handler in route:application
:
actions: {
changeFoo(foo) {
// I want to change the fooId queryParam to foo.get('id')
}
}
The problem is that the only documented ways I can find to change the query params are transitionTo('some.route', someModel, { queryParams: { ... } }
and the replaceWith
version of the same. But I'm in route:application
, so I don't know the current route's name. That means I don't know what the first argument to transitionTo
would be.
Is there another way to get the URL to become ?fooId=123
?
回答1:
You don't need current route name. You can just do 'transitionTo({queryParams: { foo: 123 })'. The router will apply it to the correct route.
回答2:
From controller:application you can set the query param foo
like this:
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['foo'],
actions: {
updateMyQueryParam() {
this.set('foo', 'hello');
}
}
});
来源:https://stackoverflow.com/questions/35192211/how-do-i-change-query-parameters-in-ember