vue3 路由报错 Uncaught Error: Catch all routes (“*“) must now be defined using a param with a custom reg

错误:

const notFound = () => import('@views/404/404.vue')
  {
    path: '*',
    name: '404',
    component: notFound
  }

根据报错信息可得 必须使用正则表达式
解决方案:

const notFound = () => import('@views/404/404.vue')
  {
    // 匹配所有路径  vue2使用*   vue3使用/:pathMatch(.*)*或/:pathMatch(.*)或/:catchAll(.*)
    path: "/:pathMatch(.*)*",
    name: "404",
    component: notFound
  }

你可能感兴趣的:(JavaScript,vue,前端,vue)