Reputation: 564
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
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
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
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