React-router:IndexRoute vs DefaultRoute

时间:2015-09-27 09:09:08

标签: javascript reactjs react-router

我想知道下面示例中IndexRouteDefaultRoute之间的区别是什么?据我所知,在这两种情况下都会呈现Home,对吧?

<Route path="/" handler={App}>
  <IndexRoute handler={Home}/>
  <Route path="about" handler={About}/>
</Route>

<Route path="/" handler={App}>
  <DefaultRoute handler={Home}/>
  <Route path="about" handler={About}/>
</Route>

1 个答案:

答案 0 :(得分:8)

DefaultRoute从react-router v1.0开始消失了。而是引入了IndexRoute

来自文档:

// v0.13.x
// with this route config
<Route path="/" handler={App}>
  <DefaultRoute name="home" handler={Home}/>
  <Route name="about" handler={About}/>
</Route>

// v1.0
<Route path="/" component={App}>
  <IndexRoute component={Home}/>
  <Route path="about" component={About}/>
</Route>

upgrade guide.

中的更多内容