vue项目,路由采用的是vue-router hash #模式,在微信中分享页面的时候,config 配置没有问题,后台正常返回。在要分享页面注入分享信息的时候,如下
created () {
this.title = window.location.href
this.content = window.location.href.split("#")[0]
let url = window.location.href.split("#")[0]+"#"+window.location.href.split("#")[1]
this.pin = url
let that = this
wx.ready(() => {
wx.onMenuShareTimeline({
title: '我是分享到朋友圈', // 分享标题
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: '', // 分享图标
success: function (res) {
// 用户点击了分享后执行的回调函数
that.$messagebox({
title: 'success朋友圈',
content: res
})
}
}),
wx.onMenuShareAppMessage({
title: '我是分享到朋友', // 分享标题
desc: '朋友朋友', // 分享描述
link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: '', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户点击了分享后执行的回调函数
that.$messagebox({
title: 'success朋友',
content: res
})
}
});
})
}
分享到朋友圈和分享给朋友的时候,分享出去的链接被微信插入了一段字符串如下
原本想分享的链接:http://www.xxx.com/test/#/share
分享给朋友后的链接:http://www.xxx.com/test/?from...
分享到朋友圈后的链接:http://www.xxx.com/test/?from...
都是在#号前面插入
在iOS和android上 互相分享都是一样的情况 分享后的页面能正常打开,但是如果在链接后面跟上参数的话就不能获取到了。如何跳坑
二次分享时,微信会自动在url后加上from=singlemessage&isappinstalled=0
在连接后加上your url?&from=singlemessage&isappinstalled=0再进行分享,即可分享成功