如题,由于场景需要,所以在全局前置守卫beforeEach里面加了公用参数
if (!to.query.source || !to.query.saleChannelId) {
const query = {
...to.query,
source: window.localStorage.getItem('_source'),
saleChannelId: window.localStorage.getItem('_saleChannelId'),
};
next &&
next({
path: to.path,
query: query,
});
} else {
next && next();
}
但是也引发一个问题,就是同一个页面会进入两次,虽然我在use(router)前加了如下代码解决了报错提示,但是不解决重复进入的问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err);
};
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
return originalReplace.call(this, location).catch(err => err);
};
next && next();
前面的next是干嘛的?可能是它导致的