How do you handle error pages in Nuxt.js?
Answer
Nuxt.js provides a special error.vue file at the root of the project that serves as the global error page. This component receives an error prop containing the status code and message. For different status codes, you can render different content: a 404 page for missing routes, a 500 page for server errors. You can throw errors in page components or server routes using throw createError({ statusCode: 404, statusMessage: 'Not Found' }). To clear an error and redirect, use the clearError({ redirect: '/' }) utility. For catching errors within component render, Nuxt also exposes the onErrorCaptured Vue hook and the NuxtErrorBoundary component for granular error boundaries.
Previous
What is the difference between `definePageMeta` and layout configuration?
Next
What is Nitro in Nuxt.js?