【学習記録16】vue3で404ルーティングを設定する

Vue3 は 404 構成を変更したため、通常のマッチングを使用する必要があります 

通常のパラメータは、 で区切られた URL フラグメント間の文字のみと一致します / 。任意の path と一致させたい場合は、カスタムの path パラメータ 正規表現を使用して、  path パラメータ の後に括弧内に正規表現を追加します。

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-見つかりません-%E8%B7%AF%E7%94%B1

Guess you like

Origin blog.csdn.net/wenhui6/article/details/121909447