问题点:登进去我们系统后,项目经理一直点浏览器自带的后退的功能,一直退到登录页。
如上图的后退按钮。
项目经理问:我们能不能不退回到登录页,能不能禁止点击退出按钮,虽然我觉得这个想法挺流氓的, 但是想到了一个这种事办法。
解决思路:点击退出按钮时,判断是不是会退出到login页面,若是,则回到index页面。代码如下:
window.addEventListener('popstate', function (event) {
const { state } = event
console.warn(state, location)
if (state.current == '/login' && state.forward != '/login') {
history.pushState(null, null, `#/index`)
}
})