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 sql中left join,right join,inner join,full join之间的区别
sql中left join,right join,inner join,full join之间的区别
2
Android inflate()引发NullPointerException
Android inflate()引发NullPointerException
3
Redis单体及集群支持的数据库数量
Redis单体及集群支持的数据库数量
4
numpy.linalg学习
numpy.linalg学习
5
JWT InvalidClaimException - The Token can't be used before
JWT InvalidClaimException - The Token can't be used before
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。