Skip to content

Commit 1753ece

Browse files
do not typegen params for layout routes with a corresponding index (#13131)
* do not typegen params for layout routes with a corresponding index * changeset --------- Co-authored-by: Pedro Cattori <[email protected]>
1 parent 8b8fc07 commit 1753ece

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: .changeset/yellow-glasses-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Fix duplicated entries in typegen for layout routes and their corresponding index route

Diff for: packages/react-router-dev/typegen/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ function register(ctx: Context) {
103103

104104
const { t } = Babel;
105105

106+
const indexPaths = new Set(
107+
Object.values(ctx.config.routes)
108+
.filter((route) => route.index)
109+
.map((route) => route.path)
110+
);
111+
106112
const typeParams = t.tsTypeAliasDeclaration(
107113
t.identifier("Params"),
108114
null,
@@ -112,6 +118,9 @@ function register(ctx: Context) {
112118
// filter out pathless (layout) routes
113119
if (route.id !== "root" && !route.path) return undefined;
114120

121+
// filter out layout routes that have a corresponding index
122+
if (!route.index && indexPaths.has(route.path)) return undefined;
123+
115124
const lineage = Route.lineage(ctx.config.routes, route);
116125
const fullpath = Route.fullpath(lineage);
117126
const params = Params.parse(fullpath);

0 commit comments

Comments
 (0)