window.location.replace(href);
试用了也是没效果 也是需要刷新
解决方案:
由于url带?a=555 参数都会导致 ios在第二次分享的时候打开页面空白状态
最后将a=555,进来的时候就setcookie,然后在ulr 带 from等因分享附带的参数 情况下,重定向,重定向url不带?a=555,而将?a=555放到分享的链接上。
代码如下:
export const getSearchUrl = (url) => {
if (url.indexOf('?') !== -1) {
const afterUrl = url.substring(url.indexOf('?') + 1);
const cookieKey = afterUrl.substring(0 , afterUrl.indexOf('='));
const cookieVal = afterUrl.substring(afterUrl.indexOf('=') + 1);
setCookie(cookieKey, cookieVal);
}
};
export const redirect = (url) => {
if (url.indexOf('?') !== -1) {
const beforeUrl = url.substring(0, url.indexOf('?'));
if (window.location.href.indexOf('from') !== -1 || window.location.href.indexOf('isappinstalled') !== -1) {
if (window.location.href.indexOf(beforeUrl) !== -1) {
window.location.href = environment.domainUrl + beforeUrl;
}
}
}
}
export const wxOAuth = (wxAppId: string, url: string) => {
sessionStorage.setItem(LAST_URL, url);
getSearchUrl(url);
const origin = isIOS() ? window.location.origin + '/#/' : window.location.origin;
window.location.href = environment.wxAuthUrl + '/third/authForLogin?authorizerAppid=' + wxAppId + '&businessURI=' + encodeURIComponent(origin);
redirect(url);
};
页面进来,获取id:
activateInfo.queryParams.subscribe(queryParams => {
if (queryParams.mediaActivityParticipantId === '' || queryParams.mediaActivityParticipantId === null || queryParams.mediaActivityParticipantId === undefined) {
this.tutorId = getCookie('mediaActivityParticipantId');
} else {
this.tutorId = queryParams.mediaActivityParticipantId;
}
});
分享代码:
wxShare({
title: '',
desc: '',
link: window.location.origin + '/#/deepCoupling/v-main?mediaActivityParticipantId=' + this.tutorId,
imgUrl: window.location.origin + '/assets/img/deep/share.jpg'
});
页面关闭,清楚改页面cookie
ngOnDestroy() {
delCookie('mediaActivityParticipantId');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…