import ua from './devices' // 判斷環境用的 function removeHistory () { if (ua.isApp()) { // 防止頁面後退 history.pushState(null, null, document.URL) window.addEventListener('popstate', function () { history.pushState(null, null, document.URL) }) } } export default removeHistory()
原理就是後退的時候,調用popsstate
以後經過history.pushState方法調地址欄當前地址
因此每次後退都是調用當前頁面