1. 程式人生 > >"Vue單頁式應用(Hash模式下 '/#/')分享出來的連結點開是首頁”問題解決

"Vue單頁式應用(Hash模式下 '/#/')分享出來的連結點開是首頁”問題解決

解決方案:頁面中轉,url重定向。

1,在static目錄下新建一個名為html的資料夾,在html資料夾中再新建一個redirect.html

html中寫入以下內容

<script>
    let url = location.href.split('?')
    let pars = url[1].split('&')
    let data = {}
    pars.forEach((n, i) => {
        let p = n.split('=')
        data[p[0]] = p[1]
    })
    if (!!data.app3Redirect) {
        self.location = decodeURIComponent(data.app3Redirect)
    }

</script>

只需要script標籤就可以了,反正只是做重定向。

2,在商品詳情頁的內容如下,注意:link: shareWxLink,

shareconfig:function(){
    var _that = this;
    wx.ready(function () {
        var shareWxLink = window.location.href.split('#')[0] + 'static/html/redirect.html?app3Redirect=' + encodeURIComponent(window.location.href);

        wx.onMenuShareTimeline({
            title: '【網上古玩城】' + _that.goods_detail.goods_name, // 分享標題
            link: shareWxLink,        // 分享連結,該連結域名或路徑必須與當前頁面對應的公眾號JS安全域名一致
            imgUrl: _that.shareimg, // 分享圖示
            success:function() {
                _that.$dialog.toast({
                    mes: '分享朋友圈成功',
                    timeout: 1500,
                    icon: 'success'
                });
                // 使用者確認分享後執行的回撥函式
            },
            cancel:function() {
                // 使用者取消分享後執行的回撥函式
            }
        });

        wx.onMenuShareAppMessage({
            title: '【網上古玩城】' + _that.goods_detail.goods_name, // 分享標題
            desc: _that.goods_detail.goods_content, // 分享描述
            link: shareWxLink,  // 分享連結,該連結域名或路徑必須與當前頁面對應的公眾號JS安全域名一致
            imgUrl: _that.shareimg, // 分享圖示
            success: function () {
                // alert('分享給朋友成功')
                _that.$dialog.toast({
                    mes: '分享給朋友成功',
                    timeout: 1500,
                    icon: 'success'
                });
                // 使用者確認分享後執行的回撥函式
            },
            cancel: function () {
                // 使用者取消分享後執行的回撥函式
            }
        })
    })
}

跳轉頁面完成!