In pseudo code, what I propose is that a Switch does the following
for routeOrSwitch in switch:
component = routeOrSwitch.match(location)
if component:
return render(component)
This would not change the semantics of Switch and make it possible to compose (and therefore: reuse) Switches.
ps using React.Fragment to group Routes (something that has been proposed) has less clear semantics, so I would prefer to allow nesting Switches.
I'm not sure I quite understand what you're getting at here, but they certainly do nest: https://reacttraining.com/react-router/web/example/nesting
Hi Tim, what I meant is that a Switch should be able to contain not only Routes but also other Switches. It would not change the semantics of a Switch: it still picks the first child routeOrSwitch that matches the location. This would make Switches composable, which would be a good thing.
Most helpful comment
Hi Tim, what I meant is that a Switch should be able to contain not only Routes but also other Switches. It would not change the semantics of a Switch: it still picks the first child
routeOrSwitchthat matches the location. This would make Switches composable, which would be a good thing.