使用hash路由作为微信回调地址时,回调返回的路由会出现
http://localhost:3001/code=AZr6xKJ5iGDjK_1mSoNGlvYiG7m0Uhg&state=812#/wechat
这样的返回格式。导致无法正常获取code
解决方法:
将路由重置,重新跳转
if (href.includes("/?code")) {
//url包括 /?code 证明为从微信跳转回来的
const hrefArr = href.split('/?')
const urls = hrefArr[1].split('#/')
window.location = hrefArr[0] + "#/" + urls.reverse().join('?');//拼接跳转
return
}
另:相关帖子关于urlencode加密的解决方案,经过测试,并不适用于当前问题,