File tree Expand file tree Collapse file tree
packages/react/src/reactrouter-compat-utils Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments