how to create a 404 component in vuejs using vue-router

后端 未结 5 1073
慢半拍i
慢半拍i 2020-12-13 13:13

I\'m new to vuejs and I\'m working on my first project with vue. I\'m just wondering how I will route to my 404.vue component when the requested url is not found.

An

5条回答
  •  [愿得一人]
    2020-12-13 13:35

    Now in Vue 3 path: '*' will not work. we have to use regex: /:catchAll(.*)

    We can use directly instead of using path: "*"

    {
        // path: "*",
        path: "/:catchAll(.*)",
        name: "NotFound",
        component:NotFound,
    }
    

    or

    {
        path: '/404', name: 'NotFound', component: NotFound
    },
    {
        path: '/:catchAll(.*)', redirect:'404'
    }
    

    I got it from here

提交回复
热议问题