IOS:每次切换路由,SPA的url是不会变的,发起签名请求的url参数必须是当前页面的url就是最初进入页面时的url
Android:每次切换路由,SPA的url是会变的,发起签名请求的url参数必须是当前页面的url(不是最初进入页面时的)
所以IOS需要修正url路径
router.beforeEach((to, from, next) => {
const agent = navigator.userAgent
const isiOS = !!agent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端
if (!to.meta.requireAuth) {
if (isiOS && to.path !== location.pathname) {
// 此处不可使用location.replace
location.assign(to.fullPath)
} else {
next()
}
} else {
if (!localStorage.getItem("UserCode") || localStorage.getItem("Company") !== '歐嘉璐尼') {
Vue.toast('请先登录!');
next('/login');
} else {
if (isiOS && to.path !== location.pathname) {
// 此处不可使用location.replace
location.assign(to.fullPath)
} else {
next()
}
}
}
window.location.assign(url) : 加载 URL 指定的新的 HTML 文档。 就相当于一个链接,跳转到指定的url,当前页面会转为新页面内容,可以点击后退返回上一个页面。