Skip to content

Commit 4864903

Browse files
committed
fix: avoid non matchable routes in auto-routes
1 parent 2a1ed81 commit 4864903

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/router/src/unplugin/codegen/generateRouteRecords.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ describe('generateRouteRecord', () => {
2929
`)
3030
})
3131

32+
it('skips routes for lone _parent files', () => {
33+
const tree = new PrefixTree(DEFAULT_OPTIONS)
34+
tree.insert('nested/_parent', 'nested/_parent.vue')
35+
36+
expect(generateRouteRecordSimple(tree)).toMatchInlineSnapshot(`
37+
"[
38+
39+
]"
40+
`)
41+
})
42+
43+
it('keeps routes with _parent when children exist', () => {
44+
const tree = new PrefixTree(DEFAULT_OPTIONS)
45+
tree.insert('nested/_parent', 'nested/_parent.vue')
46+
tree.insert('nested/index', 'nested/index.vue')
47+
48+
expect(generateRouteRecordSimple(tree)).toContain("path: '/nested'")
49+
})
50+
3251
it('works with some paths at root', () => {
3352
const tree = new PrefixTree(DEFAULT_OPTIONS)
3453
tree.insert('a', 'a.vue')

packages/router/src/unplugin/codegen/generateRouteRecords.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ ${node
2828
]`
2929
}
3030

31+
// Skip lone parent nodes - they only provide layout wrapping for children
32+
// so without children they don't make sense to be included in the route records
33+
if (!node.isMatchable() && node.children.size === 0) {
34+
return ''
35+
}
36+
3137
const definePageDataList: string[] = []
3238

3339
if (node.hasDefinePage) {

0 commit comments

Comments
 (0)