-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow descendant <Routes> to receive all params
Fixes #8073
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/react-router/__tests__/descendant-routes-params-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from "react"; | ||
import { create as createTestRenderer } from "react-test-renderer"; | ||
import { MemoryRouter as Router, Routes, Route, useParams } from "react-router"; | ||
|
||
describe("Descendant <Routes>", () => { | ||
it("receive all params from ancestor <Routes>", () => { | ||
function Message() { | ||
return <p>The params are {JSON.stringify(useParams())}</p>; | ||
} | ||
|
||
function User() { | ||
return ( | ||
<Routes> | ||
<Route path="messages/:messageId" element={<Message />} /> | ||
</Routes> | ||
); | ||
} | ||
|
||
let renderer = createTestRenderer( | ||
<Router initialEntries={["/users/mj/messages/123"]}> | ||
<Routes> | ||
<Route path="users/:userId/*" element={<User />} /> | ||
</Routes> | ||
</Router> | ||
); | ||
|
||
expect(renderer.toJSON()).toMatchInlineSnapshot(` | ||
<p> | ||
The params are | ||
{"userId":"mj","*":"messages/123","messageId":"123"} | ||
</p> | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters