-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't nest Switch
components
#107
Comments
I was thinking maybe we could find a solution if we flattened the loggedIn routes. I'm not 100% sure I'm parsing the issue as described, so this might not be a step in the right direction anyway. Ultimately, don't think this is a good avenue to explore as a change to boilermaker. But I did find it interesting. <Switch>
{someCondition && [
<Route
path="/conditional-a"
component={() => <h1>Conditional A</h1>}
/>,
<Route
path="/conditional-b"
component={() => <h1>Conditional B</h1>}
/>,
]}
<Route
path="/non-fragment"
component={() => <h1>Not Conditional</h1>}
/>
<Route
path="/"
component={() => <h1>Home</h1>}
/>
</Switch> Arguments against this:
I also tried using |
Hm, that's an interesting possibility. I think the Maybe we can double down on this. Put all routes in arrays (and Alternatively, we back off from truly dealing with this in Boilermaker, but put in a comment that says if the inner |
React-Router explicitly states that only
Router
andRoute
components should be children ofSwitch
.We have nested
Switch
es in our current codebase, in order to make some routes exist only if the user is logged in. However, if a user tries to go to a non-recognized route, we currently render a fallback route until the user is asynchronously logged in (at which point one would hope the route becomes recognized).Unfortunately, this fallback route does not trigger if placed below the nested
Switch
and the user is logged in, but the route does not match anything in the sub-switch. This is becauseSwitch
components are misinterpreted by the parentSwitch
as actually being an unconditional (pathless) route – so no routes below them will ever trigger.A student had this issue. The solution we came up with was to duplicate the fallback route inside the nested switch, which wasn't very DRY. The student subsequently created an issue here. A user responded with the following alternative:
The text was updated successfully, but these errors were encountered: