vue ssr 服务端 路由 报错 err= TypeError: Converting circular structure to JSON

  • 代码:
      let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
      matched.map(val => {
        // 解决方法
        val.instances = {}
      })
      // levelList = this.jsons(levelList)
      this.$store.commit('app/TOGGLE_NEVLIST', this.levelList)
  • 报错:
error during render : url=/rank/soft err= TypeError: Converting circular structure to JSON
     --> starting at object with constructor 'Vue'
     |     property '$options' -> object with constructor 'Object'
     |     property 'router' -> object with constructor 'VueRouter'
     --- property 'app' closes the circle
     at JSON.stringify (<anonymous>)
  • 解决思路:
  1. vue的 $router在执行的时候会使用JSON.stringify去处理路由
  2. node环境中是拒绝循环引用的1.
  3. this.$route.matched.filter返回的数据中 instances 执行 当前的对象(暂时认为是当前路由对象,欢迎举证)
  4. 上面(1)中 存在循环引用 报错
  5. 把instances 指向空对象能避免后面路由的使用报错
原文地址:https://www.cnblogs.com/YOUNGZZ/p/13633323.html