gpt4 book ai didi

javascript - react 路由器 : What is the purpose of IndexRoute?

转载 作者:IT王子 更新时间:2023-10-29 02:42:46 26 4
gpt4 key购买 nike

我不明白使用 IndexRouteIndexLink 的目的是什么。似乎无论如何下面的代码都会首先选择 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>

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

最佳答案

在上面的示例中,转到 / 会呈现 App,其中 Home 作为子级传递。在下面的示例中,转到 / 将呈现 App 既不 Home 也不 About 正在呈现,因为它们的路径都不匹配。

对于旧版本的 React Router,更多信息可在相关版本的 Index Routes and Index Links page 中找到。 .从 4.0 版开始,React Router 不再使用 IndexRoute 抽象来实现相同的目标。

关于javascript - react 路由器 : What is the purpose of IndexRoute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32706913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com