diff --git a/.changeset/yellow-glasses-sort.md b/.changeset/yellow-glasses-sort.md new file mode 100644 index 0000000000..bd4c461ac1 --- /dev/null +++ b/.changeset/yellow-glasses-sort.md @@ -0,0 +1,5 @@ +--- +"@react-router/dev": patch +--- + +Fix duplicated entries in typegen for layout routes and their corresponding index route diff --git a/packages/react-router-dev/typegen/index.ts b/packages/react-router-dev/typegen/index.ts index b49d06bdd8..4436adac2f 100644 --- a/packages/react-router-dev/typegen/index.ts +++ b/packages/react-router-dev/typegen/index.ts @@ -103,6 +103,12 @@ function register(ctx: Context) { const { t } = Babel; + const indexPaths = new Set( + Object.values(ctx.config.routes) + .filter((route) => route.index) + .map((route) => route.path) + ); + const typeParams = t.tsTypeAliasDeclaration( t.identifier("Params"), null, @@ -112,6 +118,9 @@ function register(ctx: Context) { // filter out pathless (layout) routes if (route.id !== "root" && !route.path) return undefined; + // filter out layout routes that have a corresponding index + if (!route.index && indexPaths.has(route.path)) return undefined; + const lineage = Route.lineage(ctx.config.routes, route); const fullpath = Route.fullpath(lineage); const params = Params.parse(fullpath);