小编典典

反应路由器比赛小姐

reactjs

什么是使用的优势MatchMiss部件免受react-routerRouter组件?我似乎在react-router
docs中
找不到关于此的任何文档

我的问题源于更准确地通过查看以下内容来查看react-universally样例:https :
//github.com/ctrlplusb/react-universally


阅读 251

收藏
2020-07-22

共1个答案

小编典典

<Match>并且<Miss>是React Router v4的Alpha版本中的组件。

在Beta中,<Match>已重命名<Route>(其道具也已更改,因此
pattern现在pathexactly现在exact)。该<Miss>组件已完全删除。相反,您应该使用一条<Switch>语句,该语句仅呈现匹配的第一个<Route>(或个<Redirect>)。您可以将无路径组件添加为<Switch>的路由的最后一个子组件,并且当前一个都不<Route>匹配时,它将呈现。

您可以查看API文档以了解更多详细信息。

<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>
2020-07-22