Skip to content

Commit

Permalink
fix: useParams will give the same result no matter where it is used (
Browse files Browse the repository at this point in the history
  • Loading branch information
Repraance authored May 8, 2023
1 parent e660401 commit 49032df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
exports[`nested routes gets all params from parent routes 1`] = `
<div>
<h1>
Users
Users:
michael
</h1>
<div>
<h1>
User:
User:
michael
</h1>
<div>
Expand All @@ -16,9 +17,9 @@ exports[`nested routes gets all params from parent routes 1`] = `
</h1>
<div>
<h1>
User:
User:
michael
, course
, course
routing
</h1>
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/router-react/src/__tests__/nested-params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { MemoryRouter as Router, useParams, RouterView } from '..';
describe('nested routes', () => {
it('gets all params from parent routes', () => {
function Users() {
let { username } = useParams();
return (
<div>
<h1>Users</h1>
<h1>Users:{username}</h1>
<RouterView />
</div>
);
Expand All @@ -17,7 +18,7 @@ describe('nested routes', () => {
let { username } = useParams();
return (
<div>
<h1>User: {username}</h1>
<h1>User:{username}</h1>
<RouterView />
</div>
);
Expand All @@ -40,7 +41,7 @@ describe('nested routes', () => {
return (
<div>
<h1>
User: {username}, course {courseId}
User:{username}, course{courseId}
</h1>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/router-react/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function useNavigate(): INavigateFunction {
* URL that were matched by the route path.
*/
export function useParams(): IParams {
return useContext(MatchedRouteContext).params;
return useContext(RouteContext).params;
}

/**
Expand Down

0 comments on commit 49032df

Please sign in to comment.