Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

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布局之对齐方式