DefaultRoute doesn't work with children
I was trying to do this
<Route name="root" path="/" handler={Master}>
<Route name="composer" handler={Composer}>
<DefaultRoute name="browse" path="browse" handler={Browse}>
<Route name="browse-details" path=":id" handler={BrowseDetails}/>
</DefaultRoute>
<Route name="create" handler={Create} />
<Route name="arrange" handler={Arrange} />
</Route>
<Route name="conductor" handler={Conductor} />
<Route name="performer" handler={Performer} />
<DefaultRoute name="home" handler={Home}/>
</Route>
... but a DefaultRoute doesn't seem to work with children. How can I make it so that if you browse to "/composer" you end up at /composer/browse?
I've tried adding <Redirect from="composer" to="browse"/> at the bottom as the last child of root, but that didn't seem to do anything.
Maybe I'm misunderstanding something in the API?
Ran into this too
I encountered the same thing. What worked for me was using an absolute path for the redirect component. So /dashboard will be redirected to /dashboard/company.
Related issue: https://github.com/rackt/react-router/issues/622
<Route name='dashboard' path='dashboard' handler={Dashboard}>
<Redirect from="/dashboard" to="company"/>
<Route name='company' path='company' handler={CompanyProfile} />
<Route name='activities' path='activities' handler={Activities} />
</Route>
Still would be nice not to change the url.
@0x80 <DefaultRoute> isn't supposed to have children. It's just a way to declare a route that will be rendered when none of its siblings match. See also https://github.com/rackt/react-router/issues/701
Try this instead:
<Route name="root" path="/" handler={Master}>
<Route name="composer" handler={Composer}>
<Route name="browse" path="browse" handler={Browse}>
<Route name="browse-details" path=":id" handler={BrowseDetails}/>
</Route>
<Route name="create" handler={Create} />
<Route name="arrange" handler={Arrange} />
<Redirect to="browse" />
</Route>
</Route>
It's just a way to declare a route that will be rendered when none of its siblings match.
You're describing <NotFoundRoute>. <DefaultRoute> is rendered when parent route matches exactly. Your point still stands.
Ah, yes. Please listen to @taurose and ignore me when I make GH comments early in the morning :)
@mjackson thanks that works nicely!