Tchiteu Abloh
Tchiteu Abloh

Reputation: 564

How to redirect to page 404 not found

What is the easiest way to configure routes, so that when a non-existent route is accessed, it is redirected to page 404 not found?

Vue-Router

Upvotes: 1

Views: 304

Answers (3)

Bash Stack
Bash Stack

Reputation: 519

keyword navigation guards : https://forum.vuejs.org/t/best-practice-to-redirect-to-404-a-dynamic-route/35445/2

keyword vue router custom 404 ( tutorial) : https://reactgo.com/vue-router-404-page/

as @Simon correctly stated you will need { path: '*', component: NotFound } as last array element of routes[] in your const router = new VueRouter({

Upvotes: 1

SC Kim
SC Kim

Reputation: 600

in your route.js

path:"*":
redirect:"/404"

That will redirect missing routes in vue-router to /404. Make sure your /404 is loaded with component

Upvotes: 1

Simon
Simon

Reputation: 736

If you add a route at the end to catch all:

 { path: "*", component: NotFoundPage }

Should do it, but make sure it is the last route

Upvotes: 1

Related Questions