Skip to content

Commit ea004a5

Browse files
committed
[BUGFIX release] Sticky query params for nested and for dynamic routes.
Fixed query params not being sticky for nested routes Fixed query params not working for multiple routes that each have a dynamic segment Previous only 1 dynamic segment was working correctly
1 parent 6130fa6 commit ea004a5

File tree

3 files changed

+678
-375
lines changed

3 files changed

+678
-375
lines changed

packages/ember-routing/lib/system/route.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,8 @@ function mergeEachQueryParams(controllerQP, routeQP) {
22292229
if (!controllerQP.hasOwnProperty(cqpName)) { continue; }
22302230

22312231
var newControllerParameterConfiguration = {};
2232-
merge(newControllerParameterConfiguration, controllerQP[cqpName], routeQP[cqpName]);
2232+
merge(newControllerParameterConfiguration, controllerQP[cqpName]);
2233+
merge(newControllerParameterConfiguration, routeQP[cqpName]);
22332234

22342235
qps[cqpName] = newControllerParameterConfiguration;
22352236

packages/ember-routing/lib/utils.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ export function stashParamNames(router, handlerInfos) {
4646
handlerInfos._namesStashed = true;
4747
}
4848

49+
function _calculateCacheValuePrefix(prefix, part) {
50+
// calculates the dot seperated sections from prefix that are also
51+
// at the start of part - which gives us the route name
52+
53+
// given : prefix = site.article.comments, part = site.article.id
54+
// - returns: site.article (use get(values[site.article], 'id') to get the dynamic part - used below)
55+
56+
// given : prefix = site.article, part = site.article.id
57+
// - returns: site.article. (use get(values[site.article], 'id') to get the dynamic part - used below)
58+
59+
var prefixParts = prefix.split('.');
60+
var currPrefix = '';
61+
for (var i = 0, len = prefixParts.length; i < len; i++) {
62+
var currPart = prefixParts.slice(0, i+1).join('.');
63+
if (part.indexOf(currPart) !== 0) {
64+
break;
65+
}
66+
currPrefix = currPart;
67+
}
68+
return currPrefix;
69+
}
70+
4971
/*
5072
Stolen from Controller
5173
*/
@@ -54,7 +76,14 @@ export function calculateCacheKey(prefix, _parts, values) {
5476
var suffixes = '';
5577
for (var i = 0, len = parts.length; i < len; ++i) {
5678
var part = parts[i];
57-
var value = get(values, part);
79+
var cacheValuePrefix = _calculateCacheValuePrefix(prefix, part);
80+
var value;
81+
if (cacheValuePrefix && cacheValuePrefix in values) {
82+
var partRemovedPrefix = (part.indexOf(cacheValuePrefix) === 0) ? part.substr(cacheValuePrefix.length + 1) : part;
83+
value = get(values[cacheValuePrefix], partRemovedPrefix);
84+
} else {
85+
value = get(values, part);
86+
}
5887
suffixes += '::' + part + ':' + value;
5988
}
6089
return prefix + suffixes.replace(ALL_PERIODS_REGEX, '-');

0 commit comments

Comments
 (0)