Skip to content

Commit 132ee5c

Browse files
committed
fix test
1 parent 1eb71ff commit 132ee5c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • packages/react/src/reactrouter-compat-utils

packages/react/src/reactrouter-compat-utils/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,19 @@ function reconstructNameFromDescendantParent(
205205

206206
const parentTemplate = trimSlash(trimWildcard(parentMatch.route.path || ''));
207207

208-
// Only a static leading segment (e.g. `child/*`) has a fixed position in the absolute URL; dynamic
209-
// leads (`:projectId/*`) are relative and stay with the existing wildcard-rebuild path.
210-
if (!parentTemplate || parentTemplate.startsWith(':')) {
208+
if (!parentTemplate) {
211209
return undefined;
212210
}
213211

214212
const expectedPrefix = prefixWithSlash(parentTemplate);
215-
if (currentName === expectedPrefix || currentName?.startsWith(`${expectedPrefix}/`)) {
213+
214+
// Child `<Routes>` resolve against the matched parent, but flattened route matching can already retain
215+
// a dynamic leading parameter. Adding the parent again would duplicate it (e.g. `/:id/:id`)
216+
const firstElement = parentTemplate.split('/')[0];
217+
const hasDynamicLead = firstElement?.startsWith(':') && currentName?.split('/').includes(firstElement);
218+
219+
// Rebuild only when matching the descendant subtree discarded its parent route template
220+
if (currentName === expectedPrefix || currentName?.startsWith(`${expectedPrefix}/`) || hasDynamicLead) {
216221
return undefined;
217222
}
218223

0 commit comments

Comments
 (0)