Skip to content

Commit

Permalink
Merge pull request #13202 from raytiley/fix-clobber-activetrans-qp
Browse files Browse the repository at this point in the history
Merge in activeTransition QPs when doing a transition
  • Loading branch information
rwjblue committed Mar 29, 2016
2 parents 34cedef + 2b42d56 commit 6498702
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ var EmberRouter = EmberObject.extend(Evented, {
assert(`The route ${targetRouteName} was not found`, targetRouteName && this.router.hasRoute(targetRouteName));

var queryParams = {};
// merge in any queryParams from the active transition which could include
// queryparams from the url on initial load.
if (this.router.activeTransition) {
assign(queryParams, this.router.activeTransition.queryParams);
}

assign(queryParams, _queryParams);
this._prepareQueryParams(targetRouteName, models, queryParams);

Expand Down
59 changes: 59 additions & 0 deletions packages/ember/tests/routing/query_params_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,66 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(get(controller, 'bar'), 'rab');
equal(get(controller, 'foo'), '456');
});

QUnit.test('Calling transitionTo does not lose query params already on the activeTransition', function() {
expect(2);
App.Router.map(function() {
this.route('parent', function() {
this.route('child');
this.route('sibling');
});
});

App.ParentRoute = Route.extend({
queryParams: {foo: {defaultValue: 'bar'}}
});

App.ParentChildRoute = Route.extend({
afterModel: function() {
ok(true, 'The after model hook was called');
this.transitionTo('parent.sibling');
}
});

startingURL = '/parent/child?foo=lol';
bootApplication();

var parentController = container.lookup('controller:parent');

equal(parentController.get('foo'), 'lol');

});
} else {
QUnit.test('Calling transitionTo does not lose query params already on the activeTransition', function() {
expect(2);
App.Router.map(function() {
this.route('parent', function() {
this.route('child');
this.route('sibling');
});
});

App.ParentChildRoute = Route.extend({
afterModel: function() {
ok(true, 'The after model hook was called');
this.transitionTo('parent.sibling');
}
});

App.ParentController = Controller.extend({
queryParams: ['foo'],
foo: 'bar'
});

startingURL = '/parent/child?foo=lol';
bootApplication();

var parentController = container.lookup('controller:parent');

equal(parentController.get('foo'), 'lol');

});

QUnit.test('Single query params can be set on the controller [DEPRECATED]', function() {
Router.map(function() {
this.route('home', { path: '/' });
Expand Down

0 comments on commit 6498702

Please sign in to comment.