-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After initializing the page that throws an error and navigating to other pages, the error view should disappear. #22683
Comments
Start a new pull request in StackBlitz Codeflow. |
You should clear the error with the |
@danielroe, yes, of course, but this line of code should delete the error, and it works as expected, except when throwing the error in You can reproduce the error here. Additionally, here is a videos for proof: |
Can confirm this issue - we're running Nuxt in SSG mode and the error(.vue) view doesn't disappear upon navigating away using the Header/Footer I've tried a workaround (rough sketch below), but that doesn't work as I would expect it...
|
Same for me when using an error.vue file like this: <template>
<div>
<Navigation />
<div class="container mx-auto p-6">
<h1>{{ error.message }} - {{ error.statusCode }}</h1>
<button @click="handleError">{{ $t('backToHome') }}</button>
</div>
</div>
</template>
<script setup lang="ts">
defineProps({
error: {
type: Object,
default: () => {},
},
})
const handleError = () => clearError({ redirect: '/' })
</script> The link that clears the error works, but every link inside the For a normal 404 error page i would like to not have to manually clear the error on each click, i just want to leave the 404 page via the navigation. Like it is handled on the nuxt docs: https://nuxt.com/asdfsad |
Workaround that works for me is to throw errors inside Works (but no idea why…): <script setup lang="ts">
const route = useRoute()
const { data } = await useFetch(`/api/movies/${route.params.slug}`)
onMounted(() => {
if (!data.value) {
throw createError({ statusCode: 404, statusMessage: 'Page Not Found' })
}
})
</script> Does not work and results in a "frozen" error.vue that blocks any <script setup lang="ts">
const route = useRoute()
const { data } = await useFetch(`/api/movies/${route.params.slug}`)
if (!data.value) {
throw createError({ statusCode: 404, statusMessage: 'Page Not Found' })
}
</script> |
Can confirm this is also happening on all our projects. Specifically, we are using a composable that uses createError() to throw 404 errors, among other things: // ~/pages/foobar.vue
const { data } = await useAsyncData(async () => {
// do API request
})
const entity = await usePageEntity(data)
Moving the |
For now as a very hacky workaround I've implemented this global middleware: export default defineNuxtRouteMiddleware((to, from) => {
const error = useError()
if (process.client && error.value && to && from && to.path !== from.path) {
const isOnErrorPage = document.getElementById('nuxt-error-page')
if (isOnErrorPage) {
window.location.href = to.fullPath
}
}
}) It will just force a full page load when clicking away from the error page. I also added an ID attribute on the root element in my |
I'm also encountering this issue. I have a similar situation as @dulnan, but unfortunately the hacky workaround doesn't work either. I think that's because errors that happen on the client aren't accessible through Any progress on this issue? It's been open for quite a while now. |
Had the same issue on a SSG project. Simplest workaround that worked for us was: <script setup lang="ts">
const route = useRoute();
watch(() => route.fullPath, () => clearError());
</script> inside error.vue. Hope it helps EDIT: const router = useRouter();
const removeNavigationGuard = router.beforeEach(to => {
removeNavigationGuard();
clearError({ redirect: to.fullPath });
}); |
Opened a PR to fix. Just one note, after that merges the original reproduction will be resolved, but you do need to ensure |
Awesome, that's great news <3 |
Environment
Operating System: NixOS
Node Version: v18.16.0
Nuxt Version: 3.6.5
Nitro Version: 2.5.2
Package Manager: pnpm@8.6.0
Builder: vite
User Config: pages, typescript, stylus, app, modules, components, vite
Runtime Modules: -
Build Modules: -
Reproduction
Stackblitz
Github
Describe the bug
Reproduction:
Mandatory conditions:
ssr
property innuxt.config.ts
must be set to false.showError
function must be used inuseAsyncData
(without thelazy: true
).Expected Behavior:
After initializing the page that throws an error and navigating to other pages, the error view should disappear.
Actual Behavior:
After initializing the page that throws an error and navigating to other pages, the error view does not disappear.
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: