vuejs2nuxt.jsserver-side-rendering

How to replace static error.html to custom-error.html in Nuxt 2


I tried to repalace error.html in .nuxt/views/ directory, but I don't know how I can do it. I use Nuxt 2.15.8.

I tried to follow steps from this article https://blog.lichter.io/posts/nuxtjs-change-server-error-page This article a bit old, so I am not sure that this approach still works.


Solution

  • Example from article works. We can replace the default error.html. Also, we can configure custom error messages in nuxt.config.js to do this we need to add messages field in nuxt.config.js. For instance:

    export default {
     messages: {
       hello_world: "Hello World!"
     }
    }
    

    in your custom error.html, we need to do this

    <p><%= messages.hello_world %></p>