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

Viewed 49133

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.

Any Idea?

5 Answers

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

After @g-wilson answer I went { path: '*', component: NotFound }. Might be useful if you don't want to make redirect.

Related