history.pushState

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);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章