在开发微信公众号页面时,有时需要调用微信授权的接口,要用当前页的页面链接去获取授权信息,但是在IOS上当前页的链接不是当前页的,而是入口页面的链接,在这里我们可以用下面的方法对当前页进行操作来解决这个问题
export default{
beforeRouteEnter (to, from, next) {
let u = navigator.userAgent;
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
// XXX: 修复iOS版微信HTML5 History兼容性问题
if (isiOS && to.path !== location.pathname) {
// 此处不可使用location.replace
location.assign(to.fullPath)
} else {
next()
}
}
}