Skip to content

Commit 4050bef

Browse files
authored
Fix #11629 (#11633)
1 parent a4aaeed commit 4050bef

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.changeset/thirty-swans-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
When using `v7_relativeSplatPath`, properly resolve relative paths in splat routes that are children of pathless routes

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
- modex98
185185
- morleytatro
186186
- ms10596
187+
- mspiess
187188
- mtliendo
188189
- ned-park
189190
- nilubisan

packages/react-router/__tests__/useResolvedPath-test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,38 @@ describe("useResolvedPath", () => {
420420
</div>"
421421
`);
422422
});
423+
424+
// gh-issue #11629
425+
it("when enabled, '.' resolves to the current path including any splat paths nested in pathless routes", () => {
426+
let { container } = render(
427+
<MemoryRouter
428+
initialEntries={["/foo/bar"]}
429+
future={{ v7_relativeSplatPath: true }}
430+
>
431+
<Routes>
432+
<Route path="foo">
433+
<Route>
434+
<Route path="*" element={<Component desc='<Route path="/foo"><Route><Route path="*" /></Route></Route>'/>}/>
435+
</Route>
436+
</Route>
437+
</Routes>
438+
</MemoryRouter>
439+
);
440+
let html = getHtml(container);
441+
html = html ? html.replace(/&lt;/g, "<").replace(/&gt;/g, ">") : html;
442+
expect(html).toMatchInlineSnapshot(`
443+
"<div>
444+
--- Routes: <Route path="/foo"><Route><Route path="*" /></Route></Route> ---
445+
useLocation(): /foo/bar
446+
useResolvedPath('.'): /foo/bar
447+
useResolvedPath('..'): /foo
448+
useResolvedPath('..', { relative: 'path' }): /foo
449+
useResolvedPath('baz/qux'): /foo/bar/baz/qux
450+
useResolvedPath('./baz/qux'): /foo/bar/baz/qux
451+
452+
</div>"
453+
`);
454+
});
423455
});
424456
});
425457

packages/router/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ export function getResolveToMatches<
12211221
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
12221222
if (v7_relativeSplatPath) {
12231223
return pathMatches.map((match, idx) =>
1224-
idx === matches.length - 1 ? match.pathname : match.pathnameBase
1224+
idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
12251225
);
12261226
}
12271227

0 commit comments

Comments
 (0)