Vue 禁用浏览器的前进后退操作

一、禁用前进后退功能
1、main.js中,增加popstate监听

window.addEventListener('popstate', function() {history.pushState(null, null, document.URL)
})

2、router的index.js中

const router = new Router({mode: 'hash',routes,scrollBehavior: () => {history.pushState(null, null, document.URL)}
})

也可以尝试放在router的beforeEach/afterEach中

router.afterEach((to, from) => {history.pushState(null, null, location.protocol + '//' + location.host + '/#' + to.path)
})


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部