Expose react-router context hooks (useLocation, useNavigate, etc.) for admin customization #13050
Closed
firstbirdworks
started this conversation in
Feature Requests & Ideas
Replies: 1 comment
-
Payload CMS migrated off React Router in v3. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Payload team,
I'm building custom admin components, and I'd love to use React Router hooks like
useLocation()
anduseNavigate()
to handle active states and navigation inside the admin interface.Currently the admin UI is wrapped in a
<BrowserRouter>
, but itsreact-router-dom
instance is not exposed to custom components. If I try to useuseLocation()
from my app’s installed version of react-router-dom (even matching versions), it throws:This is due to module duplication, Payload and my app resolve separate instances of react-router-dom causing context mismatches.
Feature request:
Would you consider exposing the admin router context through a public API so custom components can hook into it safely?
Example:
This would allow plugin and route authors to:
Workaround:
I’m currently using window.location.pathname with useEffect as a workaround, but it’s fragile and not reactive. It would be far cleaner to rely on the React Router context already provided internally by Payload.
Related:
I noticed this was brought up before in plugin-template#7, but it was closed without a resolution. Reopening here to formally track this feature request and make admin extension development smoother. 🙏
Beta Was this translation helpful? Give feedback.
All reactions