react-router

react-router
路由:保证url和视图同步
react-router是在react基础上建立起来的,
react渲染通过:props/state–>component–>ui;
react-router渲染通过:location–>route–>ui;

import { Router, Route, browserHistory } from 'react-router'
  1. router,route是react组件,与其他前端的主要区别是route是组件
  2. 历史记录的管理

h5的history API:
- history.back();浏览器返回键
- history.forward();浏览器前进行为
- history.go(-1);从session历史导入特定页面
- history.pushState(state, title, url);向历史记录栈顶添加一条记录(包括ajax),存储state对象,只能入栈
- history.replaceState();更改当前的历史记录
- history.state;存储的state数据

  1. 前进或后退触发popstate事件,取出state对象
  2. 在 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值