1.main.js中,增加popstate监听
// 禁止浏览器前进后退 另一部本在router的index.js中
window.addEventListener('popstate', function() {
history.pushState(null, null, document.URL)
})
2.router的index.js中:
// 禁止浏览器 前进和后退,另一部分在main.js中
const router = new VueRouter({
mode: 'history',
routes,
scrollBehavior: () => {
history.pushState(null, null, document.URL)
}
})
参考连接:https://blog.youkuaiyun.com/weixin_42217154/article/details/109776249