File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments