I have a Vue project on a Laravel backend for which SEO is important. With my current setup I redirect all incoming requests to my Vue app. Within my Vue app I handle the routing with Vue Router.
Within my setup unrecognized pages are directed to a component of my liking (404 component) but the browser gets a 200 status code. My question about this:
What can I do to give browsers a correct 404 status code?
ABSTRACT OF MY CODE:
Redirecting all to my Vue app from within Laravel (web.php file):
Route::get( '/{catchall?}', function () {
return view('app');
})->where('catchall', '.*');
In my Vue routes I catch all unrecognised paths to show my "404-component":
export const NOT_FOUND = {
path: '/*',
name: 'not found',
component: NotFoundComponent,
};
For completeness my router setup within my Vue app:
export const router = new VueRouter({
routes: routes,
mode: 'history',
base: '/',
fallback: true,
scrollBehavior (to, from, savedPosition) {
return { x: 0, y: 0 }
}
});