H5 history.pushState 在微信內修改url后點擊用safari打開/復制鏈接是修改之前的頁面


解決方案:url參數增加隨機參數

function wxRefresh() { var replaceQueryParam = (param, newval, search) => { var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?'); var query = search.replace(regex, '$1').replace(/&$/, ''); return (query.length > 2 ? query + '&' : '?') + (newval ? param + '=' + newval : ''); }; window.location.replace(location.protocol + '//' + location.host + location.pathname + replaceQueryParam('_wxr_', new Date().getTime(), location.search) + location.hash); }; // 執行 wxRefresh();




優化加入refresh,避免重復刷新
share(route) {
    var replaceQueryParam = (param, newval, search) => {
      var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?')
      var query = search.replace(regex, '$1').replace(/&$/, '')
      return (
        (query.length > 2 ? query + '&' : '?') +
        (newval ? param + '=' + newval : '')
      )
    }

    if (!route.query.refresh) {
      var chat = '&'
      if (!Object.keys(route.query).length) {
        chat = '?'
      }
      window.location.replace(
        location.protocol +
        '//' +
        location.host +
        location.pathname +
        replaceQueryParam('_wxr_', new Date().getTime(), location.search) +
        location.hash +
        chat + 'refresh=true'
      )
    }
  }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM