Replies: 3 comments 1 reply
-
You can try this: https://reactrouter.com/en/main/hooks/use-outlet-context |
Beta Was this translation helpful? Give feedback.
-
well, i'm passing state via navigate method call, using context on Outlet would definitely do the work. is there any direct way possible via browser's history api? here in this soln. we're using context api |
Beta Was this translation helpful? Give feedback.
-
When you navigate from /x/y to /x/z you could use the location.state to pass the value, then access it using Another option is to you search params, which will also work with SSR, but this would mean the user can bookmark or share the URL and resume or share the state, if that's not desirable then using location.state is better. Finally, this is still a React app, so React app solutions also work, you could move the state from /x/y to /x and then use the outlet context to pass both the state and the setter to the children routes, another options could be to keep the state outside React, like using a state management lib, e.g. Redux, Zudstand, etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an Outlet component at /x which y & z are children of, i need state value in /x/y and /x/z & /x/other routes.
Beta Was this translation helpful? Give feedback.
All reactions