当页面跳转后,侧边滚轴会还是一个页面位置
router.afterEach(() => {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
页面跳转同一页面,报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err);
};
手机、电脑端路由跳转
const routes = [{
path: '/',
beforeEnter(to, from, next) {
let path;
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
console.log('-----这里是移动端-----');
path = '/MB';
} else {
console.log('-----这里是电脑端-----');
path = '/PC';
}
next(path);
},
}]