React-Router:IndexRoute 的目的是什么?
React-Router : What is the purpose of IndexRoute?
我不明白使用 IndexRoute 和 IndexLink 的目的是什么。似乎无论如何下面的代码都会首先选择 Home 组件,除非 About 路径被激活。
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="about" component={About}/>
</Route>
对
<Route path="/" component={App}>
<Route path="home" component={Home}/>
<Route path="about" component={About}/>
</Route>
第一种情况advantage/purpose这里是什么?
在最上面的示例中,转到 /
会呈现 App
,其中 Home
作为子级传递。在下面的示例中,转到 /
会渲染 App
,而 Home
和 About
都不会被渲染,因为它们的路径都不匹配。
对于旧版本的 React Router,可在相关版本的 Index Routes and Index Links page 上获得更多信息。从 4.0 版开始,React Router 不再使用 IndexRoute
抽象来实现相同的目标。
我不明白使用 IndexRoute 和 IndexLink 的目的是什么。似乎无论如何下面的代码都会首先选择 Home 组件,除非 About 路径被激活。
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="about" component={About}/>
</Route>
对
<Route path="/" component={App}>
<Route path="home" component={Home}/>
<Route path="about" component={About}/>
</Route>
第一种情况advantage/purpose这里是什么?
在最上面的示例中,转到 /
会呈现 App
,其中 Home
作为子级传递。在下面的示例中,转到 /
会渲染 App
,而 Home
和 About
都不会被渲染,因为它们的路径都不匹配。
对于旧版本的 React Router,可在相关版本的 Index Routes and Index Links page 上获得更多信息。从 4.0 版开始,React Router 不再使用 IndexRoute
抽象来实现相同的目标。