vue 不使用 history 模式的時候分享的問題

最近開發vue的時候發現 不使用history模式的時候,二次分享地址會出現很是大的改變html

 

原來的地址  http://www.test.com/html/#/vue

二次分享打開的地址  http://www.test.com/html/?from=singlemessage&isappinstalled=0#/微信

若是有自定義分享地址  http://www.test.com/html/?from=singlemessage&isappinstalled=0#/?user_id=1app

微信分享的時候默認都會在url後面添加from和isappinstalled,這樣若是有支付頁就會出現地址錯誤的問題url

 

解決方法spa

  function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
    // 分享地址進來更新地址
    if(getQueryString('isappinstalled') === '0'){
        window.location.replace(window.location.href.replace(window.location.search,''));
        return false;
    }

 

能夠在app.vue的beforeCreate裏面添加一段這個來作地址跳轉替換。code

當你再次複製地址的時候就會發現地址就正確了。htm

相關文章
相關標籤/搜索