gpt4 book ai didi

reactjs - React 路由器匹配失败

转载 作者:行者123 更新时间:2023-12-03 13:12:53 24 4
gpt4 key购买 nike

Router 组件相比,使用 react-router 中的 MatchMiss 组件有什么优势?我似乎在 react-router docs 中找不到任何关于此的文档.

我的问题源于查看 react-universally更准确地说,请查看此处的样板:https://github.com/ctrlplusb/react-universally

最佳答案

<Match><Miss>是 React Router v4 alpha 版本中的组件。

在测试版中,<Match>已更名为<Route> (它的 props 已经改变, pattern 现在是 pathexactlyexact )。 <Miss>组件被完全删除。相反,您应该使用 <Switch>语句,它只会渲染第一个 <Route> (或 <Redirect> )匹配。您可以添加无路径组件作为 <Switch> 的最后一个子组件。的路线,当没有前面的 <Route> 时它将渲染匹配。

您可以查看API documentation了解更多详情。

<Switch>
<Route exact path='/' component={Home} />
<Route path='/about' component={About} />
// The following <Route> has no path, so it will always
// match. This means that <NoMatch> will render when none
// of the other <Route>s match the current location.
<Route component={NoMatch} />
</Switch>

关于reactjs - React 路由器匹配失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42362457/

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