Skip to content

Commit

Permalink
Merge pull request #18244 from st-h/16594
Browse files Browse the repository at this point in the history
[BUGFIX lts] Router service: Failing with query parameters on application controller
  • Loading branch information
rwjblue authored Oct 30, 2019
2 parents 1ffa71d + 9f84236 commit 93b08fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,10 @@ class EmberRouter extends EmberObject {
return true;
}

if (_fromRouterService && presentProp !== false) {
if (_fromRouterService && presentProp !== false && qp.urlKey !== qp.prop) {
// assumptions (mainly from current transitionTo_test):
// - this is only supposed to be run when there is an alias to a query param and the alias is used to set the param
// - when there is no alias: qp.urlKey == qp.prop
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { run } from '@ember/runloop';
import { get } from '@ember/-internals/metal';
import { RouterTestCase, moduleFor } from 'internal-test-helpers';
import { InternalTransition as Transition } from 'router_js';
import { inject as service } from '@ember/service';

moduleFor(
'Router Service - transitionTo',
Expand Down Expand Up @@ -449,5 +450,31 @@ moduleFor(
}, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort');
});
}

['@test RouterService#transitionTo with application query params when redirecting form a different route'](
assert
) {
assert.expect(1);

this.add(
'route:parent.child',
Route.extend({
router: service(),
beforeModel() {
this.router.transitionTo('parent');
},
})
);
this.add(
'controller:parent',
Controller.extend({
queryParams: ['url_sort'],
})
);

return this.visit('/child?url_sort=a').then(() => {
assert.equal(this.routerService.get('currentURL'), '/?url_sort=a');
});
}
}
);

0 comments on commit 93b08fe

Please sign in to comment.