一、禁用前进后退功能
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)
})