React-Router

React-Routerhtml

  React-Router的本質是根據當前location,決定是否繪製component。要使用React-Router有幾個要點:react

  1)根結點必須是Router,且Router只能有一個子結點。git

  2)Router內隨意旋轉Route,Route根據當前location,決定是否繪製component。github

 

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

  

  1)v4以上版本,須要經過createBrowserHistory創造history對象。已沒有browserHistory這個定義。api

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. 只能有一個子結點。react-router

 

參考:https://reacttraining.com/react-router/web/api/Linkapp

相關文章
相關標籤/搜索