Inserting React nodes between the Router's providers and the Router itself when using Data APIs pattern #10491
Replies: 2 comments 4 replies
-
Hi @brophdawg11, I have read your comments on #10223, and I would really appreciate your opinion about this topic. I would be really happy to propose a PR, if needed. I don't think that our case can be defined as "conditional routing", because all of our layouts are "entire route trees" that are completely "defined up-front". Really think that separating the router provider from the actual data router could make the interface a lot more flexible. |
Beta Was this translation helpful? Give feedback.
-
@brophdawg11 this is my proposal (draft): ernestostifano@40a03a8 All tests pass and it should allow placing providers and routes separately without introducing any breaking change. Is not the solution for all problems, but for sure one more step towards the final goal. This will give more flexibility to devs, at least accessing the contexts. Usagesimport {RouterProvider, DataRoutes} from 'react-router-dom';
function OptionA() {
return <RouterProvider router={router} />;
}
function OptionB() {
return (
<RouterProvider router={router}>
<SomeComponent1 />
<SomeComponent2>
<DataRoutes />
</SomeComponent2>
</RouterProvider>
);
} Both works! |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I was peeking into your source-code trying to figure out how to cover a particular use case of a project I am working on.
During that process, I found your multiple warnings encouraging to share any particular needs we might have in order to eventually improve the library (I like your approach).
So, this is the situation (I will try to skip details that are not relevant to the case).
AppContainer
component:The Problems/Doubts
ApplicationManager
component needs to have access to all the application's providers to make some high-level operations/calculations. We would also like to keep it always mounted. With the above configuration it does not have access to the navigation context.ApplicationManager
are rendered conditionally based on the application state (mainly after loading some core required resources).createBrowserRouter
only for the currently selected layout, but there are no documented examples about calling it inside auseMemo
, for example.Router
would be rendered conditionally with a different router/layout based on some application state.ApplicationManager
would be instantiated between the providers and the router internally. Should work, but the first alternative feels better, less opinionated.BrowserRouter
) this was possible, because routes are separated from the router provider, so this feels like a limitation.changeRoutes
method or similar in order to change all the routes (layout) seamlessly, without loosing the navigation state? (Maybe this is unnecessary) (trying to consider comments from Conditionally rendering Routes with `createBrowserRouter` #10223).RouterProvider
component subscribes to the router instance, but it never unsubscribes (not even after unmounting). So, would it be correct if I unmount the whole navigation and mount it again to change the layout? (This should be absolutely allowed, because it is perfectly aligned with how React works).Would like to hear some opinions in order to use the library in the most reliable and efficient way.
Would also be available to help if needed! Even documentation wise.
Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions