Skip to content

Commit 6b58877

Browse files
committed
Ensure that order of routes that cannot be disambiguated is preserved
1 parent a9ed265 commit 6b58877

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

modules/RouteNode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export default class RouteNode {
108108

109109
this.children.push(route);
110110
// Push greedy spats to the bottom of the pile
111+
112+
const originalChildren = this.children.slice(0);
113+
111114
this.children.sort((left, right) => {
112115
const leftPath = left.path
113116
.replace(/<.*?>/g, '')
@@ -138,8 +141,9 @@ export default class RouteNode {
138141
const rightParamLength = (rightPath.split('/').slice(-1)[0] || '').length;
139142
if (leftParamLength < rightParamLength) return 1;
140143
if (leftParamLength > rightParamLength) return -1;
141-
// Same last segment length, preserve definition order
142-
return 0;
144+
// Same last segment length, preserve definition order. Note that we
145+
// cannot just return 0, as sort is not guaranteed to be a stable sort.
146+
return originalChildren.indexOf(left) - originalChildren.indexOf(right);
143147
});
144148
} else {
145149
// Locate parent node

0 commit comments

Comments
 (0)