【问题标题】:vue-router 4 '/:pathMatch(.*)*' not working?vue-router 4 '/:pathMatch(.*)*' 不工作?
【发布时间】:2022-07-19 11:01:47
【问题描述】:

大家好,我想问一下 vue-router。 当我使用 vue 2 如果页面不匹配时,我使用 path: '*' 转到我的 page404 但在 vue 3 中它已被替换为 '/:pathMatch (.)' 在我尝试之后,控制台中的警告消失了,但我只是得到一个空白页面,它没有指向我的 page404。我错过了什么?我是 vue 3 的新手

这是我正在使用的版本:

  1. vue: ^3.0.0
  2. vue-router: ^4.0.0-0

这是我的 index.js

import { createRouter, createWebHistory, RouterView } from 'vue-router'

const routes = [
   {
      path: '/',
      redirect: '/login',
      component: RouterView,
      children: [{
        path: '/login',
        component: () => import('@/views/login/Login.vue'),
      }]
   },
   {
      path: '/:pathMatch(.*)*',
      component: () => import('@/views/page404/Page404.vue')
   }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

【问题讨论】:

    标签: javascript vue.js vue-router


    【解决方案1】:

    你可以试试这样写

    {
        path: "/:pathMatch(.*)*",
        redirect: "/404"
    },
    {
        path: "/404",
        name: "404",
        component: () => import("@/views/page404/Page404.vue")
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-01
      • 2018-06-14
      • 2020-07-24
      • 2018-02-25
      • 2021-04-20
      • 2018-07-22
      • 1970-01-01
      • 2021-10-16
      • 2020-03-07
      相关资源
      最近更新 更多