Replies: 1 comment
-
|
If you want to test the implementation, you can check https://stackblitz.com/~/github.com/alex-pex/poc-react-router-6-mix-2?file=src/sub-app/SubApp.tsx |
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! 👋
I'd like to propose adding support for nesting
<Router>components in React Router through an optionalallowNestingprop. This feature would be limited to MemoryRouter or custom Router implementation, and would enable advanced use cases where multiple Router instances can coexist within the same application while maintaining backward compatibility.Problem
Currently, React Router explicitly prevents nesting
<Router>components with an invariant error:This was introduced with v6. It wasn't there on the version we are ditching (v3)
This restriction limits some legitimate use cases such as:
On our app, we use this to open multiple dialog windows which are sub-apps (think "iframe" kind of isolation).
Proposed Solution
Key Changes
New
allowNestingprop on the<Router>componentfalseto maintain current behaviortrue, allows nesting a Router inside another RouterRouteContext initialization
RouteContextis now initialized withnull!instead of a default valueRouteContext.Providerto avoid context conflictsMemoryRouter support
MemoryRouterautomatically usesallowNestingbecause there is less chances of conflicts, the source of truth is handled by the app and not a single origin like "browser url"Usage Example
Considerations
Implementation
I've implemented this feature in commit alex-pex@f996571
Workaround implementations
Hack router context
If this change is rejected, I will ended up creating my own NestedMemoryRouter implementation
Colocate routers
I might also try to render routers without nesting
But it will also change the behavior and rendering
Beta Was this translation helpful? Give feedback.
All reactions