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

[v6] useParams in parent route does not contain child route params #7881

Closed
andrelandgraf opened this issue Jun 21, 2021 · 2 comments
Closed

Comments

@andrelandgraf
Copy link

I noticed some unexpected behaviour of useParams. I also reported a very similar issue for useSearchParams but this time, I am more certain it's actually an bug and not just an edge case.

I try to manage layouts in higher-order routes and make use of <Outlet /> to reuse the same layout within all sub-routes. I try to use useSearchParams and useParams in the parent route to be context aware, e.g. show a different nav-menu based on which route/URL is actually rendered right now.

Version

v6

Test Case

https://codesandbox.io/s/useparams-react-router-v6-ky20d?file=/src/App.js

Steps to reproduce

Call useParams in a parent-route and log the result. It will miss all params of its child routes.

Expected Behavior

useParams always returns all params of the current URL regardless of from where / which context it was called.

Actual Behavior

// in /projects.ts
const { projectId } = useParams();
console.log(projectId)
// would print undefined

(see the test case above)

@myNameIsDu
Copy link

#7803 (comment)

@timdorr
Copy link
Member

timdorr commented Jun 22, 2021

Duplicate of #7803

@timdorr timdorr marked this as a duplicate of #7803 Jun 22, 2021
@timdorr timdorr closed this as completed Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants