react-router

1、window.location当前页面地址信息
属性:
href url完整地址
hash 路由,#开始的部分
search 查询部分,?开始的url
host 主机名及端口号
hostname 主机名
pathname url路径部分
方法:
replace() 替换
reload() 重新加载
如:http://172.16.87.204:8900/?s=1#/invoiceLottery/lotteryRecord?ss=22

href: "http://172.16.87.204:8900/?s=1#/invoiceLottery/lotteryRecord?ss=22"
hash: "#/invoiceLottery/lotteryRecord?ss=22"
search: "?s=1"
host: "172.16.87.204:8900"
hostname: "172.16.87.204"
pathname: "/"

 

2、浏览器history(浏览器历史记录)

history.back(); // 返回上级 (history.go(-1))
history.forward(); // 跳转到下个页面(history.go(1))
history.go(); // 用于指定页跳转

 

3、react的history对象
 
history改造的浏览器history(单页面hash改变加载不同内容)
history.location // 当前页面所在位置
history.push({ pathname: ‘/new-place‘ }); // 路由跳转
history.replace({ pathname: ‘/new-place‘ }); // 路由跳转(覆盖式)
history.goBack(); // 返回上一个页面
history.goForward(); // 跳转下一个页面
history.go(); // 用于指定页跳转
history.listen(); // 监听地址变化,执行相关操作

 

4、react-router是建立在history对象之上
一个history知道如何去监听浏览器地址栏的变化,并解析这个URL转换为location对象,
然后router使用它匹配到路由,最后正确地渲染对应组件

 

5、dva中dva-router使用routerRedux跳转路由
routerRedux.push();
routerRedux.replace();
routerRedux.goBack(); // 返回上一级路由(会刷新页面)

// model里面使用
yield put(routerRedux.goBack());

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...