用户在退出登录后需要清楚sessionStorage,并且重定向到login页面,但是在没有退出的情况下点击浏览器的后退按钮然后再点击前进不用登陆依然可以访问的原页面,现在需要解决这个问题
这是正常的退出登录功能
logout() {
this.$confirm("Tip: Are you sure you want to logout", {
confirmButtonText: "Log out",
cancelButtonText: "Cancel",
type: "warning",
}).then(() => {
// 点击确认后,清除session用户信息
sessionStorage.clear();
// 跳转到登录页面
this.$router.push("/login");
});
},
在退出后要跳转到的页面 禁止回退页面的mounted( )方法中添加禁止浏览器的后退的方法
触发后禁止浏览器的后退键
history.pushState(null, null, document.URL);
window.addEventListener("popstate",function(e) {
history.pushState(null, null, document.URL);
}, false);