remix-run/react-router · error
Unable to define routes with duplicate route id
Error message
Unable to define routes with duplicate route id: "${route.id}" What it means
defineRoutes keys its manifest by route id, which defaults to createRouteId(file) — the module's file path — or an explicit options.id. Before inserting, it checks 'route.id in routes' and throws on a collision rather than letting the second definition silently overwrite the first. This guards against ambiguous route trees where two entries claim the same id.
Solutions
- Give each route a unique file path
- When intentionally reusing a module, pass distinct id options: route('a', 'page.tsx', { id: 'a' }) and route('b', 'page.tsx', { id: 'b' })
- Check for accidental duplicates in generated/looped route definitions
Example fix
// before
const routes = defineRoutes(() => {
route("about", "routes/page.tsx");
route("company", "routes/page.tsx"); // same file => duplicate id
});
// after
const routes = defineRoutes(() => {
route("about", "routes/page.tsx", { id: "about-page" });
route("company", "routes/page.tsx", { id: "company-page" });
}); Defensive patterns
Strategy: validation
Validate before calling
// track ids yourself and fail with a clearer message before the library does
const seen = new Set<string>();
function assertUniqueId(id: string) {
if (seen.has(id)) throw new Error(`Duplicate route id: '${id}'`);
seen.add(id);
}
const routes = defineRoutes(() => {
assertUniqueId("about-page");
route("about", "routes/page.tsx", { id: "about-page" });
assertUniqueId("company-page");
route("company", "routes/page.tsx", { id: "company-page" });
}); Prevention
- Give every route a unique file, or explicit unique ids when reusing a file
- When generating routes from data, key by a unique field and assert uniqueness
- Search the definitions for a repeated file path before reporting the bug
When it happens
Trigger: Two route() calls referencing the same file path (same derived id); two calls passing the same explicit id option; a helper loop generating definitions that collapse onto one file or id.
Common situations: Copy-pasted route definitions reusing a file; mapping a list where multiple entries render the same component file; deliberately using one module for both a pathless layout and a page without giving one a distinct id.
Related errors
- You tried to define routes asynchronously but started…
- Expected a route.id in react-router processRoutes() function
AI-assisted analysis of remix-run/react-router@6beaca3952 (2026-08-18).
Data as JSON: /api/errors/b6f131d3fb9296f7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/react-router-remix-routes-option-adapter/defineRoutes.ts:103
// route(path, file, options, children)
// route(path, file, options)
options = optionsOrChildren || {};
}
let route: RouteManifestEntry = {
path: path ? path : undefined,
index: options.index ? true : undefined,
caseSensitive: options.caseSensitive ? true : undefined,
id: options.id || createRouteId(file),
parentId:
parentRoutes.length > 0
? parentRoutes[parentRoutes.length - 1].id
: "root",
file,
};
if (route.id in routes) {
throw new Error(
`Unable to define routes with duplicate route id: "${route.id}"`,
);
}
routes[route.id] = route;
if (children) {
parentRoutes.push(route);
children();
parentRoutes.pop();
}
};
callback(defineRoute);
alreadyReturned = true;
return routes;View on GitHub (pinned to 6beaca3952)