React-Router

React-Router

  React-Router的本质是根据当前location,决定是否绘制component。要使用React-Router有几个要点:

  1)根结点必须是Router,且Router只能有一个子结点。

  2)Router内随意旋转Route,Route根据当前location,决定是否绘制component。

 

  The common low-level interface for all router components. Typically apps will use one of the high-level routers instead:

  

  1)v4以上版本,需要通过createBrowserHistory创造history对象。已没有browserHistory这个定义。

import { Router } from 'react-router'
import createBrowserHistory from 'history/createBrowserHistory'

const history = createBrowserHistory()

<Router history={history}>
  <App/>
</Router>

  2)A single child element to render. 只能有一个子结点。

参考:https://reacttraining.com/react-router/web/api/Link

原文地址:https://www.cnblogs.com/tekkaman/p/6991565.html