Skip to content

Commit b0a795e

Browse files
committed
fix: remove empty names from auto routes
1 parent 4539e15 commit b0a795e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/codegen/__snapshots__/generateRouteRecords.spec.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ exports[`generateRouteRecord > names > creates single word names 1`] = `
321321
]"
322322
`;
323323

324+
exports[`generateRouteRecord > names > handles empty names 1`] = `
325+
"[
326+
{
327+
path: '/about',
328+
/* no name */
329+
component: () => import('about.vue'),
330+
/* no children */
331+
}
332+
]"
333+
`;
334+
324335
exports[`generateRouteRecord > names > works with nested views 1`] = `
325336
"[
326337
{

src/codegen/generateRouteRecords.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ describe('generateRouteRecord', () => {
172172

173173
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
174174
})
175+
176+
it('handles empty names', () => {
177+
const tree = new PrefixTree(DEFAULT_OPTIONS)
178+
const node = tree.insert('about', 'about.vue')
179+
node.setCustomRouteBlock('about', {
180+
name: '',
181+
})
182+
183+
expect(generateRouteRecordSimple(tree)).toMatchSnapshot()
184+
})
175185
})
176186

177187
describe('route block', () => {

src/codegen/generateRouteRecords.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ${node
6262
${indentStr}path: '${node.path}',
6363
${indentStr}${
6464
node.value.components.size
65-
? `name: '${node.name}',`
65+
? node.name ? `name: '${node.name}',` : `/* no name */`
6666
: `/* internal name: '${node.name}' */`
6767
}
6868
${

0 commit comments

Comments
 (0)