我微信分享采用的是: 頁面初始化時動態加載js-sdk, 然后在需要分享的頁面進行sdk的分享初始化
app.vue
store.vue
這種方法在安卓上完全正常, 好用得令人發指, 但是!!!
ios卻不是省油燈
ios的分享 參數都沒帶上來 鏈接是第一次進入的頁面 !
破案 ->
IOS:每次切換路由,SPA的url是不會變的,發起簽名請求的url參數必須是當前頁面的url就是最初進入頁面時的url
Android:每次切換路由,SPA的url是會變的,發起簽名請求的url參數必須是當前頁面的url(不是最初進入頁面時的)
解決方法 ->
main.js
1 router.beforeEach((to, from, next) => { 2 const agent = navigator.userAgent; 3 const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios終端 4 if (isiOS && to.path !== location.pathname) { 5 // 此處不可使用location.replace 6 location.assign(to.fullPath) 7 } else { 8 next() 9 } 10 });
ios切換路由, url不是不會變嗎, 我們就在路由守衛里面每次都幫他變一下
by the way !!
location.assign(url) 等價於 location.href = url;