react-router: Nested IndexRoute not working
I have this route setup, where I need nested IndexRoutes
<Route path="/admin" component={App}>
<IndexRoute component={HomeBody}>
<IndexRoute component={Overview}/>
</IndexRoute>
// more routes...
</Route>
But the inner IndexRoute doesn’t ever seem to resolve.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 16 (13 by maintainers)
@ryanflorence Sorry about writing to the closed issue. You’re saying that nesting
IndexRoutes does not make sense, but why not? What if I need complex default structurewithoutany redirects just at my root ('/'path)? As long as new api providescomponentattributes to every route why do you not allow to nest default route component viachildren?Like this: (Here
AppandAuthorizedcomponents just render their children)Another way to accomplish the desired behavior would be using just
Routecomponents withoutpathspecified and inheriting it from parent but that is not working. Like this:But actually this is just the same as using
IndexRoute.Your second example doesn’t work because it’s trying to express
//as a path to navigate to. Each path, even if duplicated, becomes a node in the route tree, separated by slashes (or being a slash itself if there is nothing else in the path).You’re really close. Here’s what you need:
Edit: What @taion said.
That doesn’t make sense, index routes are leaf nodes, can’t be nested.
Should be
@timdorr I appreciate (and I’m using) the solution you gave. However it seems somewhat non-intuitive to me that a
Routecould fall through to anIndexRoutethat is not an immediate child. It seems odd that the grandparent would be able to figure that one of itspath-less children has anIndexRoute, so it should go ahead and fall through. Am I missing something conceptually about React Router?Does that make sense? We can follow up on Reactiflux or Stack Overflow - the issue tracker is not great for this sort of Q&A thing.
Yeah, so it’s nothing conceptual and at some level it’s a bit sloppy, but in practice it’s really convenient for certain kinds of route definitions.
Maybe I am just confusing myself, but the discrepancies between the following cases are not intuitive:
This works:
This does not work:
This also does not work, but I think semantically captures what I am trying to do and should be supported: