JS跳转阻止后退至上一页面,没有历史记录

window.location.replace

window.location.replace('要转向的页面')  //不会有历史记录

let backLen = history.length
history.forward()
history.go(-backLen) // Return at the beginning
window.location.replace('/#/home')

window.location.hash

JS通过改变location.hash时清除history

通过使用以下方法来给hash赋值

window.location.hash = 'hash的值'

会在window.history新增一条历史记录,如果想清除掉这条记录(不清除的话点击返回会回到上一个hash值的页面),可以使用

window.location.replace(window.location.href.toString().replace(window.location.hash, '') + "#" + "hash的值")
上一篇 H5中localStorage和sessionStorage区别
下一篇 Flexbox布局之对齐方式
目录
文章列表
1 布隆过滤器的方式解决缓存穿透问题
布隆过滤器的方式解决缓存穿透问题
2
Node.js包管理工具yarn安装使用
Node.js包管理工具yarn安装使用
3
Called attach on a child which is not detached ViewHolder问题解决
Called attach on a child which is not detached ViewHolder问题解决
4
Flutter Widget之InkWell
Flutter Widget之InkWell
5
Jenkins构建ant-design-pro项目
Jenkins构建ant-design-pro项目
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。