Skip to content

Commit

Permalink
Merge pull request #19236 from rreckonerr/fix/active-transition-qp-se…
Browse files Browse the repository at this point in the history
…rialization
  • Loading branch information
rwjblue authored Nov 9, 2020
2 parents 14b7c33 + 20da5b2 commit 58daeff
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ interface PartialRenderOptions {
model?: {};
}

function getFullQueryParams(router: EmberRouter, state: TransitionState<Route>) {
export function getFullQueryParams(router: EmberRouter, state: TransitionState<Route>) {
if (state['fullQueryParams']) {
return state['fullQueryParams'];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { calculateCacheKey, extractRouteArgs, getActiveTargetName, resemblesURL
import DSL from './dsl';
import Route, {
defaultSerialize,
getFullQueryParams,
hasDefaultSerialize,
RenderOptions,
ROUTE_CONNECTIONS,
Expand All @@ -28,7 +29,6 @@ import { MatchCallback } from 'route-recognizer';
import Router, {
InternalRouteInfo,
logAbort,
QUERY_PARAMS_SYMBOL,
STATE_SYMBOL,
Transition,
TransitionError,
Expand Down Expand Up @@ -868,7 +868,7 @@ class EmberRouter extends EmberObject {

let unchangedQPs = {};
let qpUpdates = this._qpUpdates;
let params = this._routerMicrolib.activeTransition[QUERY_PARAMS_SYMBOL];
let params = getFullQueryParams(this, this._routerMicrolib.activeTransition[STATE_SYMBOL]);
for (let key in params) {
if (!qpUpdates.has(key)) {
unchangedQPs[key] = params[key];
Expand Down
49 changes: 49 additions & 0 deletions packages/ember/tests/routing/query_params_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,55 @@ moduleFor(
});
}

['@test Calling transitionTo does not serialize query params already serialized on the activeTransition'](
assert
) {
assert.expect(3);

this.router.map(function () {
this.route('parent', function () {
this.route('child');
this.route('sibling');
});
});

this.add(
'route:parent.child',
Route.extend({
afterModel() {
this.transitionTo('parent.sibling');
},
})
);

this.add(
'controller:parent',
Controller.extend({
queryParams: ['array', 'string'],
array: [],
string: '',
})
);

// `/parent/child?array=["one",2]&string=hello`
return this.visit('/parent/child?array=%5B%22one%22%2C2%5D&string=hello').then(() => {
this.assertCurrentPath(
'/parent/sibling?array=%5B%22one%22%2C2%5D&string=hello',
'redirected to the sibling route, instead of child route'
);
assert.equal(
this.getController('parent').get('string'),
'hello',
'controller has value from the active transition'
);
assert.deepEqual(
this.getController('parent').get('array'),
['one', 2],
'controller has value from the active transition'
);
});
}

async ['@test Single query params can be set on the controller and reflected in the url'](
assert
) {
Expand Down

0 comments on commit 58daeff

Please sign in to comment.