You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background
We're building a complex architecture with nested micro services, where multiple "Apps" live in the same React tree. We want to allow these Apps to benefit from independent routing. See description below for details.
Problem
This should work, except for one problem: The <Router> component does not like being nested. There is an explicit check on line 288 to prevent this, with the message: You cannot render a <Router> inside another <Router>. You never need more than one.
Unless there's a better way to achieve our requirement, we do indeed need more than one.
Suggestion
As far as I can tell this check did not exist in v5 and is supposed to help developers avoid a common mistake. That is useful, but undermines our use case. My suggestion is to either remove the check or to add a prop that allows disabling it (something like <Router allowNestedRouter>) as an informed choice.
As far as I can tell there should be no technical limitation preventing this, as Router is just a context provider and nested context providers will just shadow their ancestors.
Details
Our attempted solution is based on a custom Router with a custom History sub class that can be injected for each App (based on this suggestion). The individual Apps' current pathnames are combined and appended to the page URL's hash via one "main" Router+History.
A URL could look something like this (extra spaces for readability): https://example.com/home #foo:/hello #bar:/settings
Here's what a corresponding React tree in our setup might look like:
<RootRouter> // this is mostly a copy of BrowserRouter and uses a BrowserHistory instance
... page level routing points to /home ...
<SomeApp>
<AppRouter name="foo"> // also similar to BrowserRouter, but uses a custom AppHistory instance
... app level routing, points to /hello ...
</AppRouter>
</SomeApp>
<SomeOtherApp>
<AppRouter name="bar>
... app level routing, points to /settings ...
</AppRouter>
</SomeOtherApp>
</RootRouter>
The custom AppHistory class overwrites methods like push and replace to transform path changes into hash changes for the <RootRouter>'s BrowserHistory
Please let me know if my suggestion is viable and if so, which option you prefer. I'd be happy to submit a pull request to help things along.
Thank you for your awesome work! 👍
The text was updated successfully, but these errors were encountered:
Background
We're building a complex architecture with nested micro services, where multiple "Apps" live in the same React tree. We want to allow these Apps to benefit from independent routing. See description below for details.
Problem
This should work, except for one problem: The
<Router>
component does not like being nested. There is an explicit check on line 288 to prevent this, with the message:You cannot render a <Router> inside another <Router>. You never need more than one.
Unless there's a better way to achieve our requirement, we do indeed need more than one.
Suggestion
As far as I can tell this check did not exist in v5 and is supposed to help developers avoid a common mistake. That is useful, but undermines our use case. My suggestion is to either remove the check or to add a prop that allows disabling it (something like
<Router allowNestedRouter>
) as an informed choice.As far as I can tell there should be no technical limitation preventing this, as
Router
is just a context provider and nested context providers will just shadow their ancestors.Details
Our attempted solution is based on a custom Router with a custom History sub class that can be injected for each App (based on this suggestion). The individual Apps' current pathnames are combined and appended to the page URL's hash via one "main" Router+History.
A URL could look something like this (extra spaces for readability):
https://example.com/home #foo:/hello #bar:/settings
Here's what a corresponding React tree in our setup might look like:
The custom
AppHistory
class overwrites methods likepush
andreplace
to transform path changes into hash changes for the<RootRouter>
'sBrowserHistory
Please let me know if my suggestion is viable and if so, which option you prefer. I'd be happy to submit a pull request to help things along.
Thank you for your awesome work! 👍
The text was updated successfully, but these errors were encountered: