http://www.ruanyifeng.com/blog/2016/05/react_router.html
路由的切换方式有两种:
import { hashHistory | browserHistory } from 'react-router'; <Router history={hashHistory | browserHistory}> <Route path="/about" component={About}/> </Router>
两者的关系可以查看这里:http://www.cnblogs.com/hellohello/p/8040289.html
路由组件之间的数据传递,可以认为是页面之间的数据传递,可以使用的方式:cookie,query,localStorage等。
注意sessionStorage不能用于页面之间传递数据,因为每个页面标签都是一个会话。
因为路由的切换,实际上是改变了挂载点中的组件,所以如果使用的是react-redux,可以在挂载点的外面套一个容器组件,容器组件提供了store,而路由组件就可以通过context获取到这个store,即路由组件之间可以通过这个store进行数据共享。
路由切换时,组件的声明周期变化:https://react-guide.github.io/react-router-cn/docs/guides/advanced/ComponentLifecycle.html