nuxt: Bug: Handling errors with the NuxtErrorBoundary component
The NuxtErrorBoundary component does not seem to work as expected:
The #error slot will receive error as a prop. (If you set error = null it will trigger re-rendering the default slot;
Example:
// app.vue
<template>
<NuxtErrorBoundary>
<NuxtPage/>
<template #error="{ error }">
<p>An error occurred: {{ error }}</p>
<button @click="() => clearError({ redirect: '/' })">
This will clear the error.
</button>
</template>
</NuxtErrorBoundary>
</template>
Problem 1:
The error is NOT cleared at all when the button is clicked. The error message still can be seen on the screen.
Problem 2:
The Home page is NOT rendered at all when the route is redirected to / successfully. It is still rendering the error component and message.
Any ideas?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 16
- Comments: 20 (4 by maintainers)
FWIW, I’m using a home-grown
components/ErrorBoundary.vue:Features:
NuxtErrorBoundaryadvertisesparent.vuealongsideparent/child1.vueandparent/child2.vue(handles crash in child1 and allows to switch to child2)This is how one can use it with
nuxt-page:Any update about this issue ? When
NuxtErrorBoundaryis used the full error page shows up.With
NuxtErrorBoundaryin app.vue,ssr: false, and an error thrown from a page component, nothing appears at all, just an error in the console. The error will show properly on page navigation, but not on initial page load.[Vue warn]
Error
Hey, work for me in app.vue
Trying to use
NuxtErrorBoundaryon a component/page level, and I dont think its preventing global error page from rendering. I’m throwing createError from API and trying to gracefully show it while not rendering the global error page. Hopefully this ifxes soon… I’m about to pull all my hair out.Here is my own take on an
ErrorBoundarycomponent:Hi I have the same issue using NuxtErrorBoundary around NuxtPage 👍
Any idea or workaround ?
Hey! Could you kindly provide a reproduction via StackBlitz or CodeSandbox? 🙏