美文网首页
vue history模式 ios微信分享坑

vue history模式 ios微信分享坑

作者: 秀萝卜 | 来源:发表于2022-02-07 13:39 被阅读0次

参考资料:https://blog.csdn.net/weixin_50214760/article/details/115704839

问题描述:ios首次进入后分享失败,但是刷新后可以正常分享

问题分析:ios分享失败是因为签名失败,因为苹果在微信中浏览器机制和安卓不同,有IOS缓存问题,和IOS对单页面的优化问题,通俗点说安卓进行页面跳转分享时会刷新当前的url,而苹果不会,苹果是通过历史记录进来的,不会刷新url所以会导致签名失败

解决办法:

beforeRouteEnter(to, from, next) {
  // XXX: 修复iOS版微信HTML5 History兼容性问题
  if (to.path !== location.pathname) {
  // 此处不可使用location.replace
    location.assign(to.fullPath)
  } else {
    next()
  }
}

再次更新 笨方法解决苹果返回白屏问题

router.beforeEach((to, from, next) => {
  var u = navigator.userAgent;
  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  if(isiOS && to.path!==location.pathname){
    location.assign(to.fullPath)
  }
 setTimeout(() => {
    next()
  }, 100);
})

相关文章

网友评论

      本文标题:vue history模式 ios微信分享坑

      本文链接:https://www.haomeiwen.com/subject/hujmkrtx.html