Reactjs React Router |如何同时使用IndexRoute和重定向?版本:1.0.0-rc1

Reactjs React Router |如何同时使用IndexRoute和重定向?版本:1.0.0-rc1,reactjs,react-router,Reactjs,React Router,如标题所示,如何将它们结合使用 像这样: <Router history={history}> <Route path="/" component={Root}> <Route path='home' component={HomeContainer}></Route> <Route path='about' component={AboutContainer}></Route> <Ind

如标题所示,如何将它们结合使用

像这样:

<Router history={history}>
  <Route path="/" component={Root}>
    <Route path='home' component={HomeContainer}></Route>
    <Route path='about' component={AboutContainer}></Route>

    <IndexRoute component={HomeContainer}/>
  </Route>
</Router>

但这似乎是一个小小的解决办法。

对我来说,最好的解决方案是使用onEnter函数。不确定这在1.x上的效果如何,因为我在2.0上使用它

<IndexRoute onEnter={(targetState, replace) => {replace('/home')}} />

您能展示一些示例URL吗?我发现很难理解你想要的行为。在问题中添加一些澄清:
componentDidMount() {
  this.history.pushState(null, `/home`, null);
},
<IndexRoute onEnter={(targetState, replace) => {replace('/home')}} />