react-router安裝命令
npm install -S react-router
react-router的使用
import { Router, Route, hashHistory } from 'react-router';
render((
<Router history={hashHistory}>
<Route path="/" component={App}/>
</Router>
), document.getElementById('app'));
Router組件有一個(gè)參數(shù)history,它的值hashHistory表示,路由的切換由URL的hash變化決定
嵌套路由
<Router history={hashHistory}>
<Route path="/" component={App}>
<Route path="/repos" component={Repos}/>
<Route path="/about" component={About}/>
</Route>
</Router>
用戶訪問repos組件的時(shí)候會(huì)先加載app再加載repos
IndexRoute
默認(rèn)情況下加載的組件
<Router>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="accounts" component={Accounts}/>
<Route path="statements" component={Statements}/>
</Route>
</Router>