0👍
✅
You have to define all your routes as path: '*'
will redirect all routes to not found if you have not defined them.
import NotFound from './views/NotFound'
import NewComponent from './views/NewComponent'
const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/',
component: NewComponent,
children: [
{
path: '404', // Changed
name: '404',
component: NotFound
}
]
},
{
path: '*',
redirect: '/404'
}
})
Now if you try /
route it will redirect you to NewComponent
Its just an example. Hope it helps
And you should use window.location.href = "/404.php"
inside created hook
<template>
<div id="404">Page Not Found</div>
</template>
<script>
export default {
created () {
window.location.href = "/404.php"
}
}
</script>
Source:stackexchange.com