vuejs/vue-router · warning
Duplicate named routes definition
Error message
Duplicate named routes definition: { name: "${name}", path: "${record.path}" } What it means
Two route records define the same `name`. Only the first registration is kept in nameMap, so navigation by that name resolves to the first path, silently ignoring the later duplicate. The warning is skipped for alias-matched records (matchAs).
Solutions
- Rename one of the routes so each name is unique
- Deduplicate routes before registering (by name) when building routes dynamically
- Use router.hasRoute / check nameMap before adding in Vue Router 4
- If dynamic re-registration is intended, remove the old route first
Example fix
// before
[{ path: '/a', name: 'user' }, { path: '/b', name: 'user' }]
// after
[{ path: '/a', name: 'user-a' }, { path: '/b', name: 'user-b' }] Defensive patterns
Strategy: validation
Validate before calling
function assertUniqueNames(routes) {
const seen = new Set()
for (const r of routes) {
if (r.name) {
if (seen.has(r.name)) throw new Error(`Duplicate route name: ${r.name}`)
seen.add(r.name)
}
}
}
assertUniqueNames(routes) Prevention
- Enforce unique route names with a unit test over the route table
- Namespace route names per module when merging route configs
- Check existing names before dynamic registration
When it happens
Trigger: routes: [{ path: '/a', name: 'x' }, { path: '/b', name: 'x' }] — the second addRoute with name 'x' hits the existing nameMap entry; also common when addRoutes/addRoute is called repeatedly with overlapping configs.
Common situations: Copy-pasted route definitions; dynamically generated routes re-registered with the same names; merging route modules that reuse names.
Related errors
- Named Route ' ' has a default child route. When navigating…
- props in " " is a , expecting an object, function or…
- Duplicate param keys in route with path
- Found an alias with the same value as the path
- invalid redirect option
AI-assisted analysis of vuejs/vue-router@680ccc68c5 (2026-09-02).
Data as JSON: /api/errors/c275136403a6a46b.
Report an issue: GitHub.
Appendix: source
Thrown at src/create-route-map.js:184
path: alias,
children: route.children
}
addRouteRecord(
pathList,
pathMap,
nameMap,
aliasRoute,
parent,
record.path || '/' // matchAs
)
}
}
if (name) {
if (!nameMap[name]) {
nameMap[name] = record
} else if (process.env.NODE_ENV !== 'production' && !matchAs) {
warn(
false,
`Duplicate named routes definition: ` +
`{ name: "${name}", path: "${record.path}" }`
)
}
}
}
function compileRouteRegex (
path: string,
pathToRegexpOptions: PathToRegexpOptions
): RouteRegExp {
const regex = Regexp(path, [], pathToRegexpOptions)
if (process.env.NODE_ENV !== 'production') {
const keys: any = Object.create(null)
regex.keys.forEach(key => {
warn(
!keys[key.name],View on GitHub (pinned to 680ccc68c5)