How to have a layer between Router and Routes #10599
-
I'm new to React Router v6, but not to React Router in general. What I'm trying to solve was relatively easy before, but I can't work out now how to do it :( I'm wanting to have a component that wraps all of my routes, but must be inside the router - because it needs to use the However, to minimise flickering, I don't want to render the routes until this has succeeded - it involves making an XHR call for an access token, so will take an amount of time. It seems - maybe incorrectly? - to me that what I want is therefore:
However, I can't see any way of achieving this with Is there a better way to achieve this? Or is this the only option right now? Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is exactly what the new Data Router paradigms aim to help with by completely decoupling data fetching from rendering. So what you really want (when using Otherwise, yes the solution would be is to move the stuff that used to live between |
Beta Was this translation helpful? Give feedback.
This is exactly what the new Data Router paradigms aim to help with by completely decoupling data fetching from rendering. So what you really want (when using
RouterProvider
) is to do your auth checks in yourloader
andredirect
there which (1) can be async and (2) happens completely before any rendering happens.Otherwise, yes the solution would be is to move the stuff that used to live between
BrowserRouter
+Routes
into a root layout route. But moving your data fetch8ing to loaders/actions should provide a mu…