How to add custom static 404 error page in Nuxt ?
This article is about how to add a custom static 404 page in our nuxt application. 404 error page willbe the fallback page if a page is not found in the static site.
In this article, we will learn how to add custom static 404 error page in nuxt application.
A 404 Error is a status code which occurs when a page is not found in the server.
The 404 Error page are the fallback page which is shown when a content in a website is not found or the content has been moved to other place.
Add static 404 Error Page in Nuxt.
To add a 404 Error page in nuxt follow the steps below.
Step 1: Create a new layout error.vue in your layouts folder in nuxt. Add you html code as you need inside the the error.vue page.
layouts/error.vue
Step 2: Now addgenerate: { fallback: '404.html' } in your nuxt.config.js file.
export default { generate: { fallback: '404.html' }, }
Step 3: After you have done the above two steps, run npm generate and the npm start . Now visit any random page which is not present in your site, you will get the 404 error page.
Note: In development environment you will not get the error page, to check you to
npm generateand thennpm runor you can just deploy the site to check.
That's it, now you have successfully added a 404 error page in your static site.
If you want more NuxtJS related article, Read Here .
Related Topics:
Add Robots.txt in your Nuxtjs Application
Related Posts
How to add common header and footer in Nuxt
Short post on how to add common header and footer component for all your pages in your nuxt application using layouts directory.
How to add external script tag in head in Nuxt
To add external javascript script in nuxt we have to add the script tag with src in the head() method.
Convert image to webp in nuxtjs | Image Optimization
To optimize an image in nuxt we have to use the @nuxt/image module. It can convert an image to webp format in nuxt application.
How to Add Syntax Highlighting PrismJS to Nuxt
This article is about how to add a code syntax highlighter PrismJS to Nuxt and configure PrismJs theme in NuxtJS.
