防止/禁止页面后退

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方法调地址栏当前地址
所以每次后退都是调用当前页面

 

posted @ 2019-09-17 11:39  Model-Zachary  阅读(124)  评论(0编辑  收藏  举报