Skip to content

Commit 58daeff

Browse files
authored
Merge pull request #19236 from rreckonerr/fix/active-transition-qp-serialization
2 parents 14b7c33 + 20da5b2 commit 58daeff

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

packages/@ember/-internals/routing/lib/system/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ interface PartialRenderOptions {
19351935
model?: {};
19361936
}
19371937

1938-
function getFullQueryParams(router: EmberRouter, state: TransitionState<Route>) {
1938+
export function getFullQueryParams(router: EmberRouter, state: TransitionState<Route>) {
19391939
if (state['fullQueryParams']) {
19401940
return state['fullQueryParams'];
19411941
}

packages/@ember/-internals/routing/lib/system/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { calculateCacheKey, extractRouteArgs, getActiveTargetName, resemblesURL
1414
import DSL from './dsl';
1515
import Route, {
1616
defaultSerialize,
17+
getFullQueryParams,
1718
hasDefaultSerialize,
1819
RenderOptions,
1920
ROUTE_CONNECTIONS,
@@ -28,7 +29,6 @@ import { MatchCallback } from 'route-recognizer';
2829
import Router, {
2930
InternalRouteInfo,
3031
logAbort,
31-
QUERY_PARAMS_SYMBOL,
3232
STATE_SYMBOL,
3333
Transition,
3434
TransitionError,
@@ -868,7 +868,7 @@ class EmberRouter extends EmberObject {
868868

869869
let unchangedQPs = {};
870870
let qpUpdates = this._qpUpdates;
871-
let params = this._routerMicrolib.activeTransition[QUERY_PARAMS_SYMBOL];
871+
let params = getFullQueryParams(this, this._routerMicrolib.activeTransition[STATE_SYMBOL]);
872872
for (let key in params) {
873873
if (!qpUpdates.has(key)) {
874874
unchangedQPs[key] = params[key];

packages/ember/tests/routing/query_params_test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,55 @@ moduleFor(
137137
});
138138
}
139139

140+
['@test Calling transitionTo does not serialize query params already serialized on the activeTransition'](
141+
assert
142+
) {
143+
assert.expect(3);
144+
145+
this.router.map(function () {
146+
this.route('parent', function () {
147+
this.route('child');
148+
this.route('sibling');
149+
});
150+
});
151+
152+
this.add(
153+
'route:parent.child',
154+
Route.extend({
155+
afterModel() {
156+
this.transitionTo('parent.sibling');
157+
},
158+
})
159+
);
160+
161+
this.add(
162+
'controller:parent',
163+
Controller.extend({
164+
queryParams: ['array', 'string'],
165+
array: [],
166+
string: '',
167+
})
168+
);
169+
170+
// `/parent/child?array=["one",2]&string=hello`
171+
return this.visit('/parent/child?array=%5B%22one%22%2C2%5D&string=hello').then(() => {
172+
this.assertCurrentPath(
173+
'/parent/sibling?array=%5B%22one%22%2C2%5D&string=hello',
174+
'redirected to the sibling route, instead of child route'
175+
);
176+
assert.equal(
177+
this.getController('parent').get('string'),
178+
'hello',
179+
'controller has value from the active transition'
180+
);
181+
assert.deepEqual(
182+
this.getController('parent').get('array'),
183+
['one', 2],
184+
'controller has value from the active transition'
185+
);
186+
});
187+
}
188+
140189
async ['@test Single query params can be set on the controller and reflected in the url'](
141190
assert
142191
) {

0 commit comments

Comments
 (0)