vuejs/vue-router · warning
Duplicate named routes definition: { name: "${name}", path:
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).
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)
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
- props in "${route.path}" is a ${typeof config}, expecting an
- Named Route '${route.name}' has a default child route. When
- invalid redirect option: ${JSON.stringify(redirect)}
- Non-nested routes must include a leading slash character. Fi
- Route with path "${path}" contains unencoded characters, mak
AI-assisted analysis of vuejs/vue-router@680ccc68c5 (2026-09-02).
Data as JSON: /api/errors/c275136403a6a46b.
Report an issue: GitHub.