React Router 使用教程
React Router 一个针对React而设计的路由解决方案、可以友好的帮你解决React components 到URl之间的同步映射关系。 本文转载自 阮一峰的日志 基本用法 React Router 安装命令 1 $ npm install -save-dev react-router 路由器Router就是React的一个组件。 12 import { Router } from 'react-router';render(<Router/>, document.getElementById('app')); Router组件本身只是一个容器,真正的路由要通过Route组件定义。 1234567 import { Router, Route, hashHistory } from 'react-router';render(( <Router history={hashHistory}> <Route path="/" component={App}/> </Router>), document.getElementById('app')); 上面代码中,用户访问根路由/(比如 http://www.example.com /),组件APP就会加载到document.getElementById(‘app’)。 你可能还注意到,Router组件有一个参数history