- 安装router
npm install --save-dev react-router
- 在入口文件中引入router
import { Router, Router, hashHistory} from 'react-router'
普通的路由使用方法
123456789ReactDOM.render((<Router history={hashHistory}><Route path="/page" component={Page}></Route><Route path="/list" component={List}></Route></Router>),document.querySelector("#App"))嵌套路由的使用方法
入口index.jsx
1234567891011ReactDOM.render((<Router history={hashHistory}><Route path="/" component={App}><Route path="/page" component={Page} /><Route path="/list" component={List} /></Route></Router>),document.querySelector("#App"))App.jsx,render返回
1return(<div className="wide">{this.props.children}</div>)
嵌套中使用IndexRoute组件
IndexRoute就是根路径/
时访问的页面123456789101112ReactDOM.render((<Router history={hashHistory}><Route path="/" component={App}><IndexRoute component={Main} /><Route path="/page" component={Page} /><Route path="/list" component={List} /></Route></Router>),document.querySelector("#App"))