react-router
2016-03-22 11:32
603 查看
react-router
路由:保证url和视图同步
react-router是在react基础上建立起来的,
react渲染通过:props/state–>component–>ui;
react-router渲染通过:location–>route–>ui;
router,route是react组件,与其他前端的主要区别是route是组件
历史记录的管理
h5的history API:
- history.back();浏览器返回键
- history.forward();浏览器前进行为
- history.go(-1);从session历史导入特定页面
- history.pushState(state, title, url);向历史记录栈顶添加一条记录(包括ajax),存储state对象,只能入栈
- history.replaceState();更改当前的历史记录
- history.state;存储的state数据
前进或后退触发popstate事件,取出state对象
在 react-router 内部将该对象存储到了 sessionStorage,saveState 操作
也可使用地址栏location.hash值模拟
1. 使用hashchange事件监听window.location.hash变化
2. hash变化时浏览器更新url,并在history栈产生一条记录
3. 路由系统会将所有的路由信息都保存到 location.hash 中
4. react-router 内部注册hashchange
5. 通过判断currentLocation 与nextLocation 是否相同来决定是否调用transitonTo(location)跳转
react-router教程
github
路由:保证url和视图同步
react-router是在react基础上建立起来的,
react渲染通过:props/state–>component–>ui;
react-router渲染通过:location–>route–>ui;
import { Router, Route, browserHistory } from 'react-router'
router,route是react组件,与其他前端的主要区别是route是组件
历史记录的管理
h5的history API:
- history.back();浏览器返回键
- history.forward();浏览器前进行为
- history.go(-1);从session历史导入特定页面
- history.pushState(state, title, url);向历史记录栈顶添加一条记录(包括ajax),存储state对象,只能入栈
- history.replaceState();更改当前的历史记录
- history.state;存储的state数据
前进或后退触发popstate事件,取出state对象
在 react-router 内部将该对象存储到了 sessionStorage,saveState 操作
也可使用地址栏location.hash值模拟
1. 使用hashchange事件监听window.location.hash变化
2. hash变化时浏览器更新url,并在history栈产生一条记录
3. 路由系统会将所有的路由信息都保存到 location.hash 中
4. react-router 内部注册hashchange
5. 通过判断currentLocation 与nextLocation 是否相同来决定是否调用transitonTo(location)跳转
react-router教程
github
相关文章推荐
- React Native 开发笔记
- React-Native入门指导之iOS篇
- React-周边类库
- React入门教程(二)
- 使用React并做一个简单的to-do-list
- React-服务器端渲染
- ReactNative 代码智能提醒(webstorm)
- React-性能优化详解
- React-动画详解
- React Native学习笔记-1:JSC profiler is not supported.(转载)
- React.js入门必须知道的那些事
- React Native: 把现代web科技带给移动开发者
- [转] 三步将你的 React Native 项目运行在 Web 浏览器上面
- React Native 开始~
- 一分钟搭建Webpack+react+es6框架
- React/React Native 的ES5 ES6写法对照表
- ReactJS学习笔记——生命周期、数据流与事件
- React Native 运行出现 Could not connect to development server 解决方法
- React ajax
- React Native android真机运行时候 界面一片空白