反应路由器匹配未命中 [英] React Router Match Miss

查看:62
本文介绍了反应路由器匹配未命中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the advantage of using Match and Miss components from react-router over Router component? I cannot seem find any documentation about this in react-router docs.

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

My question spawns from looking at react-universally boilerplate, more exactly, by looking here: https://github.com/ctrlplusb/react-universally

推荐答案

是 React Router v4 alpha 版本中的组件.

<Match> and <Miss> were components in the alpha release of React Router v4.

在测试版中, 已重命名为 (并且其道具已更改,因此 pattern 现在是pathexactlyexact). 组件被完全删除.相反,您应该使用 语句,它只会呈现第一个 (或 )匹配.您可以添加一个无路径组件作为 <Switch> 路由的最后一个子节点,并且当前面的 不匹配时,它将呈现.

In the beta, <Match> has been renamed <Route> (and its props have changed so that pattern is now path and exactly is exact). The <Miss> component was removed entirely. Instead you should use a <Switch> statement, which will only render the first <Route> (or <Redirect>) that is matched. You can add a pathless component as the last child of the <Switch>'s routes and it will render when none of the preceding <Route>s match.

您可以查看 API 文档了解更多详情.

You can check out the API documentation for more details.

<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>

这篇关于反应路由器匹配未命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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