@nuxt/docs-nightly 4.5.1-29742962.84b6b25e → 4.5.1-29742976.83f20aa7

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.
Files changed (79) hide show
  1. package/1.getting-started/02.installation.md +6 -0
  2. package/1.getting-started/05.assets.md +126 -0
  3. package/1.getting-started/07.routing.md +22 -0
  4. package/1.getting-started/08.seo-meta.md +19 -4
  5. package/1.getting-started/09.transitions.md +5 -1
  6. package/1.getting-started/10.data-fetching.md +3 -5
  7. package/1.getting-started/11.state-management.md +2 -2
  8. package/1.getting-started/14.layers.md +16 -2
  9. package/1.getting-started/15.prerendering.md +36 -9
  10. package/1.getting-started/16.deployment.md +3 -1
  11. package/2.directory-structure/1.app/1.components.md +23 -0
  12. package/2.directory-structure/1.app/1.composables.md +2 -2
  13. package/2.directory-structure/1.app/3.app-config.md +2 -0
  14. package/2.directory-structure/1.layers.md +2 -0
  15. package/2.directory-structure/1.server.md +7 -1
  16. package/2.directory-structure/1.shared.md +17 -1
  17. package/3.guide/1.concepts/1.rendering.md +9 -2
  18. package/3.guide/1.concepts/2.nuxt-lifecycle.md +2 -2
  19. package/3.guide/1.concepts/3.auto-imports.md +1 -1
  20. package/3.guide/2.best-practices/devcontainers.md +109 -0
  21. package/3.guide/2.best-practices/hydration.md +4 -4
  22. package/3.guide/2.best-practices/performance.md +2 -2
  23. package/3.guide/2.best-practices/plugins.md +3 -3
  24. package/3.guide/3.ai/1.mcp.md +1 -1
  25. package/3.guide/3.ai/2.llms-txt.md +3 -3
  26. package/3.guide/4.modules/7.best-practices.md +2 -2
  27. package/3.guide/4.modules/8.ecosystem.md +1 -1
  28. package/3.guide/5.recipes/1.custom-routing.md +1 -1
  29. package/3.guide/5.recipes/4.sessions-and-authentication.md +1 -1
  30. package/3.guide/6.going-further/1.experimental-features.md +14 -20
  31. package/3.guide/6.going-further/10.runtime-config.md +4 -0
  32. package/3.guide/6.going-further/7.layers.md +6 -0
  33. package/4.api/1.components/1.client-only.md +2 -2
  34. package/4.api/1.components/13.nuxt-time.md +12 -11
  35. package/4.api/1.components/14.nuxt-announcer.md +1 -1
  36. package/4.api/1.components/4.nuxt-link.md +2 -2
  37. package/4.api/1.components/6.nuxt-error-boundary.md +5 -5
  38. package/4.api/1.components/8.nuxt-island.md +21 -0
  39. package/4.api/2.composables/on-prehydrate.md +12 -2
  40. package/4.api/2.composables/use-announcer.md +1 -1
  41. package/4.api/2.composables/use-async-data.md +68 -68
  42. package/4.api/2.composables/use-cookie.md +5 -5
  43. package/4.api/2.composables/use-fetch.md +9 -9
  44. package/4.api/2.composables/use-head.md +1 -1
  45. package/4.api/2.composables/use-layout.md +4 -4
  46. package/4.api/2.composables/use-lazy-async-data.md +11 -5
  47. package/4.api/2.composables/use-lazy-fetch.md +13 -7
  48. package/4.api/2.composables/use-nuxt-app.md +7 -7
  49. package/4.api/2.composables/use-nuxt-data.md +7 -7
  50. package/4.api/2.composables/use-runtime-hook.md +2 -2
  51. package/4.api/3.utils/abort-navigation.md +1 -1
  52. package/4.api/3.utils/add-route-middleware.md +2 -2
  53. package/4.api/3.utils/define-lazy-hydration-component.md +1 -0
  54. package/4.api/3.utils/define-nuxt-plugin.md +1 -1
  55. package/4.api/3.utils/define-nuxt-route-middleware.md +1 -1
  56. package/4.api/3.utils/define-page-meta.md +1 -1
  57. package/4.api/3.utils/refresh-nuxt-data.md +1 -1
  58. package/4.api/4.commands/build.md +1 -1
  59. package/4.api/4.commands/dev.md +1 -1
  60. package/4.api/4.commands/generate.md +1 -1
  61. package/4.api/4.commands/init.md +1 -1
  62. package/4.api/4.commands/module.md +2 -2
  63. package/4.api/5.kit/1.modules.md +4 -4
  64. package/4.api/5.kit/10.templates.md +3 -3
  65. package/4.api/5.kit/11.app-config.md +1 -0
  66. package/4.api/5.kit/12.nitro.md +5 -5
  67. package/4.api/5.kit/13.resolving.md +8 -4
  68. package/4.api/5.kit/14.logging.md +1 -1
  69. package/4.api/5.kit/15.builder.md +1 -1
  70. package/4.api/5.kit/17.layers.md +1 -1
  71. package/4.api/5.kit/5.components.md +1 -1
  72. package/4.api/5.kit/6.context.md +2 -2
  73. package/4.api/5.kit/9.head.md +1 -1
  74. package/4.api/5.kit/9.plugins.md +2 -2
  75. package/4.api/6.advanced/1.hooks.md +3 -3
  76. package/4.api/6.advanced/2.import-meta.md +3 -3
  77. package/5.community/4.contribution.md +86 -0
  78. package/6.bridge/10.configuration.md +1 -1
  79. package/package.json +1 -1
@@ -107,6 +107,12 @@ deno run dev -o
107
107
  Well done! A browser window should automatically open for <http://localhost:3000>.
108
108
  ::
109
109
 
110
+ ::tip{icon="i-lucide-container"}
111
+ If you're using Docker or want a consistent development environment across machines, consider using a dev container.
112
+
113
+ [Learn more about dev containers](/docs/4.x/guide/best-practices/devcontainers)
114
+ ::
115
+
110
116
  ::
111
117
 
112
118
  ## Next Steps
@@ -52,3 +52,129 @@ For example, referencing an image file that will be processed if a build tool is
52
52
  ::note
53
53
  Nuxt won't serve files in the [`app/assets/`](/docs/4.x/directory-structure/app/assets) directory at a static URL like `/assets/my-file.png`. If you need a static URL, use the [`public/`](/docs/4.x/getting-started/assets#public-directory) directory.
54
54
  ::
55
+
56
+ ### Static vs. Dynamic `src`
57
+
58
+ When an `src` is a static string literal in your template, the build tool rewrites it into a runtime helper that resolves the final URL. A public path such as `/img/nuxt.png` is wrapped so that your [`app.baseURL`](/docs/4.x/api/nuxt-config#baseurl) is applied when the page renders, and a bundled path such as `~/assets/img/nuxt.png` additionally becomes an import that resolves to the hashed output file.
59
+
60
+ ```vue
61
+ <template>
62
+ <!-- Static paths are rewritten: app.baseURL is applied at runtime, and the bundled file is hashed. -->
63
+ <img src="/img/nuxt.png">
64
+ <img src="~/assets/img/nuxt.png">
65
+ </template>
66
+ ```
67
+
68
+ Because `app.baseURL` is applied at runtime, a static public path works even when the base URL is only known at deploy time (for example set via `NUXT_APP_BASE_URL`), and it works whether or not the file is processed by the build. This resolution only happens for literal paths the build tool can see.
69
+
70
+ A bound `:src` whose value is assembled at runtime is opaque to the build tool, so none of that rewriting happens. The string is used exactly as written:
71
+
72
+ ```vue
73
+ <template>
74
+ <!-- This does not work: the path is built at runtime, so Vite never sees it as an import. -->
75
+ <img :src="`~/assets/img/${name}.png`">
76
+ </template>
77
+ ```
78
+
79
+ A runtime-built public path like `/img/${name}.png` is therefore **not** prefixed with [`app.baseURL`](/docs/4.x/api/nuxt-config#baseurl). If your application is deployed below the origin root, prefix it yourself with [`useRuntimeConfig().app.baseURL`](/docs/4.x/api/composables/use-runtime-config) (for example via [`joinURL`](https://github.com/unjs/ufo#joinurl)).
80
+
81
+ The sections below cover how to handle each case when the path is only known at runtime.
82
+
83
+ #### Public Assets
84
+
85
+ If the files do not need to be processed or hashed, put them in the [`public/`](/docs/4.x/directory-structure/public) directory and reference them by URL:
86
+
87
+ ```vue [app/app.vue]
88
+ <script setup lang="ts">
89
+ const props = defineProps<{
90
+ name: string
91
+ }>()
92
+
93
+ const imageUrl = computed(() => `/img/${props.name}.png`)
94
+ </script>
95
+
96
+ <template>
97
+ <img
98
+ :src="imageUrl"
99
+ :alt="props.name"
100
+ >
101
+ </template>
102
+ ```
103
+
104
+ Files in `public/` keep their original filenames.
105
+
106
+ #### Bundled Assets with Vite
107
+
108
+ The approaches below are specific to Vite, Nuxt's default builder.
109
+
110
+ When the possible files are known, list their imports explicitly:
111
+
112
+ ```vue [app/app.vue]
113
+ <script setup lang="ts">
114
+ const props = defineProps<{
115
+ theme: 'light' | 'dark'
116
+ }>()
117
+
118
+ const logos = {
119
+ light: () => import('./assets/img/logo-light.png?url'),
120
+ dark: () => import('./assets/img/logo-dark.png?url'),
121
+ }
122
+
123
+ const logoUrl = (await logos[props.theme]()).default
124
+ </script>
125
+
126
+ <template>
127
+ <img
128
+ :src="logoUrl"
129
+ alt="Nuxt"
130
+ >
131
+ </template>
132
+ ```
133
+
134
+ Each import has a literal path, so Vite can find both files at build time while loading only the selected module at runtime.
135
+
136
+ When many files share a directory and extension, use a [variable dynamic import](https://vite.dev/guide/features.html#dynamic-import) instead of listing every file:
137
+
138
+ ```ts
139
+ async function getImageUrl (name: string) {
140
+ const image = await import(`./assets/img/${name}.png?url`)
141
+ return image.default
142
+ }
143
+ ```
144
+
145
+ Only the filename can be dynamic in this example. Keeping the directory and extension in the import lets Vite find the possible files at build time.
146
+
147
+ For a broader pattern or an explicit map of available files, use [`import.meta.glob`](https://vite.dev/guide/features.html#glob-import):
148
+
149
+ ```ts
150
+ const images = import.meta.glob<string>('./assets/img/*.{png,jpg,svg}', {
151
+ query: '?url',
152
+ import: 'default',
153
+ })
154
+
155
+ async function getImageUrl (name: string) {
156
+ const load = images[`./assets/img/${name}.png`]
157
+
158
+ if (!load) {
159
+ throw new Error(`Unknown image: ${name}`)
160
+ }
161
+
162
+ return await load()
163
+ }
164
+ ```
165
+
166
+ Glob imports are lazy by default. Add `eager: true` if the URLs must be available synchronously:
167
+
168
+ ```ts
169
+ const images = import.meta.glob<string>('./assets/img/*.{png,jpg,svg}', {
170
+ query: '?url',
171
+ import: 'default',
172
+ eager: true,
173
+ })
174
+ ```
175
+
176
+ Every matching asset is still included in the build output. Lazy imports load each match on demand, while an eager glob loads all matches up front and can increase the initial JavaScript size or inline small assets.
177
+
178
+ ::warning
179
+ Await a lazy import before using its URL in server-rendered markup. Vite's [`new URL(..., import.meta.url)` pattern](https://vite.dev/guide/assets.html#new-url-url-import-meta-url) does not work with SSR.
180
+ ::
@@ -6,6 +6,28 @@ navigation.icon: i-lucide-milestone
6
6
 
7
7
  One core feature of Nuxt is the file system router. Every Vue file inside the [`app/pages/`](/docs/4.x/directory-structure/app/pages) directory creates a corresponding URL (or route) that displays the contents of the file. By using dynamic imports for each page, Nuxt leverages code-splitting to ship the minimum amount of JavaScript for the requested route.
8
8
 
9
+ ::note
10
+ Code-splitting is enabled by default and is recommended for most apps. If you have a specific reason to ship a single bundle instead, you can disable it in your [`nuxt.config`](/docs/4.x/api/nuxt-config):
11
+
12
+ ```ts [nuxt.config.ts]
13
+ export default defineNuxtConfig({
14
+ vite: {
15
+ $client: {
16
+ build: {
17
+ rolldownOptions: {
18
+ output: {
19
+ codeSplitting: false,
20
+ },
21
+ },
22
+ },
23
+ },
24
+ },
25
+ })
26
+ ```
27
+
28
+ This ships all JavaScript in a single file. It is rarely beneficial — it usually increases the initial download, even on slow connections — so only disable code-splitting if you have measured that it helps your case.
29
+ ::
30
+
9
31
  ## Pages
10
32
 
11
33
  Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`app/pages/` directory](/docs/4.x/directory-structure/app/pages), based on their filename.
@@ -33,9 +33,24 @@ export default defineNuxtConfig({
33
33
  })
34
34
  ```
35
35
 
36
+ ::note
37
+ When you set [`app.cdnURL`](/docs/4.x/api/nuxt-config#cdnurl), assets in your [`public/`](/docs/4.x/directory-structure/public) directory (including `favicon.ico`) are served from that CDN. Nuxt resolves public assets against `cdnURL`, falling back to `app.baseURL`. However, a static `app.head` link such as `href: '/favicon.ico'` above is a literal path and is **not** resolved against `cdnURL`. To point the favicon at the resolved location, build the `href` from runtime config with [`useHead()`](/docs/4.x/api/composables/use-head) in `app.vue`:
38
+
39
+ ```vue [app/app.vue]
40
+ <script setup lang="ts">
41
+ const { cdnURL, baseURL } = useRuntimeConfig().app
42
+ useHead({
43
+ link: [
44
+ { rel: 'icon', type: 'image/x-icon', href: `${cdnURL || baseURL}favicon.ico` },
45
+ ],
46
+ })
47
+ </script>
48
+ ```
49
+ ::
50
+
36
51
  You can also provide any of the keys listed below in [Types](/docs/4.x/getting-started/seo-meta#types).
37
52
 
38
- ### Defaults Tags
53
+ ### Default Tags
39
54
 
40
55
  Some tags are provided by Nuxt by default to ensure your website works well out of the box.
41
56
 
@@ -142,7 +157,7 @@ If you need to duplicate tags across client-server boundaries, apply a `key` att
142
157
 
143
158
  Below are the non-reactive types used for [`useHead`](/docs/4.x/api/composables/use-head), [`app.head`](/docs/4.x/api/nuxt-config#head) and components.
144
159
 
145
- ```ts
160
+ ```ts [Types]
146
161
  interface MetaObject {
147
162
  title?: string
148
163
  titleTemplate?: string | ((title?: string) => string)
@@ -231,7 +246,7 @@ If you want to use a function (for full control), then this cannot be set in you
231
246
 
232
247
  Now, if you set the title to `My Page` with [`useHead`](/docs/4.x/api/composables/use-head) on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `null` to default to 'Site Title'.
233
248
 
234
- ### Template Params
249
+ ### Template Parameters
235
250
 
236
251
  You can use `templateParams` to provide additional placeholders in your `titleTemplate` besides the default `%s`. This allows for more dynamic title generation.
237
252
 
@@ -273,7 +288,7 @@ useHead({
273
288
  </script>
274
289
  ```
275
290
 
276
- ## Examples
291
+ ## Example
277
292
 
278
293
  ### With `definePageMeta`
279
294
 
@@ -8,6 +8,10 @@ navigation.icon: i-lucide-toggle-right
8
8
  Nuxt leverages Vue's [`<Transition>`](https://vuejs.org/guide/built-ins/transition#the-transition-component) component to apply transitions between pages and layouts.
9
9
  ::
10
10
 
11
+ ::important
12
+ Because Nuxt uses Vue's `<Transition>` component, a page or layout you want to animate must have a **single root element**. A page or layout with multiple root elements (a fragment) cannot be animated, so the transition will not run and navigating between routes may error. Nuxt warns about this in development. Wrap the template in a single root element (for example a `<div>`).
13
+ ::
14
+
11
15
  ## Page Transitions
12
16
 
13
17
  You can enable page transitions to apply an automatic transition for all your [pages](/docs/4.x/directory-structure/app/pages).
@@ -414,7 +418,7 @@ When `<NuxtPage />` is used in `app.vue`, transitions can be configured with the
414
418
  Remember, this page transition cannot be overridden with `definePageMeta` on individual pages.
415
419
  ::
416
420
 
417
- ## View Transitions API (experimental)
421
+ ## View Transitions API (Experimental)
418
422
 
419
423
  Nuxt ships with an experimental implementation of the [**View Transitions API**](https://developer.chrome.com/docs/web-platform/view-transitions) (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API)). This is an exciting new way to implement native browser transitions which (among other things) have the ability to transition between unrelated elements on different pages.
420
424
 
@@ -14,7 +14,7 @@ In a nutshell:
14
14
 
15
15
  Both `useFetch` and `useAsyncData` share a common set of options and patterns that we will detail in the last sections.
16
16
 
17
- ## The need for `useFetch` and `useAsyncData`
17
+ ## The Need for `useFetch` and `useAsyncData`
18
18
 
19
19
  Nuxt is a framework which can run isomorphic (or universal) code in both server and client environments. If the [`$fetch` function](/docs/4.x/api/utils/dollarfetch) is used to perform data fetching in the setup function of a Vue component, this may cause data to be fetched twice, once on the server (to render the HTML) and once again on the client (when the HTML is hydrated). This can cause hydration issues, increase the time to interactivity and cause unpredictable behavior.
20
20
 
@@ -546,8 +546,6 @@ const id = ref(null)
546
546
  const { data, status } = useLazyFetch(() => `/api/users/${id.value}`, {
547
547
  immediate: false,
548
548
  })
549
-
550
- const pending = computed(() => status.value === 'pending')
551
549
  </script>
552
550
 
553
551
  <template>
@@ -556,14 +554,14 @@ const pending = computed(() => status.value === 'pending')
556
554
  <input
557
555
  v-model="id"
558
556
  type="number"
559
- :disabled="pending"
557
+ :disabled="status === 'pending'"
560
558
  >
561
559
 
562
560
  <div v-if="status === 'idle'">
563
561
  Type a user ID
564
562
  </div>
565
563
 
566
- <div v-else-if="pending">
564
+ <div v-else-if="status === 'pending'">
567
565
  Loading ...
568
566
  </div>
569
567
 
@@ -29,7 +29,7 @@ For example, doing `export myState = ref({})` would result in state shared acros
29
29
  Instead use `const useX = () => useState('x')`
30
30
  ::
31
31
 
32
- ## Examples
32
+ ## Example
33
33
 
34
34
  ### Basic Usage
35
35
 
@@ -219,7 +219,7 @@ const color = useColor() // Same as useState('color')
219
219
 
220
220
  :video-accordion{title="Watch a video from Daniel Roe on how to deal with global state and SSR in Nuxt" videoId="dZSNW07sO-A"}
221
221
 
222
- ## Using third-party libraries
222
+ ## Using Third-Party Libraries
223
223
 
224
224
  Nuxt **used to rely** on the Vuex library to provide global state management. If you are migrating from Nuxt 2, please head to [the migration guide](/docs/4.x/migration/configuration#vuex).
225
225
 
@@ -127,12 +127,26 @@ layers/
127
127
  This pattern is useful for creating base layers with defaults that can be progressively overridden by more specific layers.
128
128
  ::
129
129
 
130
+ Alternatively, you can control the order of your `~~/layers` directories from `nuxt.config` by referencing them in [`extends`](/docs/4.x/api/nuxt-config#extends), without renaming your directories. The entries are ordered like any other `extends` layer, with the **first entry having the highest priority**:
131
+
132
+ ```ts [nuxt.config.ts]
133
+ export default defineNuxtConfig({
134
+ extends: [
135
+ '~~/layers/admin', // highest priority
136
+ '~~/layers/features',
137
+ '~~/layers/base', // lowest priority (among the listed layers)
138
+ ],
139
+ })
140
+ ```
141
+
142
+ Both `~~/...` (recommended) and `~/...` alias forms as well as relative paths (`./layers/admin`) are supported. Any layer in `~~/layers` that you do not list keeps its alphabetical auto-scan order, ranked below the layers you list in `extends`.
143
+
130
144
  ### When to Use Each
131
145
 
132
146
  - **`~~/layers` directory** - Use for local layers that are part of your project
133
147
  - **`extends`** - Use for external dependencies (npm packages, remote repositories) or layers outside your project directory
134
148
 
135
- ### Full Example with extends
149
+ ### Full Example with `extends`
136
150
 
137
151
  ```ts [nuxt.config.ts]
138
152
  export default defineNuxtConfig({
@@ -163,7 +177,7 @@ Read more about layers in the **Layer Author Guide**.
163
177
 
164
178
  :video-accordion{title="Watch a video from Alexander Lichter about Nuxt Layers" videoId="fr5yo3aVkfA"}
165
179
 
166
- ## Examples
180
+ ## Example
167
181
 
168
182
  ::card-group
169
183
  ::card{icon="i-simple-icons-github" title="Content Wind" to="https://github.com/Atinux/content-wind" target="_blank"}
@@ -40,23 +40,17 @@ deno x nuxt generate
40
40
 
41
41
  You can now deploy the `.output/public` directory to any static hosting service or preview it locally with `npx serve .output/public`.
42
42
 
43
+ Static and prerender builds also emit `200.html` and `404.html` SPA fallbacks. See [What are 200.html and 404.html?](/docs/4.x/guide/concepts/rendering#what-are-200html-and-404html).
44
+
43
45
  Working of the Nitro crawler:
44
46
 
45
47
  1. Load the HTML of your application's root route (`/`), any non-dynamic pages in your `~/pages` directory, and any other routes in the `nitro.prerender.routes` array.
46
- 2. Save the HTML and `payload.json` to the `~/.output/public/` directory to be served statically.
48
+ 2. Save the HTML and `_payload.json` to the `~/.output/public/` directory to be served statically.
47
49
  3. Find all anchor tags (`<a href="...">`) in the HTML to navigate to other routes.
48
50
  4. Repeat steps 1-3 for each anchor tag found until there are no more anchor tags to crawl.
49
51
 
50
52
  This is important to understand since pages that are not linked to a discoverable page can't be pre-rendered automatically.
51
53
 
52
- ### Payload Extraction
53
-
54
- Nuxt generates `_payload.json` alongside HTML for:
55
- - Prerendered routes (at build time)
56
- - ISR/SWR routes (on first request)
57
-
58
- Payloads contain serialized data from `useAsyncData` and `useFetch`. Client-side navigation loads these cached payloads instead of re-fetching data. Configure dynamic routes like `pages/[...slug].vue` with route rules: `'/**': { isr: true }`.
59
-
60
54
  ::read-more{to="/docs/4.x/api/commands/generate#nuxt-generate"}
61
55
  Read more about the `nuxt generate` command.
62
56
  ::
@@ -149,6 +143,39 @@ export default defineNuxtConfig({
149
143
  })
150
144
  ```
151
145
 
146
+ ## Payload Extraction
147
+
148
+ When Nuxt renders a page on the server, it serializes the results of your data fetching ([`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`useFetch`](/docs/4.x/api/composables/use-fetch)) and app state ([`useState`](/docs/4.x/api/composables/use-state)) into a payload so the client can hydrate without re-fetching. With payload extraction enabled, Nuxt also writes this payload to a `_payload.json` file alongside the route's HTML:
149
+
150
+ - Prerendered routes generate their payload file at build time.
151
+ - Routes using [ISR or SWR caching](/docs/4.x/guide/concepts/rendering#hybrid-rendering) generate their payload file when the route is first rendered, even on a hybrid (non-static) site.
152
+
153
+ During client-side navigation, Nuxt fetches the `_payload.json` file for the destination route and reuses the extracted data instead of running the data fetching again in the browser.
154
+
155
+ You can control this behavior with the [`experimental.payloadExtraction`](/docs/4.x/api/nuxt-config#payloadextraction) option:
156
+
157
+ - `'client'` - The payload is inlined in the HTML for the initial render and extracted to `_payload.json` files for client-side navigation. There is no extra network request on first load.
158
+ - `true` - The payload is extracted to a separate `_payload.json` file for both the initial render and client-side navigation. The HTML is smaller and the payload file can be cached by a CDN, at the cost of one extra request on first load.
159
+ - `false` - Payload extraction is disabled. The payload is always inlined in the HTML and no `_payload.json` files are generated.
160
+
161
+ The default is `true`, or `'client'` when `compatibilityVersion: 5` is set. It is forced to `false` when `ssr: false` is set.
162
+
163
+ ```ts twoslash [nuxt.config.ts]
164
+ export default defineNuxtConfig({
165
+ experimental: {
166
+ payloadExtraction: 'client',
167
+ },
168
+ })
169
+ ```
170
+
171
+ A few practical consequences to be aware of:
172
+
173
+ - On a fully static site, client-side navigation reuses the data captured at build time, so data can be stale until the next rebuild.
174
+ - For ISR/SWR routes, CDNs can cache payload files alongside the HTML, improving client-side navigation performance for cached routes. Dynamic routes like `pages/[...slug].vue` can opt in with glob patterns such as `'/**': { isr: true }`.
175
+ - Payloads are serialized with [devalue](https://github.com/Rich-Harris/devalue), so custom types (such as class instances) need payload plugins with custom reducers and revivers to survive the round trip.
176
+
177
+ :read-more{title="Payload reducers and revivers" to="/docs/4.x/api/composables/use-nuxt-app#payload"}
178
+
152
179
  ## Runtime Prerender Configuration
153
180
 
154
181
  ### `prerenderRoutes`
@@ -77,9 +77,11 @@ By default, the workload gets distributed to the workers with the round robin st
77
77
 
78
78
  There are two ways to deploy a Nuxt application to any static hosting services:
79
79
 
80
- - Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `nuxt generate`.) It will also generate `/200.html` and `/404.html` single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host).
80
+ - Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `nuxt generate`.) It will also generate `/200.html` and `/404.html` single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host). See [What are 200.html and 404.html?](/docs/4.x/guide/concepts/rendering#what-are-200html-and-404html).
81
81
  - Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/4.x/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
82
82
 
83
+ Prerendered routes also emit `_payload.json` files with the data captured at build time, which Nuxt reuses during client-side navigation. Read more about [payload extraction](/docs/4.x/getting-started/prerendering#payload-extraction).
84
+
83
85
  ### Static Fallback Pages
84
86
 
85
87
  Nuxt can generate two fallback pages for static hosts:
@@ -356,6 +356,25 @@ export default defineNuxtConfig({
356
356
  Any nested directories need to be added first as they are scanned in order.
357
357
  ::
358
358
 
359
+ Each directory entry also accepts `pattern` and `ignore` glob options, which control which files are scanned within `path`. This is useful when your components live in nested folders that don't follow the default layout, such as a domain-driven structure:
360
+
361
+ ```ts twoslash [nuxt.config.ts]
362
+ export default defineNuxtConfig({
363
+ components: [
364
+ // ~/domains/blog/components/PostCard.vue => <PostCard />
365
+ {
366
+ path: '~/domains',
367
+ pattern: '*/components/**',
368
+ pathPrefix: false,
369
+ },
370
+ ],
371
+ })
372
+ ```
373
+
374
+ ::note
375
+ If `pattern` is specified, the `extensions` option has no effect, so make sure your pattern matches the file extensions you want to scan.
376
+ ::
377
+
359
378
  ## npm Packages
360
379
 
361
380
  If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/4.x/api/kit/components#addcomponent) in a [local module](/docs/4.x/directory-structure/modules) to register them.
@@ -524,6 +543,10 @@ You can partially hydrate a component by setting a `nuxt-client` attribute on th
524
543
  This only works within a server component. Slots for client components are working only with `experimental.componentIsland.selectiveClient` set to `'deep'` and since they are rendered server-side, they are not interactive once client-side.
525
544
  ::
526
545
 
546
+ ::warning
547
+ Use `nuxt-client` only on local `.vue` SFCs. Built-ins like [`<NuxtLink>`](/docs/4.x/api/components/nuxt-link) skip the islands transform. After client navigation you may see `Failed to locate Teleport target`, or the link disappears with no error. Wrap the built-in in your own `.vue` file and put `nuxt-client` on that wrapper, or drop `nuxt-client` from the built-in. See [#29251](https://github.com/nuxt/nuxt/issues/29251) and [#26002](https://github.com/nuxt/nuxt/issues/26002).
548
+ ::
549
+
527
550
  #### Server Component Context
528
551
 
529
552
  When rendering a server-only or island component, `<NuxtIsland>` makes a fetch request which comes back with a `NuxtIslandResponse`. (This is an internal request if rendered on the server, or a request that you can see in the network tab if it's rendering on client-side navigation.)
@@ -56,7 +56,7 @@ Be aware that you have to run [`nuxt prepare`](/docs/4.x/api/commands/prepare),
56
56
  If you create a composable without having the dev server running, TypeScript will throw an error, such as `Cannot find name 'useBar'.`
57
57
  ::
58
58
 
59
- ## Examples
59
+ ## Example
60
60
 
61
61
  ### Nested Composables
62
62
 
@@ -69,7 +69,7 @@ export const useFoo = () => {
69
69
  }
70
70
  ```
71
71
 
72
- ### Access plugin injections
72
+ ### Access Plugin Injections
73
73
 
74
74
  You can access [plugin injections](/docs/4.x/directory-structure/app/plugins#providing-helpers) from composables:
75
75
 
@@ -67,6 +67,8 @@ Read more about the `updateAppConfig` utility.
67
67
 
68
68
  Nuxt tries to automatically generate a TypeScript interface from provided app config so you won't have to type it yourself.
69
69
 
70
+ The fully inferred type is only available in app code (components, composables, plugins and so on). In server routes, code in the `shared/` directory and `nuxt.config`, keys defined in `app.config` files are typed as `unknown` instead: typing them there would require typechecking your app code outside the app context, where app auto-imports are not available. Keys defined inline in the `appConfig` option of `nuxt.config` are typed everywhere. If you need other keys typed outside app code, you can extend the `AppConfig` interface as described below. The location of the augmentation file determines which contexts see it: a `.d.ts` file in the `shared/` directory covers app code, shared code and server routes.
71
+
70
72
  However, there are some cases where you might want to type it yourself. There are two possible things you might want to type.
71
73
 
72
74
  ### App Config Input
@@ -82,6 +82,8 @@ When multiple layers define the same resource (component, composable, page, etc.
82
82
 
83
83
  To control the order, prefix directories with numbers: `1.base/`, `2.features/`, `3.admin/`.
84
84
 
85
+ Alternatively, reference the directories in [`extends`](/docs/4.x/api/nuxt-config#extends) (e.g. `extends: ['~~/layers/admin', '~~/layers/base']`) to order them from `nuxt.config` without renaming, with the first entry taking the highest priority.
86
+
85
87
  :read-more{to="/docs/4.x/getting-started/layers#layer-priority"}
86
88
 
87
89
  :video-accordion{title="Watch a video from Learn Vue about Nuxt Layers" videoId="lnFCM7c9f7I"}
@@ -7,7 +7,7 @@ navigation.icon: i-vscode-icons-folder-type-server
7
7
 
8
8
  Nuxt automatically scans files inside these directories to register API and server handlers with Hot Module Replacement (HMR) support.
9
9
 
10
- ```bash [Directory structure]
10
+ ```bash [Directory Structure]
11
11
  -| server/
12
12
  ---| api/
13
13
  -----| hello.ts # /api/hello
@@ -21,6 +21,12 @@ Each file should export a default function defined with `defineEventHandler()` o
21
21
 
22
22
  The handler can directly return JSON data, a `Promise`, or use `event.node.res.end()` to send a response.
23
23
 
24
+ ::important
25
+ Do not import Vue app code (components, composables, or other app-only utilities) in your server routes or utilities, and do not import server-only code in your app.
26
+ ::
27
+
28
+ :read-more{to="/docs/4.x/directory-structure/shared#why-you-cannot-mix-vue-and-nitro-code" title="Why You Cannot Mix Vue and Nitro Code"}
29
+
24
30
  ```ts twoslash [server/api/hello.ts]
25
31
  export default defineEventHandler((event) => {
26
32
  return {
@@ -15,6 +15,22 @@ The `shared/` directory is available in Nuxt v3.14+.
15
15
  Code in the `shared/` directory cannot import any Vue or Nitro code.
16
16
  ::
17
17
 
18
+ ## Why You Cannot Mix Vue and Nitro Code
19
+
20
+ Nuxt builds two separate bundles: the Vue app (client and server-side rendering) and the Nitro server (API routes, server middleware, server plugins). They are bundled independently and run in different contexts. Code in the `shared/` directory is used in both bundles, so it cannot import from either.
21
+
22
+ ### Vue App Code in Nitro
23
+
24
+ Components and composables need the Vue app runtime and often the Nuxt context (for example `useNuxtApp()` or `useRoute()`), neither of which exists in Nitro. Importing them into server code can cause build or runtime errors, and can pull the Vue app's dependencies into your server bundle.
25
+
26
+ ### Nitro Code in the Vue App
27
+
28
+ Server-only code (such as Node APIs, Nitro utilities, or server route handlers) must not run in the browser. Importing it into your app can break the client build, cause runtime errors in the browser, or leak server logic into the client bundle.
29
+
30
+ ### Type-Only Imports
31
+
32
+ `import type` is erased at compile time and does not pull runtime code into the other bundle, so importing only types across the boundary may appear to work. Even so, keep shared types (such as API response types) in `shared/types/`, where they are auto-imported in both contexts. This keeps the boundary clear, avoids accidentally turning a type import into a value import later, and matches Nuxt's separate [type contexts](/docs/4.x/guide/concepts/typescript#project-references) for app, server, and shared code.
33
+
18
34
  :video-accordion{title="Watch a video from Vue School on sharing utils and types between app and server" videoId="nnAR-MO3q5M"}
19
35
 
20
36
  ## Usage
@@ -82,7 +98,7 @@ The way `shared/utils` and `shared/types` auto-imports work and are scanned is i
82
98
 
83
99
  Any other files you create in the `shared/` folder must be manually imported using the `#shared` alias (automatically configured by Nuxt):
84
100
 
85
- ```ts
101
+ ```ts [Importing From #shared]
86
102
  // For files directly in the shared directory
87
103
  import capitalize from '#shared/capitalize'
88
104
 
@@ -124,7 +124,14 @@ This will produce three files:
124
124
  - `200.html`
125
125
  - `404.html`
126
126
 
127
- The `200.html` file is intended for static hosts that need a success-status fallback for client-side routing. The `404.html` file is intended for static hosts that serve a not-found page while preserving a 404 status. Which file you should use depends on your hosting provider's fallback or rewrite settings.
127
+ #### What are 200.html and 404.html?
128
+
129
+ Static hosts need an HTML shell for client-side routes and missing paths. Nuxt emits two SPA fallbacks for that:
130
+
131
+ - **`200.html`**. Serve this for unmatched paths when you want the client router to handle the URL.
132
+ - **`404.html`**. Serve this when the host should keep a 404 status and still load your app.
133
+
134
+ `nuxt generate` and `nuxt build --prerender` write these into `.output/public/`. A plain `nuxt build` without prerender does not. With hybrid route rules, add the fallbacks with route rules or run a prerender build if you need them. Point your host at the file your provider expects.
128
135
 
129
136
  #### Skipping Client Fallback Generation
130
137
 
@@ -194,7 +201,7 @@ The different properties you can use are the following:
194
201
  - `appMiddleware: string | string[] | Record<string, boolean>`{lang=ts} - Allows you to define middleware that should or should not run for page paths within the Vue app part of your application (that is, not your Nitro routes)
195
202
 
196
203
  ::note
197
- Routes using `isr` or `swr` also generate `_payload.json` files alongside HTML. Client-side navigation loads these cached payloads instead of re-fetching data. Configure dynamic routes like `pages/[...slug].vue` with glob patterns: `'/**': { isr: true }`.
204
+ Routes using `isr` or `swr` also generate `_payload.json` files alongside HTML. Client-side navigation loads these cached payloads instead of re-fetching data. Read more about [payload extraction](/docs/4.x/getting-started/prerendering#payload-extraction).
198
205
  ::
199
206
 
200
207
  Whenever possible, route rules will be automatically applied to the deployment platform's native rules for optimal performances (Netlify and Vercel are currently supported).
@@ -5,7 +5,7 @@ description: "Understanding the lifecycle of Nuxt applications can help you gain
5
5
 
6
6
  The goal of this chapter is to provide a high-level overview of the different parts of the framework, their execution order, and how they work together.
7
7
 
8
- ## Server lifecycle
8
+ ## Server Lifecycle
9
9
 
10
10
  On the server, the following steps are executed for every initial request to your application:
11
11
 
@@ -109,7 +109,7 @@ Before finalizing and sending the HTML, Nitro will call the [`render:html`](/doc
109
109
 
110
110
  ::
111
111
 
112
- ## Client lifecycle
112
+ ## Client Lifecycle
113
113
 
114
114
  This part of the lifecycle is fully executed in the browser, no matter which Nuxt mode you've chosen.
115
115
 
@@ -179,7 +179,7 @@ export default defineNuxtConfig({
179
179
  })
180
180
  ```
181
181
 
182
- ## Auto-import from Third-Party Packages
182
+ ## Auto-Import from Third-Party Packages
183
183
 
184
184
  Nuxt also allows auto-importing from third-party packages.
185
185