Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11629 #11633

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1178,7 +1178,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