Lifecycle Hooks

Nuxt provides a powerful hooking system to expand almost every aspect using hooks.
Read more in Docs > Guide > Going Further > Hooks.

App Hooks (Runtime)

Check the app source code for all available hooks.

HookArgumentsEnvironmentDescription
app:createdvueAppServer & ClientCalled when initial vueApp instance is created.
app:errorerrServer & ClientCalled when a fatal error occurs.
app:error:cleared{ redirect? }Server & ClientCalled when a fatal error occurs.
vue:setup-Server & ClientCalled when the setup of Nuxt root is initialized. This callback must be synchronous.
vue:errorerr, target, infoServer & ClientCalled when a vue error propagates to the root component. Learn More.
app:renderedrenderContextServerCalled when SSR rendering is done.
app:redirected-ServerCalled before SSR redirection.
app:beforeMountvueAppClientCalled before mounting the app, called only on client side.
app:mountedvueAppClientCalled when Vue app is initialized and mounted in browser.
app:suspense:resolveappComponentClientOn Suspense resolved event.
app:manifest:update{ id, timestamp }ClientCalled when there is a newer version of your app detected.
app:data:refreshkeys?ClientCalled when refreshNuxtData is called.
link:prefetchtoClientCalled when a <NuxtLink> is observed to be prefetched.
page:startpageComponent?ClientCalled on Suspense inside of NuxtPage pending event.
page:finishpageComponent?ClientCalled on Suspense inside of NuxtPage resolved event.
page:loading:start-ClientCalled when a route navigation begins (before resolution) or when the page key changes. May fire without the page component's setup() re-running if the page is reused (e.g. with a static key in definePageMeta).
page:loading:end-ClientCalled after page:finish
page:transition:finishpageComponent?ClientAfter page transition onAfterLeave event.
dev:ssr-logslogsClientCalled with an array of server-side logs that have been passed to the client (if features.devLogs is enabled).
page:view-transition:starttransitionClientCalled after document.startViewTransition is called when experimental viewTransition support is enabled. The transition argument is a ViewTransition object with a types property (ViewTransitionTypeSet) that can be read or modified.

Nuxt Hooks (Build Time)

Check the schema source code for all available hooks.

HookArgumentsDescription
kit:compatibilitycompatibility, issuesAllows extending compatibility checks.
readynuxtCalled after Nuxt initialization, when the Nuxt instance is ready to work.
closenuxtCalled when Nuxt instance is gracefully closing.
restart{ hard?: boolean }To be called to restart the current Nuxt instance.
modules:before-Called during Nuxt initialization, before installing user modules.
modules:done-Called during Nuxt initialization, after installing user modules.
module:beforemoduleCalled immediately before each individual module is set up.
module:donemoduleCalled immediately after each individual module has been set up, including how long it took.
app:resolveappCalled after resolving the app instance.
app:templatesappCalled during NuxtApp generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to .nuxt).
app:templatesGeneratedappCalled after templates are compiled into the virtual file system (vfs).
server:routesroutes, contextCalled when Nuxt needs the full set of route handlers the server will serve, so that it can type $fetch and useFetch against them. The configured server builder adds the handlers it discovered by scanning, alongside those registered through serverHandlers.
build:before-Called before Nuxt bundle builder.
build:done-Called after Nuxt bundle builder is complete.
build:manifestmanifestCalled during the manifest build by Vite and webpack. This allows customizing the manifest that Nitro will use to render <script> and <link> tags in the final HTML, including each entry's prefetch and preload flags.
builder:generateAppoptionsCalled before generating the app.
builder:watchevent, pathCalled at build time in development when the watcher spots a change to a file or directory in the project.
pages:extendpagesCalled after page routes are scanned from the file system.
pages:resolvedpagesCalled after page routes have been augmented with scanned metadata.
pages:routerOptions{ files: Array<{ path: string, optional?: boolean }> }Called when resolving router.options files. Later items in the array override earlier ones.
server:devHandlerhandlerCalled when the dev middleware is being registered on the Nitro dev server.
imports:sourcespresetsCalled at setup allowing modules to extend sources.
imports:extendimportsCalled at setup allowing modules to extend imports.
imports:contextcontextCalled when the unimport context is created.
imports:dirsdirsAllows extending import directories.
components:dirsdirsCalled within app:resolve allowing to extend the directories that are scanned for auto-importable components.
components:extendcomponentsAllows extending new components.
nitro:confignitroConfigCalled before initializing Nitro, allowing customization of Nitro's configuration.
nitro:initnitroCalled after Nitro is initialized, which allows registering Nitro hooks and interacting directly with Nitro.
nitro:build:beforenitroCalled before building the Nitro instance.
nitro:build:public-assetsnitroCalled after copying public assets. Allows modifying public assets before Nitro server is built.
prerender:routesctxAllows extending the routes to be pre-rendered.
build:errorerrorCalled when an error occurs at build time.
prepare:typesoptionsCalled before @nuxt/cli writes TypeScript configuration files (.nuxt/tsconfig.app.json, .nuxt/tsconfig.server.json, etc.) and .nuxt/nuxt.d.ts, allowing addition of custom references and declarations in nuxt.d.ts, or directly modifying the options in generated configurations
listenlistenerServer, listenerCalled when the dev server is loading.
schema:extendschemasAllows extending default schemas.
schema:resolvedschemaAllows extending resolved schema.
schema:beforeWriteschemaCalled before writing the given schema.
schema:written-Called after the schema is written.
vite:extendviteBuildContextAllows extending Vite default context.
vite:extendConfigviteInlineConfig, envAllows extending Vite default config. Deprecated in Nuxt 5+. In Nuxt 5, this operates on a shared configuration rather than separate client/server configs.
vite:configResolvedviteInlineConfig, envAllows reading the resolved Vite config. Deprecated in Nuxt 5+. In Nuxt 5, this operates on a shared configuration rather than separate client/server configs.
vite:serverCreatedviteServer, envCalled when the Vite server is created.
vite:compiled-Called after Vite server is compiled.
webpack:configwebpackConfigsCalled before configuring the webpack compiler.
webpack:configResolvedwebpackConfigsAllows reading the resolved webpack config.
webpack:compileoptionsCalled right before compilation.
webpack:compiledoptionsCalled after resources are loaded.
webpack:changeshortPathCalled on change on WebpackBar.
webpack:error-Called on done if has errors on WebpackBar.
webpack:done-Called on allDone on WebpackBar.
webpack:progressstatesArrayCalled on progress on WebpackBar.
rsbuild:configrsbuildConfigCalled before creating the Rsbuild instance, with the Rsbuild config containing the client and ssr environments. The Rsbuild builder also calls rspack:config and rspack:configResolved with the generated Rspack configs, named client and ssr.
rsbuild:compileoptionsCalled right before the first compilation of an environment.
rsbuild:compiledoptionsCalled after an environment has been compiled.

Renderer Hooks (Runtime, Server-Side)

The Nuxt renderer calls these hooks while it renders a page, under any server builder. A module registers them from a renderer plugin. When Nuxt runs on Nitro, a server plugin can also register them on nitroApp.hooks. Their types are declared on NuxtServerRendererHooks, exported from nuxt/server.

HookArgumentsDescription
render:routecontext, { event }Called once per request, before rendering begins. Set context.prefersStream to false to render the request without streaming.
render:htmlhtml, { event, streaming? }Called with the parts of the HTML document (htmlAttrs, head, bodyAttrs, bodyPrepend, body and bodyAppend) before they are joined. For a streamed response, it is called before the shell is sent, with streaming: true, and changes to body and bodyAppend are dropped.
render:html:chunkcontext, { event }Called for each chunk of a streamed response before it is sent. Replace context.chunk, a Uint8Array, to transform it.
render:html:closecontext, { event }Called when the body of a streamed response has been rendered, before the closing tags. Push to context.bodyAppend to add markup at the end of the body.
render:documentcontext, { event }Called with the serialised HTML document of a response that is not streamed, once every render:html handler has run. Replace context.html to change it. Not called for a server component.
render:islandislandResponse, { event, islandContext }Called before a server component response is sent. Server components are only rendered on Nitro.

There is no render:response hook. Response headers set on event.res.headers from render:html are sent with the page, and render:document can replace the serialised document.

Nitro App Hooks (Runtime, Server-Side)

These hooks are called by Nitro, so they are only available when Nuxt runs on Nitro. See Nitro for all available hooks.

HookArgumentsDescriptionTypes
dev:ssr-logs{ path, logs }Called at the end of a request cycle with an array of server-side logs.-
close-Called when Nitro is closed.-
errorerror, { event? }Called when an error occurs.error, event
requesteventCalled when a request is received.event
responseresponse, eventCalled before sending the response.response