-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[Feature]: New hook "useChildRoutePath()" to get the current route "path" value. #8555
Comments
Unfortunately, this isn't possible for a number of reasons. Most notably is which child you mean under the current Since your SO question mentions animations, I think what you're looking for will be answered by #8008, whenever that lands. I'd watch that topic for updates. |
@timdorr I guess it's a little bit easier than you think, because we know which |
Ability to know what route path is rendered in would be very helpful. Path of one direct child is enough for example to decide to render the or current path or both.
Something like:
|
What is the new or updated feature that you are suggesting?
I am suggesting a new hook called
useChildRoutePath()
. This hook will return the route path value of current route.Why should this feature be included?
Nesting
Route
is very intuitive. With that usingOutlet
makes it perfect setup.Mostly you have a wrapper component for
Outlet
like this:Now, if
Layout
component wants to know what is being rendered inOutlet
only way (I know) is to useuseLocation
hook to get pathname.Layout
can parse the pathname value and apply the business logic based on it.However, pathname parsing becomes complicated if routes are nested and
Layout
just needs to know the route.path value.Also if
Layout
position is moved in the nested hierarchy of routes the custom parsing of route.path needs to be updated.This sample solution might work for some very simple nested routes but failed for complex routes with dynamic path values (eg.
path=":id/messages"
)Using suggested hook though everything becomes easy!
Please take a look at this question for a detailed use case (with actual requirement):
https://stackoverflow.com/questions/70576327/how-to-get-child-route-path-with-react-router-v6
Let me know if I can provide more information or if there is solution already.
The text was updated successfully, but these errors were encountered: