@@ -156,7 +156,7 @@ describe('generateRouteNamedMap', () => {
156
156
tree . insert ( 'a/[id]/index' , 'a/[id]/index.vue' )
157
157
expect ( formatExports ( generateRouteNamedMap ( tree ) ) ) . toMatchInlineSnapshot ( `
158
158
"export interface RouteNamedMap {
159
- '/a': RouteRecordInfo<'/a', '/a', Record<never, never>, Record<never, never>, '/a/' | '/a/[id]/ ' | '/a/[id]'>,
159
+ '/a': RouteRecordInfo<'/a', '/a', Record<never, never>, Record<never, never>, '/a/' | '/a/[id]' | '/a/[id]/ '>,
160
160
'/a/': RouteRecordInfo<'/a/', '/a', Record<never, never>, Record<never, never>>,
161
161
'/a/[id]': RouteRecordInfo<'/a/[id]', '/a/:id', { id: ParamValue<true> }, { id: ParamValue<false> }, '/a/[id]/'>,
162
162
'/a/[id]/': RouteRecordInfo<'/a/[id]/', '/a/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
@@ -190,8 +190,8 @@ describe('generateRouteNamedMap', () => {
190
190
tree . insert ( 'parent/other-child' , 'parent/other-child.vue' )
191
191
expect ( formatExports ( generateRouteNamedMap ( tree ) ) ) . toMatchInlineSnapshot ( `
192
192
"export interface RouteNamedMap {
193
- '/parent': RouteRecordInfo<'/parent', '/parent', Record<never, never>, Record<never, never>, '/parent/child' | '/parent/child/subchild/grandchild ' | '/parent/other- child' | '/parent/child/subchild '>,
194
- '/parent/child': RouteRecordInfo<'/parent/child', '/parent/child', Record<never, never>, Record<never, never>, '/parent/child/subchild/grandchild ' | '/parent/child/subchild'>,
193
+ '/parent': RouteRecordInfo<'/parent', '/parent', Record<never, never>, Record<never, never>, '/parent/child' | '/parent/child/subchild' | '/parent/child/subchild/grandchild ' | '/parent/other- child'>,
194
+ '/parent/child': RouteRecordInfo<'/parent/child', '/parent/child', Record<never, never>, Record<never, never>, '/parent/child/subchild' | '/parent/child/subchild/grandchild '>,
195
195
'/parent/child/subchild': RouteRecordInfo<'/parent/child/subchild', '/parent/child/subchild', Record<never, never>, Record<never, never>, '/parent/child/subchild/grandchild'>,
196
196
'/parent/child/subchild/grandchild': RouteRecordInfo<'/parent/child/subchild/grandchild', '/parent/child/subchild/grandchild', Record<never, never>, Record<never, never>>,
197
197
'/parent/other-child': RouteRecordInfo<'/parent/other-child', '/parent/other-child', Record<never, never>, Record<never, never>>,
@@ -296,6 +296,39 @@ describe('generateRouteNamedMap', () => {
296
296
}"
297
297
` )
298
298
} )
299
+
300
+ it ( 'generates stable union types regardless of insertion order' , ( ) => {
301
+ // Test that same routes inserted in different orders produce identical union types
302
+ const createTree = ( insertionOrder : string [ ] ) => {
303
+ const tree = new PrefixTree ( DEFAULT_OPTIONS )
304
+ tree . insert ( 'parent' , 'parent.vue' )
305
+
306
+ // Insert children in the specified order
307
+ insertionOrder . forEach ( ( route ) => {
308
+ tree . insert ( route , `${ route } .vue` )
309
+ } )
310
+
311
+ return formatExports ( generateRouteNamedMap ( tree ) )
312
+ }
313
+
314
+ // Same routes, different insertion orders
315
+ const order1 = [ 'parent/zebra' , 'parent/alpha' , 'parent/beta' ]
316
+ const order2 = [ 'parent/alpha' , 'parent/zebra' , 'parent/beta' ]
317
+ const order3 = [ 'parent/beta' , 'parent/alpha' , 'parent/zebra' ]
318
+
319
+ const result1 = createTree ( order1 )
320
+ const result2 = createTree ( order2 )
321
+ const result3 = createTree ( order3 )
322
+
323
+ // All should be identical due to stable sorting
324
+ expect ( result1 ) . toBe ( result2 )
325
+ expect ( result2 ) . toBe ( result3 )
326
+
327
+ // Verify the union type is alphabetically sorted
328
+ expect ( result1 ) . toContain (
329
+ "'/parent/alpha' | '/parent/beta' | '/parent/zebra'"
330
+ )
331
+ } )
299
332
} )
300
333
301
334
/**
0 commit comments