React-router: IndexRoute和DefaultRoute的区别

4

我想知道以下示例中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个回答

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>

升级指南中有更多相关的内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接