Skip to content

Commit 72012ab

Browse files
committed
fix: avoid false duplicate route warning for named views
Closes #2648
1 parent b52a13e commit 72012ab

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/router/src/unplugin/core/tree.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,14 @@ describe('Tree', () => {
12751275
expect(c.children.has('_parent')).toBe(false)
12761276
})
12771277

1278+
it('does not flag named views as conflicts', () => {
1279+
const tree = new PrefixTree(RESOLVED_OPTIONS)
1280+
tree.insert('posts/index', 'posts/index.vue')
1281+
tree.insert('posts/index@header', 'posts/index@header.vue')
1282+
1283+
expect(collectDuplicatedRouteNodes(tree)).toEqual([])
1284+
})
1285+
12781286
it('collects _parent conflicts', () => {
12791287
const tree = new PrefixTree(RESOLVED_OPTIONS)
12801288
const nested = tree.insert('nested', 'nested.vue')

packages/router/src/unplugin/core/tree.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,12 @@ export function collectDuplicatedRouteNodes(
624624
}
625625

626626
const dups = Array.from(seen.values())
627-
.filter(nodes => Object.keys(nodes).length > 1)
627+
// All entries in a group reference the same TreeNode instance, so
628+
// comparing the number of files to components.size tells us if any
629+
// file was overwritten (e.g. index.vue vs index@default.vue both
630+
// targeting the "default" view). Different named views on the same
631+
// node (e.g. index.vue + index@header.vue) are not conflicts.
632+
.filter(nodes => nodes.length > nodes[0].node.value.components.size)
628633
.map(nodes =>
629634
nodes.toSorted(({ node: a }, { node: b }) => {
630635
// put the one that takes precedence at the end of the list

0 commit comments

Comments
 (0)