React-router:IndexRoute 与 DefaultRoute
React-router: IndexRoute vs DefaultRoute
我想知道下面示例中的 IndexRoute
和 DefaultRoute
有什么区别?据我了解,在这两种情况下 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>
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.
我想知道下面示例中的 IndexRoute
和 DefaultRoute
有什么区别?据我了解,在这两种情况下 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>
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.