{"record":{"id":"c275136403a6a46b","repo":"vuejs/vue-router","slug":"duplicate-named-routes-definition-name-name","errorCode":null,"errorMessage":"Duplicate named routes definition: { name: \"${name}\", path: \"${record.path}\" }","messagePattern":"Duplicate named routes definition: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/create-route-map.js","lineNumber":184,"sourceCode":"        path: alias,\n        children: route.children\n      }\n      addRouteRecord(\n        pathList,\n        pathMap,\n        nameMap,\n        aliasRoute,\n        parent,\n        record.path || '/' // matchAs\n      )\n    }\n  }\n\n  if (name) {\n    if (!nameMap[name]) {\n      nameMap[name] = record\n    } else if (process.env.NODE_ENV !== 'production' && !matchAs) {\n      warn(\n        false,\n        `Duplicate named routes definition: ` +\n          `{ name: \"${name}\", path: \"${record.path}\" }`\n      )\n    }\n  }\n}\n\nfunction compileRouteRegex (\n  path: string,\n  pathToRegexpOptions: PathToRegexpOptions\n): RouteRegExp {\n  const regex = Regexp(path, [], pathToRegexpOptions)\n  if (process.env.NODE_ENV !== 'production') {\n    const keys: any = Object.create(null)\n    regex.keys.forEach(key => {\n      warn(\n        !keys[key.name],","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/vuejs/vue-router/blob/680ccc68c506cca9be6207745043245d61fa715a/src/create-route-map.js#L166-L202","documentation":"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).","triggerScenarios":"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.","commonSituations":"Copy-pasted route definitions; dynamically generated routes re-registered with the same names; merging route modules that reuse names.","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"],"exampleFix":"// before\n[{ path: '/a', name: 'user' }, { path: '/b', name: 'user' }]\n// after\n[{ path: '/a', name: 'user-a' }, { path: '/b', name: 'user-b' }]","handlingStrategy":"validation","validationCode":"function assertUniqueNames(routes) {\n  const seen = new Set()\n  for (const r of routes) {\n    if (r.name) {\n      if (seen.has(r.name)) throw new Error(`Duplicate route name: ${r.name}`)\n      seen.add(r.name)\n    }\n  }\n}\nassertUniqueNames(routes)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["vue-router","routing","named-routes","duplicate"],"backgroundTag":"duplicate-named-route","analyzedSha":"680ccc68c506cca9be6207745043245d61fa715a","analyzedAt":"2026-09-02T19:19:01.204Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}