React-Router:IndexRoute的目的是什么? [英] React-Router : What is the purpose of IndexRoute?

查看:112
本文介绍了React-Router:IndexRoute的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白使用 IndexRoute IndexLink 的目的是什么。似乎在任何情况下,除非关闭路径被激活,否则下面的代码将首先选择Home组件。

I don't understand what the purpose of using an IndexRoute and IndexLink. It seems that in any case the code below would of selected the Home component first unless the About path was activated.

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

vs

<Route path="/" component={App}>
  <Route path="home" component={Home}/>
  <Route path="about" component={About}/>
</Route>

第一种情况的优势/目的是什么?

What's the advantage/purpose here of the first case?

推荐答案

在上面的示例中,转到 / 将呈现 App Home 作为孩子传递。在下面的示例中,转到 / 将呈现 App ,其中既不 主页关于正在呈现,因为它们的路径都不匹配。

In the top example, going to / would render App with Home passed as a child. In the bottom example, going to / would render App with neither Home nor About being rendered, since neither of their paths match.

对于旧版本的React Router,有关关联版本的更多信息索引路径和索引链接页面。从版本4.0开始,React Router不再使用 IndexRoute 抽象来实现相同的目标。

For older versions of React Router, more information is available on associated version's Index Routes and Index Links page. Starting in version 4.0, React Router no longer uses the IndexRoute abstraction to achieve the same goal.

这篇关于React-Router:IndexRoute的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆