关于vue在hash模式偶发不能后退的处理

问题描述:

在hash模式下,点击返回按钮(通过router)或者通过浏览器的返回按钮(histroy.go(-1))页面的地址发生了变化,但是页面并没有变化。

问题处理:

在app.vue中添加

  // 通过监听hashchange事件 判断当前页面的路由与实际的路由是否一致
   window.addEventListener('hashchange', () => {
            let currPath = window.location.hash.slice(1)
            if (this.$route.path !== currPath) { // 不一致就跳转url的路由
                this.$router.push(currPath)
            }
    }, false)
原文地址:https://www.cnblogs.com/zjianfei/p/15728319.html