[Vue warn]: Error in beforeCreate hook: "RangeError: Maximum call stack size exc

630 阅读1分钟

问题概述

本地启动vue项目无报错, 访问页面时 出现错误 RangeError: Maximum call stack size exceeded,

image.png

解题思路

因访问路由出现问题, 故排查重点在路由。按照错误类型为无限套娃导致的栈溢出, 排查方向为 查看路由中是否存在循环问题。源代码如下:

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login,

    },

    {
      path: '/Public',
      name: 'Public',
      redirect:'Index',
      component: Public,
      children:[
        {
          path: '/Index',
          name: 'Index',
          component: Index,
          redirect:'/Index'
        },
        ...

发现路由地址path重定向地址redirect一样, 出现一直在路由地址和重定向地址无限跳转, 最终导致栈溢出。更改如下:

...
    {
      path: '/Index',
      name: 'Index',
      component: Index,
    },
...