vue移动端keepalive与微信分享冲突

1.目前遇到一个问题,一个列表页面list,一个详情页面detail,列表页为了从详情页返回的时候能保留浏览位置,设置了keepAlive为true,在beforerouterenter中进行判断,这个一直没有问题。

beforeRouteEnter (to, from, next) {
      if(from.name === 'Product'){
        to.meta.isBack=true;
      }else{
        to.meta.isBack=false;
      }
      next()
    },
    
     activated(){
      var vm = this;


      if(!this.$route.meta.isBack){
        //请求数据
        sendRequest();
      }else{
          //不请求数据
      }
    },

但是最近新加的详情页分享功能,因为每次分享出去的链接都是首页链接,所以为了修复这个问题,在beforerouterenter中加了

const agent = navigator.userAgent;
        const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        if (isiOS && to.path !== location.pathname) {
          // 此处不可使用location.replace
          location.assign(to.fullPath)
        } else {
          next()
        }

这就导致了一个问题,从列表页进入详情页存在一个类似刷新的操作,然后点击返回的时候,在list页面的beforerouterenter中获取from.name为null,这就导致了to.meta.isBack=false;每次回列表页都会重新请求一下接口。
而且即使我设置了

beforeRouteEnter (to, from, next) {
       to.meta.isBack=true;
      next()
    },

返回到列表还是会请求接口刷新页面。不知道大家有没有遇到这样的问题

阅读 1.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题