我是靠谱客的博主 搞怪金鱼,这篇文章主要介绍Vue路由给每个页面添加参数,现在分享给大家,希望可以做个参考。

    if (to.query.company) {
      next();
      return;
    }
    if (from.query.company) {
      let query = to.query;
      let other = JSON.parse(Cookies.get("query"));
      for (var key in other) {
        query[key] = other[key];
      }
      console.log(query);
      next({
        path: to.path,
        query: query
      });
    } else {
      next();
    }

这样写每个页面是都加上需要的参数的了,但是跳转的时候会报错   Redircted when going from "" to "" via a navigation guard

最终 重写push replace 解决

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  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);
};

 

最后

以上就是搞怪金鱼最近收集整理的关于Vue路由给每个页面添加参数的全部内容,更多相关Vue路由给每个页面添加参数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(132)

评论列表共有 0 条评论

立即
投稿
返回
顶部