How to add custom static 404 error page in Nuxt ?

featured Image

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 generate and then npm run or 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

Add Google Analytics in Nuxt Application

Generate sitemap for dynamic routes in nuxtjs application

Related Posts

featured Image

How To Add Robots.txt in your Nuxtjs Application

Here in this article, we will see how to add a robot.txt file in our nuxtjs application after it is built or generated before deployment. Before learning the steps to…

Read more
featured Image

How To Add Font Locally In Nuxt App

In this tutorial, we will learn the step-by-step process of how to add a custom google font locally in your nuxtjs application. You can either use a premium font or…

Read more
featured Image

How To Add Google Font in Nuxt Application

Here in this article we will see how to add google font in your nuxtjs project/application. The process is really simple you just have to import the google font link…

Read more