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

  1. Rename one of the routes so each name is unique
  2. Deduplicate routes before registering (by name) when building routes dynamically
  3. Use router.hasRoute / check nameMap before adding in Vue Router 4
  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

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


AI-assisted analysis of vuejs/vue-router@680ccc68c5 (2026-09-02). Data as JSON: /api/errors/c275136403a6a46b. Report an issue: GitHub.