---
title: "Lifecycle Hooks"
description: "Nuxt provides a powerful hooking system to expand almost every aspect using hooks."
canonical_url: "https://nuxt.com/docs/4.x/api/advanced/hooks"
---
# Lifecycle Hooks

> Nuxt provides a powerful hooking system to expand almost every aspect using hooks.

::read-more{to="https://nuxt.com/docs/4.x/guide/going-further/hooks"}
::

## App Hooks (Runtime)

Check the [app source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L37) for all available hooks.

| Hook                         | Arguments           | Environment     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ---------------------------- | ------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `app:created`                | `vueApp`            | Server & Client | Called when initial `vueApp` instance is created.                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `app:error`                  | `err`               | Server & Client | Called when a fatal error occurs.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `app:error:cleared`          | `{ redirect? }`     | Server & Client | Called when a fatal error occurs.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `vue:setup`                  | -                   | Server & Client | Called when the setup of Nuxt root is initialized. This callback must be synchronous.                                                                                                                                                                                                                                                                                                                                                                                                     |
| `vue:error`                  | `err, target, info` | Server & Client | Called when a vue error propagates to the root component. [Learn More](https://vuejs.org/api/composition-api-lifecycle#onerrorcaptured).                                                                                                                                                                                                                                                                                                                                                  |
| `app:rendered`               | `renderContext`     | Server          | Called when SSR rendering is done.                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `app:redirected`             | -                   | Server          | Called before SSR redirection.                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `app:beforeMount`            | `vueApp`            | Client          | Called before mounting the app, called only on client side.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `app:mounted`                | `vueApp`            | Client          | Called when Vue app is initialized and mounted in browser.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `app:suspense:resolve`       | `appComponent`      | Client          | On [Suspense](https://vuejs.org/guide/built-ins/suspense#suspense) resolved event.                                                                                                                                                                                                                                                                                                                                                                                                        |
| `app:manifest:update`        | `{ id, timestamp }` | Client          | Called when there is a newer version of your app detected.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `app:data:refresh`           | `keys?`             | Client          | Called when `refreshNuxtData` is called.                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `link:prefetch`              | `to`                | Client          | Called when a `<NuxtLink>` is observed to be prefetched.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `page:start`                 | `pageComponent?`    | Client          | Called on [Suspense](https://vuejs.org/guide/built-ins/suspense#suspense) inside of `NuxtPage` pending event.                                                                                                                                                                                                                                                                                                                                                                             |
| `page:finish`                | `pageComponent?`    | Client          | Called on [Suspense](https://vuejs.org/guide/built-ins/suspense#suspense) inside of `NuxtPage` resolved event.                                                                                                                                                                                                                                                                                                                                                                            |
| `page:loading:start`         | -                   | Client          | Called 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`           | -                   | Client          | Called after `page:finish`                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `page:transition:finish`     | `pageComponent?`    | Client          | After page transition [onAfterLeave](https://vuejs.org/guide/built-ins/transition#javascript-hooks) event.                                                                                                                                                                                                                                                                                                                                                                                |
| `dev:ssr-logs`               | `logs`              | Client          | Called with an array of server-side logs that have been passed to the client (if `features.devLogs` is enabled).                                                                                                                                                                                                                                                                                                                                                                          |
| `page:view-transition:start` | `transition`        | Client          | Called after `document.startViewTransition` is called when [experimental viewTransition support is enabled](https://nuxt.com/docs/4.x/getting-started/transitions#view-transitions-api-experimental). The `transition` argument is a [`ViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) object with a `types` property ([`ViewTransitionTypeSet`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransitionTypeSet)) that can be read or modified. |

## Nuxt Hooks (Build Time)

Check the [schema source code](https://github.com/nuxt/nuxt/blob/main/packages/schema/src/types/hooks.ts#L83) for all available hooks.

| Hook                        | Arguments                                                | Description                                                                                                                                                                                                                                                                                                                            |
| --------------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `kit:compatibility`         | `compatibility, issues`                                  | Allows extending compatibility checks.                                                                                                                                                                                                                                                                                                 |
| `ready`                     | `nuxt`                                                   | Called after Nuxt initialization, when the Nuxt instance is ready to work.                                                                                                                                                                                                                                                             |
| `close`                     | `nuxt`                                                   | Called 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:before`             | `module`                                                 | Called immediately before each individual module is set up.                                                                                                                                                                                                                                                                            |
| `module:done`               | `module`                                                 | Called immediately after each individual module has been set up, including how long it took.                                                                                                                                                                                                                                           |
| `app:resolve`               | `app`                                                    | Called after resolving the `app` instance.                                                                                                                                                                                                                                                                                             |
| `app:templates`             | `app`                                                    | Called during `NuxtApp` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`).                                                                                                                                                                            |
| `app:templatesGenerated`    | `app`                                                    | Called after templates are compiled into the [virtual file system](https://nuxt.com/docs/4.x/directory-structure/nuxt) (vfs).                                                                                                                                                                                                          |
| `build:before`              | -                                                        | Called before Nuxt bundle builder.                                                                                                                                                                                                                                                                                                     |
| `build:done`                | -                                                        | Called after Nuxt bundle builder is complete.                                                                                                                                                                                                                                                                                          |
| `build:environment:start`   | `environment`                                            | Called in a production build when a bundle starts, with its `name`, `consumer` (`client` or `server`) and the `builder` that bundles it. Every bundle the app builder and the server builder write is reported, including intermediate ones, and bundles built concurrently overlap.                                                   |
| `build:environment:done`    | `environment, { duration, outDir, files }`               | Called in a production build once a bundle has been written to disk, with how long it took, where it was written and the `path` (relative to `outDir`) and `size` of each file.                                                                                                                                                        |
| `build:prerender:start`     | `{ routes }`                                             | Called when prerendering starts, with the number of routes it starts from, whichever server builder prerenders.                                                                                                                                                                                                                        |
| `build:prerender:route`     | `route`                                                  | Called after each route is prerendered, with its `route`, `duration`, the `total` number of routes queued so far (which grows while links are crawled), the `fileName` it was written to, whether it was `skipped`, and an `error` (`status` and `message`) when it failed, with the pages that link to it (`linkedFrom`) where known. |
| `build:prerender:done`      | `{ duration, written, failed }`                          | Called when prerendering finishes, before the build fails for any route that failed to render. Each entry in `failed` has the same `route`, `status`, `message` and `linkedFrom`.                                                                                                                                                      |
| `build:manifest`            | `manifest`                                               | Called 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:generateApp`       | `options`                                                | Called before generating the app.                                                                                                                                                                                                                                                                                                      |
| `builder:watch`             | `event, path`                                            | Called at build time in development when the watcher spots a change to a file or directory in the project.                                                                                                                                                                                                                             |
| `pages:extend`              | `pages`                                                  | Called after page routes are scanned from the file system.                                                                                                                                                                                                                                                                             |
| `pages:resolved`            | `pages`                                                  | Called 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:routes`             | `routes`, `context`                                      | Called when Nuxt needs the full set of route handlers the server will serve, so that it can type `$fetch` and `useFetch` against them.                                                                                                                                                                                                 |
| `server:devHandler`         | `handler`                                                | Called when the dev middleware is being registered on the Nitro dev server.                                                                                                                                                                                                                                                            |
| `imports:sources`           | `presets`                                                | Called at setup allowing modules to extend sources.                                                                                                                                                                                                                                                                                    |
| `imports:extend`            | `imports`                                                | Called at setup allowing modules to extend imports.                                                                                                                                                                                                                                                                                    |
| `imports:context`           | `context`                                                | Called when the [unimport](https://github.com/unjs/unimport) context is created.                                                                                                                                                                                                                                                       |
| `imports:dirs`              | `dirs`                                                   | Allows extending import directories.                                                                                                                                                                                                                                                                                                   |
| `components:dirs`           | `dirs`                                                   | Called within `app:resolve` allowing to extend the directories that are scanned for auto-importable components.                                                                                                                                                                                                                        |
| `components:extend`         | `components`                                             | Allows extending new components.                                                                                                                                                                                                                                                                                                       |
| `nitro:config`              | `nitroConfig`                                            | Called before initializing Nitro, allowing customization of Nitro's configuration.                                                                                                                                                                                                                                                     |
| `nitro:init`                | `nitro`                                                  | Called after Nitro is initialized, which allows registering Nitro hooks and interacting directly with Nitro.                                                                                                                                                                                                                           |
| `nitro:build:before`        | `nitro`                                                  | Called before building the Nitro instance.                                                                                                                                                                                                                                                                                             |
| `nitro:build:public-assets` | `nitro`                                                  | Called after copying public assets. Allows modifying public assets before Nitro server is built.                                                                                                                                                                                                                                       |
| `prerender:routes`          | `ctx`                                                    | Allows extending the routes to be pre-rendered.                                                                                                                                                                                                                                                                                        |
| `build:error`               | `error`                                                  | Called when an error occurs at build time.                                                                                                                                                                                                                                                                                             |
| `prepare:types`             | `options`                                                | Called 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                                           |
| `listen`                    | `listenerServer, listener`                               | Called when the dev server is loading, with the HTTP, HTTPS or HTTP/2 server.                                                                                                                                                                                                                                                          |
| `schema:extend`             | `schemas`                                                | Allows extending default schemas.                                                                                                                                                                                                                                                                                                      |
| `schema:resolved`           | `schema`                                                 | Allows extending resolved schema.                                                                                                                                                                                                                                                                                                      |
| `schema:beforeWrite`        | `schema`                                                 | Called before writing the given schema.                                                                                                                                                                                                                                                                                                |
| `schema:written`            | -                                                        | Called after the schema is written.                                                                                                                                                                                                                                                                                                    |
| `vite:extend`               | `viteBuildContext`                                       | Allows extending Vite default context.                                                                                                                                                                                                                                                                                                 |
| `vite:extendConfig`         | `viteInlineConfig, env`                                  | Allows extending Vite default config. **Deprecated in Nuxt 5+.** In Nuxt 5, this operates on a shared configuration rather than separate client/server configs.                                                                                                                                                                        |
| `vite:configResolved`       | `viteInlineConfig, env`                                  | Allows 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:serverCreated`        | `viteServer, env`                                        | Called when the Vite server is created.                                                                                                                                                                                                                                                                                                |
| `vite:compiled`             | -                                                        | Called after Vite server is compiled.                                                                                                                                                                                                                                                                                                  |
| `webpack:config`            | `webpackConfigs`                                         | Called before configuring the webpack compiler.                                                                                                                                                                                                                                                                                        |
| `webpack:configResolved`    | `webpackConfigs`                                         | Allows reading the resolved webpack config.                                                                                                                                                                                                                                                                                            |
| `webpack:compile`           | `options`                                                | Called right before compilation.                                                                                                                                                                                                                                                                                                       |
| `webpack:compiled`          | `options`                                                | Called after resources are loaded.                                                                                                                                                                                                                                                                                                     |
| `webpack:change`            | `shortPath`                                              | Called on `change` on WebpackBar.                                                                                                                                                                                                                                                                                                      |
| `webpack:error`             | -                                                        | Called on `done` if has errors on WebpackBar.                                                                                                                                                                                                                                                                                          |
| `webpack:done`              | -                                                        | Called on `allDone` on WebpackBar.                                                                                                                                                                                                                                                                                                     |
| `webpack:progress`          | `statesArray`                                            | Called on `progress` on WebpackBar.                                                                                                                                                                                                                                                                                                    |
| `rsbuild:config`            | `rsbuildConfig`                                          | Called 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:compile`           | `options`                                                | Called right before the first compilation of an environment.                                                                                                                                                                                                                                                                           |
| `rsbuild:compiled`          | `options`                                                | Called 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](https://nuxt.com/docs/4.x/api/kit/nitro#addrendererplugin). When Nuxt runs on Nitro, a [server plugin](https://nuxt.com/docs/4.x/directory-structure/server#server-plugins) can also register them on `nitroApp.hooks`. Their types are declared on `NuxtServerRendererHooks`, exported from `nuxt/server`.

| Hook                | Arguments                                  | Description                                                                                                                                                                                                                                                                               |
| ------------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `render:route`      | `context, { event }`                       | Called once per request, before rendering begins. Set `context.prefersStream` to `false` to render the request without streaming.                                                                                                                                                         |
| `render:html`       | `html, { 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:chunk` | `context, { event }`                       | Called for each chunk of a streamed response before it is sent. Replace `context.chunk`, a `Uint8Array`, to transform it.                                                                                                                                                                 |
| `render:html:close` | `context, { 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:document`   | `context, { 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:island`     | `islandResponse, { event, islandContext }` | Called before a server component response is sent. Server components are only rendered on Nitro.                                                                                                                                                                                          |

`render:response` is a Nitro hook rather than a renderer hook, so it is only called when Nuxt runs on Nitro, and a renderer plugin cannot register it. A renderer plugin can use `render:document` to 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](https://nitro.build/guide/plugins#available-hooks) for all available hooks.

| Hook              | Arguments             | Description                                                             | Types                                                                                                                                                                                                                                           |
| ----------------- | --------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dev:ssr-logs`    | `{ path, logs }`      | Called at the end of a request cycle with an array of server-side logs. | -                                                                                                                                                                                                                                               |
| `render:response` | `response, { event }` | Called before sending the response.                                     | [response](https://github.com/nuxt/nuxt/blob/71ef8bd3ff207fd51c2ca18d5a8c7140476780c7/packages/nuxt/src/core/runtime/nitro/renderer.ts#L24), [event](https://github.com/h3js/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38) |
| `close`           | -                     | Called when Nitro is closed.                                            | -                                                                                                                                                                                                                                               |
| `error`           | `error, { event? }`   | Called when an error occurs.                                            | [error](https://github.com/nitrojs/nitro/blob/d20ffcbd16fc4003b774445e1a01e698c2bb078a/src/types/runtime/nitro.ts#L48), [event](https://github.com/h3js/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38)                      |
| `request`         | `event`               | Called when a request is received.                                      | [event](https://github.com/h3js/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38)                                                                                                                                              |
| `beforeResponse`  | `event, { body }`     | Called before sending the response.                                     | [event](https://github.com/h3js/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38), unknown                                                                                                                                     |
| `afterResponse`   | `event, { body }`     | Called after sending the response.                                      | [event](https://github.com/h3js/h3/blob/f6ceb5581043dc4d8b6eab91e9be4531e0c30f8e/src/types.ts#L38), unknown                                                                                                                                     |


## Sitemap

See the full [sitemap](https://nuxt.com/sitemap.md) for all pages.
