-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Support nested Switches #467
Comments
yeah I had the same problem that switch does not work well with nested routes like:
<Router base="...">
<Route path="/component-tree-a" nest>
<>
<Route path="/">
<ComponentA/>
</Route>
<Route path="/config">
<ComponentB/>
</Route>
</>
</Route>
<Route path="/component-tree-b" nest>
<ComponentTreeBRouter/>
</Route>
<Route><Error404RouteComponent/></Route>
</Switch>
</Router> actually I created a
switch than looks like:
I would prefer if something like:
but looks like that might be hard to support... |
@schmitch It's a bit hard to follow what your problem with nested routes is. Can you give an example of the thing that doesn't work for you, but only using Switch and Route? (and no custom components). Or is it (exactly) the same problem as what I posted? |
@mnieber actually the custom components is the problem. we prefer them to make nested routes since we have tons of routes |
I need something like this so that some routes share a context provider. // App.jsx
<Switch>
<Route path="/a" component={A} nest />
<Route path="/b" component={B} />
</Switch>
// A.jsx
<Provider>
<Switch>
<Route path="/1" component={A1} />
<Route path="/2" component={A2} />
</Switch>
</Provider> |
@haggen It looks like your example would already work with the current Switch. Doesn't it work? |
@mnieber Oh indeed it does! Reading the docs I was under the impression that Routes needed to be directly nested. Thanks! |
Hi, I've read the docs to see if nested Switches are supported (a longstanding wish), and I think they are not, so I wanted to make a feature proposal.
The idea is that a switch picks the first matching route or switch. A switch matches if one of its routes (or switches) matches. It's basically the Composite pattern.
The use-case is this one:
If I want to create separate route groups for "color" or "food" then it would be great if I can refactor this to
The text was updated successfully, but these errors were encountered: