【学习记录16】vue3配置404路由

vue3对404配置进行了修改,必须要使用正则匹配 

常规参数只匹配 url 片段之间的字符,用 / 分隔。如果我们想匹配任意路径,我们可以使用自定义的 路径参数 正则表达式,在 路径参数 后面的括号中加入 正则表达式 :

import {
  createRouter,
  createWebHashHistory
} from 'vue-router'

const routes = [
  {
    path: '/404',
    name: 'NoPage404',
    component: NoPage,
    hidden: true
  },
  {
    path: '/:pathMatch(.*)',
    redirect: '/404',
    hidden: true
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
export default router

官网链接icon-default.png?t=LA92https://next.router.vuejs.org/zh/guide/essentials/dynamic-matching.html#%E6%8D%95%E8%8E%B7%E6%89%80%E6%9C%89%E8%B7%AF%E7%94%B1%E6%88%96-404-not-found-%E8%B7%AF%E7%94%B1

猜你喜欢

转载自blog.csdn.net/wenhui6/article/details/121909447