"Cannot read properties of undefined (reading 'matched')"

新手上路,请多包涵

vue cli要根据路由生成菜单,于是将new Router赋值给一个常量,再将常量导出,但是会报错
image.png
页面也渲染不出来。
具体代码如下

更改前代码↓

const routes = [
  {
    name: "layout",
    path: '/',
    component: () => import('@/layout'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: home,
        meta: { title: '首页' }
      },
    ]
  },
]
export default new Router({({
  routes: routes
})

更改后代码↓

const routes = [
  {
    name: "layout",
    path: '/',
    component: () => import('@/layout'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: home,
        meta: { title: '首页' }
      },
    ]
  },
]
const router = new Router({
  routes: routes
})

请问这是为什么?。。

阅读 7.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题