@nuxt/docs 3.19.2 → 3.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +2 -2
- package/1.getting-started/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +41 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +2 -1
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +7 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -7,15 +7,15 @@ This guide helps you better understand Nuxt internals to develop new solutions a
|
|
|
7
7
|
|
|
8
8
|
## The Nuxt Interface
|
|
9
9
|
|
|
10
|
-
When you start Nuxt in development mode with [`nuxt dev`](/docs/api/commands/dev) or building a production application with [`nuxt build`](/docs/api/commands/build),
|
|
10
|
+
When you start Nuxt in development mode with [`nuxt dev`](/docs/3.x/api/commands/dev) or building a production application with [`nuxt build`](/docs/3.x/api/commands/build),
|
|
11
11
|
a common context will be created, referred to as `nuxt` internally. It holds normalized options merged with `nuxt.config` file,
|
|
12
|
-
some internal state, and a powerful [hooking system](/docs/api/advanced/hooks) powered by [unjs/hookable](https://github.com/unjs/hookable)
|
|
12
|
+
some internal state, and a powerful [hooking system](/docs/3.x/api/advanced/hooks) powered by [unjs/hookable](https://github.com/unjs/hookable)
|
|
13
13
|
allowing different components to communicate with each other. You can think of it as **Builder Core**.
|
|
14
14
|
|
|
15
|
-
This context is globally available to be used with [Nuxt Kit](/docs/guide/going-further/kit) composables.
|
|
15
|
+
This context is globally available to be used with [Nuxt Kit](/docs/3.x/guide/going-further/kit) composables.
|
|
16
16
|
Therefore only one instance of Nuxt is allowed to run per process.
|
|
17
17
|
|
|
18
|
-
To extend the Nuxt interface and hook into different stages of the build process, we can use [Nuxt Modules](/docs/guide/going-further/modules).
|
|
18
|
+
To extend the Nuxt interface and hook into different stages of the build process, we can use [Nuxt Modules](/docs/3.x/guide/going-further/modules).
|
|
19
19
|
|
|
20
20
|
For more details, check out [the source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nuxt.ts).
|
|
21
21
|
|
|
@@ -25,42 +25,42 @@ When rendering a page in the browser or on the server, a shared context will be
|
|
|
25
25
|
This context keeps vue instance, runtime hooks, and internal states like ssrContext and payload for hydration.
|
|
26
26
|
You can think of it as **Runtime Core**.
|
|
27
27
|
|
|
28
|
-
This context can be accessed using [`useNuxtApp()`](/docs/api/composables/use-nuxt-app) composable within Nuxt plugins and `<script setup>` and vue composables.
|
|
28
|
+
This context can be accessed using [`useNuxtApp()`](/docs/3.x/api/composables/use-nuxt-app) composable within Nuxt plugins and `<script setup>` and vue composables.
|
|
29
29
|
Global usage is possible for the browser but not on the server, to avoid sharing context between users.
|
|
30
30
|
|
|
31
|
-
Since [`useNuxtApp`](/docs/api/composables/use-nuxt-app) throws an exception if context is currently unavailable, if your composable does not always require `nuxtApp`, you can use [`tryUseNuxtApp`](/docs/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
31
|
+
Since [`useNuxtApp`](/docs/3.x/api/composables/use-nuxt-app) throws an exception if context is currently unavailable, if your composable does not always require `nuxtApp`, you can use [`tryUseNuxtApp`](/docs/3.x/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
32
32
|
|
|
33
|
-
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/guide/directory-structure/plugins).
|
|
33
|
+
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/3.x/guide/directory-structure/plugins).
|
|
34
34
|
|
|
35
|
-
Check [Nuxt App](/docs/api/composables/use-nuxt-app) for more information about this interface.
|
|
35
|
+
Check [Nuxt App](/docs/3.x/api/composables/use-nuxt-app) for more information about this interface.
|
|
36
36
|
|
|
37
37
|
`nuxtApp` has the following properties:
|
|
38
38
|
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
vueApp
|
|
39
|
+
```ts
|
|
40
|
+
interface NuxtApp {
|
|
41
|
+
vueApp // the global Vue application: https://vuejs.org/api/application.html#application-api
|
|
42
42
|
|
|
43
|
-
versions
|
|
43
|
+
versions // an object containing Nuxt and Vue versions
|
|
44
44
|
|
|
45
45
|
// These let you call and add runtime NuxtApp hooks
|
|
46
46
|
// https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18
|
|
47
|
-
hooks
|
|
48
|
-
hook
|
|
49
|
-
callHook
|
|
47
|
+
hooks
|
|
48
|
+
hook
|
|
49
|
+
callHook
|
|
50
50
|
|
|
51
51
|
// Only accessible on server-side
|
|
52
52
|
ssrContext: {
|
|
53
|
-
url
|
|
54
|
-
req
|
|
55
|
-
res
|
|
56
|
-
runtimeConfig
|
|
57
|
-
noSSR
|
|
58
|
-
}
|
|
53
|
+
url
|
|
54
|
+
req
|
|
55
|
+
res
|
|
56
|
+
runtimeConfig
|
|
57
|
+
noSSR
|
|
58
|
+
}
|
|
59
59
|
|
|
60
60
|
// This will be stringified and passed from server to client
|
|
61
61
|
payload: {
|
|
62
|
-
serverRendered: true
|
|
63
|
-
data: {}
|
|
62
|
+
serverRendered: true
|
|
63
|
+
data: {}
|
|
64
64
|
state: {}
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -76,6 +76,6 @@ Nuxt builds and bundles project using Node.js but also has a runtime side.
|
|
|
76
76
|
|
|
77
77
|
While both areas can be extended, that runtime context is isolated from build-time. Therefore, they are not supposed to share state, code, or context other than runtime configuration!
|
|
78
78
|
|
|
79
|
-
`nuxt.config` and [Nuxt Modules](/docs/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/guide/directory-structure/plugins) can be used to extend runtime.
|
|
79
|
+
`nuxt.config` and [Nuxt Modules](/docs/3.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/3.x/guide/directory-structure/plugins) can be used to extend runtime.
|
|
80
80
|
|
|
81
|
-
When building an application for production, `nuxt build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/guide/going-further/modules).
|
|
81
|
+
When building an application for production, `nuxt build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/3.x/guide/going-further/modules).
|
|
@@ -5,7 +5,7 @@ description: "Nuxt provides a runtime config API to expose configuration and sec
|
|
|
5
5
|
|
|
6
6
|
## Exposing
|
|
7
7
|
|
|
8
|
-
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig) option.
|
|
8
|
+
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your [`nuxt.config`](/docs/3.x/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/3.x/api/nuxt-config#runtimeconfig) option.
|
|
9
9
|
|
|
10
10
|
```ts [nuxt.config.ts]
|
|
11
11
|
export default defineNuxtConfig({
|
|
@@ -14,9 +14,9 @@ export default defineNuxtConfig({
|
|
|
14
14
|
apiSecret: '123',
|
|
15
15
|
// Keys within public, will be also exposed to the client-side
|
|
16
16
|
public: {
|
|
17
|
-
apiBase: '/api'
|
|
18
|
-
}
|
|
19
|
-
}
|
|
17
|
+
apiBase: '/api',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -78,7 +78,7 @@ export default defineNuxtConfig({
|
|
|
78
78
|
apiSecret: '', // can be overridden by NUXT_API_SECRET environment variable
|
|
79
79
|
public: {
|
|
80
80
|
apiBase: '', // can be overridden by NUXT_PUBLIC_API_BASE environment variable
|
|
81
|
-
}
|
|
81
|
+
},
|
|
82
82
|
},
|
|
83
83
|
})
|
|
84
84
|
```
|
|
@@ -87,7 +87,7 @@ export default defineNuxtConfig({
|
|
|
87
87
|
|
|
88
88
|
### Vue App
|
|
89
89
|
|
|
90
|
-
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) to access the runtime config.
|
|
90
|
+
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/3.x/api/composables/use-runtime-config) to access the runtime config.
|
|
91
91
|
|
|
92
92
|
::important
|
|
93
93
|
The behavior is different between the client-side and server-side:
|
|
@@ -120,14 +120,14 @@ if (import.meta.server) {
|
|
|
120
120
|
|
|
121
121
|
### Plugins
|
|
122
122
|
|
|
123
|
-
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
123
|
+
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/3.x/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
124
124
|
|
|
125
125
|
```ts [plugins/config.ts]
|
|
126
126
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
127
127
|
const config = useRuntimeConfig()
|
|
128
128
|
|
|
129
129
|
console.log('API base URL:', config.public.apiBase)
|
|
130
|
-
})
|
|
130
|
+
})
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
### Server Routes
|
|
@@ -139,15 +139,15 @@ export default defineEventHandler(async (event) => {
|
|
|
139
139
|
const { apiSecret } = useRuntimeConfig(event)
|
|
140
140
|
const result = await $fetch('https://my.api.com/test', {
|
|
141
141
|
headers: {
|
|
142
|
-
Authorization: `Bearer ${apiSecret}
|
|
143
|
-
}
|
|
142
|
+
Authorization: `Bearer ${apiSecret}`,
|
|
143
|
+
},
|
|
144
144
|
})
|
|
145
145
|
return result
|
|
146
146
|
})
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
::note
|
|
150
|
-
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
150
|
+
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/3.x/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
151
151
|
::
|
|
152
152
|
|
|
153
153
|
## Typing Runtime Config
|
|
@@ -9,15 +9,15 @@ The hooking system is powered by [unjs/hookable](https://github.com/unjs/hookabl
|
|
|
9
9
|
|
|
10
10
|
## Nuxt Hooks (Build Time)
|
|
11
11
|
|
|
12
|
-
These hooks are available for [Nuxt Modules](/docs/guide/going-further/modules) and build context.
|
|
12
|
+
These hooks are available for [Nuxt Modules](/docs/3.x/guide/going-further/modules) and build context.
|
|
13
13
|
|
|
14
14
|
### Within `nuxt.config.ts`
|
|
15
15
|
|
|
16
|
-
```
|
|
16
|
+
```ts [nuxt.config.ts]
|
|
17
17
|
export default defineNuxtConfig({
|
|
18
18
|
hooks: {
|
|
19
|
-
close: () => { }
|
|
20
|
-
}
|
|
19
|
+
close: () => { },
|
|
20
|
+
},
|
|
21
21
|
})
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -29,7 +29,7 @@ import { defineNuxtModule } from '@nuxt/kit'
|
|
|
29
29
|
export default defineNuxtModule({
|
|
30
30
|
setup (options, nuxt) {
|
|
31
31
|
nuxt.hook('close', async () => { })
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -39,9 +39,9 @@ Explore all available Nuxt hooks.
|
|
|
39
39
|
|
|
40
40
|
## App Hooks (Runtime)
|
|
41
41
|
|
|
42
|
-
App hooks can be mainly used by [Nuxt Plugins](/docs/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/3.x/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
|
-
```
|
|
44
|
+
```ts [plugins/test.ts]
|
|
45
45
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
46
46
|
nuxtApp.hook('page:start', () => {
|
|
47
47
|
/* your code goes here */
|
|
@@ -55,9 +55,9 @@ Explore all available App hooks.
|
|
|
55
55
|
|
|
56
56
|
## Server Hooks (Runtime)
|
|
57
57
|
|
|
58
|
-
These hooks are available for [server plugins](/docs/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
58
|
+
These hooks are available for [server plugins](/docs/3.x/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
59
59
|
|
|
60
|
-
```
|
|
60
|
+
```ts [~/server/plugins/test.ts]
|
|
61
61
|
export default defineNitroPlugin((nitroApp) => {
|
|
62
62
|
nitroApp.hooks.hook('render:html', (html, { event }) => {
|
|
63
63
|
console.log('render:html', html)
|
|
@@ -79,7 +79,7 @@ Learn more about available Nitro lifecycle hooks.
|
|
|
79
79
|
You can define your own custom hooks support by extending Nuxt's hook interfaces.
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
import { HookResult } from
|
|
82
|
+
import type { HookResult } from '@nuxt/schema'
|
|
83
83
|
|
|
84
84
|
declare module '#app' {
|
|
85
85
|
interface RuntimeNuxtHooks {
|
|
@@ -92,7 +92,7 @@ declare module '#app' {
|
|
|
92
92
|
|
|
93
93
|
declare module 'nitropack' {
|
|
94
94
|
interface NitroRuntimeHooks {
|
|
95
|
-
'your-nitro-hook': () => void
|
|
95
|
+
'your-nitro-hook': () => void
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
```
|