方法一
afterEach(to, from) {
const u = navigator.userAgent.toLowerCase()
if (u.indexOf('like mac os x') < 0 || u.match(/WebP/i) === 'webp') return
if (to.path !== global.location.pathname) {
location.assign(to.fullPath)
}
}
方法二
beforeEach(to, from, next) {
next()
var replaceUrl = window.location.href.split('#')[0] + '#' + to.path;
var index = 0; // 索引初始化
// 给replaceUrl拼接参数
for (var i in to.query) {
// 判断是否等于第一个参数
if (index === 0) {
// 拼接地址第一个参数,添加“?”号
replaceUrl += '?' + i + '=' + to.query[i]
} else {
// 拼接地址非第一个参数,添加“&”号
replaceUrl += '&' + i + '=' + to.query[i]
}
index++; // 索引++
}
window.location.replace(replaceUrl); // 重定向跳转
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。