refactor(router): make v2RouteName the single authority for the v2 name rule

Moves the `v2-` de-dup (needed because getPascalCaseRouteName folds the
v2/ URL segment into the base) into the unit-tested v2RouteName helper
and simplifies the vite.config.ts call site to v2RouteName(raw, nodePath).
Removes the duplicated isV2 detection. No behavioural change: /v2/dashboard
still resolves to route name v2-dashboard; v1 names unchanged. Addresses
the Task 3 code-review Important finding.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-16 09:37:07 +02:00
parent 714abd7178
commit 9d5398e0a2
3 changed files with 37 additions and 25 deletions

View File

@@ -38,26 +38,16 @@ export default defineConfig({
// Defensive path read: unplugin-vue-router 0.8.8 TreeNode exposes
// `.fullPath`; fall back to `.value.path` then '' so a future
// plugin bump can't silently drop the v2- prefix. Step 5 below
// empirically verifies the emitted name.
// plugin bump can't silently drop the v2- prefix.
const nodePath
= (routeNode.fullPath
?? routeNode.value?.path
?? '') as string
// getPascalCaseRouteName includes the 'v2' segment from the URL
// path prefix set by routesFolder (e.g. 'v2/dashboard' → 'v2-dashboard').
// Strip that prefix before v2RouteName re-adds the canonical `v2-`
// so we get 'v2-dashboard' not 'v2-v2-dashboard'.
const isV2
= nodePath === '/v2'
|| nodePath === 'v2'
|| nodePath.startsWith('/v2/')
|| nodePath.startsWith('v2/')
const base = isV2 && raw.startsWith('v2-') ? raw.slice(3) : raw
return v2RouteName(base, nodePath)
// v2RouteName is the single authority for the /v2 name rule,
// including de-duping the `v2-` that getPascalCaseRouteName
// already folds in from the routesFolder URL prefix.
return v2RouteName(raw, nodePath)
},
}),
vue(),