From c5135efccc58dbf21d55462acd3e2c66533af8d3 Mon Sep 17 00:00:00 2001 From: Luke Nelson Date: Fri, 7 Jun 2024 17:24:50 +0100 Subject: [PATCH] docs: add note about middleware re-running for error pages (#27481) --- docs/1.getting-started/8.error-handling.md | 4 ++++ docs/2.guide/2.directory-structure/1.middleware.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/1.getting-started/8.error-handling.md b/docs/1.getting-started/8.error-handling.md index e3b944dbc6..c4b44a438d 100644 --- a/docs/1.getting-started/8.error-handling.md +++ b/docs/1.getting-started/8.error-handling.md @@ -125,6 +125,10 @@ When you are ready to remove the error page, you can call the [`clearError`](/do Make sure to check before using anything dependent on Nuxt plugins, such as `$route` or `useRouter`, as if a plugin threw an error, then it won't be re-run until you clear the error. :: +::note +Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](#useerror) in middleware to check if an error is being handled. +:: + ::note If you are running on Node 16 and you set any cookies when rendering your error page, they will [overwrite cookies previously set](https://github.com/nuxt/nuxt/pull/20585). We recommend using a newer version of Node as Node 16 reached end-of-life in September 2023. :: diff --git a/docs/2.guide/2.directory-structure/1.middleware.md b/docs/2.guide/2.directory-structure/1.middleware.md index e4e97484d3..64e66ecf6d 100644 --- a/docs/2.guide/2.directory-structure/1.middleware.md +++ b/docs/2.guide/2.directory-structure/1.middleware.md @@ -134,6 +134,10 @@ export default defineNuxtRouteMiddleware(to => { }) ``` +::note +Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/getting-started/error-handling#useerror) in middleware to check if an error is being handled. +:: + ## Adding Middleware Dynamically It is possible to add global or named route middleware manually using the [`addRouteMiddleware()`](/docs/api/utils/add-route-middleware) helper function, such as from within a plugin.