mounted(){
if (window.history && window.history.pushState) {
// @ts-ignore
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.goBack, false);
}
}
methods:{
goBack(){
console.log('支持');
this.$router.replace({path: '/'});
//replace替换原路由,作用是避免回退死循环
}
}
destroyed() {
// 清除监听
window.removeEventListener('popstate', this.goBack, false);
}