Skip to content

Commit

Permalink
Fix #11629 (#11633)
Browse files Browse the repository at this point in the history
  • Loading branch information
mspiess authored Jun 18, 2024
1 parent a4aaeed commit 4050bef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thirty-swans-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

When using `v7_relativeSplatPath`, properly resolve relative paths in splat routes that are children of pathless routes
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
- modex98
- morleytatro
- ms10596
- mspiess
- mtliendo
- ned-park
- nilubisan
Expand Down
32 changes: 32 additions & 0 deletions packages/react-router/__tests__/useResolvedPath-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,38 @@ describe("useResolvedPath", () => {
</div>"
`);
});

// gh-issue #11629
it("when enabled, '.' resolves to the current path including any splat paths nested in pathless routes", () => {
let { container } = render(
<MemoryRouter
initialEntries={["/foo/bar"]}
future={{ v7_relativeSplatPath: true }}
>
<Routes>
<Route path="foo">
<Route>
<Route path="*" element={<Component desc='<Route path="/foo"><Route><Route path="*" /></Route></Route>'/>}/>
</Route>
</Route>
</Routes>
</MemoryRouter>
);
let html = getHtml(container);
html = html ? html.replace(/&lt;/g, "<").replace(/&gt;/g, ">") : html;
expect(html).toMatchInlineSnapshot(`
"<div>
--- Routes: <Route path="/foo"><Route><Route path="*" /></Route></Route> ---
useLocation(): /foo/bar
useResolvedPath('.'): /foo/bar
useResolvedPath('..'): /foo
useResolvedPath('..', { relative: 'path' }): /foo
useResolvedPath('baz/qux'): /foo/bar/baz/qux
useResolvedPath('./baz/qux'): /foo/bar/baz/qux
</div>"
`);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ export function getResolveToMatches<
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
if (v7_relativeSplatPath) {
return pathMatches.map((match, idx) =>
idx === matches.length - 1 ? match.pathname : match.pathnameBase
idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
);
}

Expand Down

0 comments on commit 4050bef

Please sign in to comment.