@nuxt/docs-nightly 4.1.3-29313386.edc02e27 → 4.1.3-29316215.910d159d

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 (165) hide show
  1. package/1.getting-started/01.introduction.md +4 -4
  2. package/1.getting-started/02.installation.md +1 -1
  3. package/1.getting-started/03.configuration.md +25 -25
  4. package/1.getting-started/04.views.md +3 -3
  5. package/1.getting-started/05.assets.md +9 -3
  6. package/1.getting-started/06.styling.md +53 -43
  7. package/1.getting-started/07.routing.md +9 -9
  8. package/1.getting-started/08.seo-meta.md +50 -37
  9. package/1.getting-started/09.transitions.md +38 -33
  10. package/1.getting-started/10.data-fetching.md +61 -53
  11. package/1.getting-started/11.state-management.md +19 -12
  12. package/1.getting-started/12.error-handling.md +17 -15
  13. package/1.getting-started/13.server.md +8 -8
  14. package/1.getting-started/14.layers.md +19 -13
  15. package/1.getting-started/15.prerendering.md +28 -28
  16. package/1.getting-started/16.deployment.md +8 -8
  17. package/1.getting-started/17.testing.md +42 -42
  18. package/1.getting-started/18.upgrade.md +50 -68
  19. package/2.guide/0.index.md +5 -5
  20. package/2.guide/1.directory-structure/0.output.md +1 -1
  21. package/2.guide/1.directory-structure/1.app/1.assets.md +1 -1
  22. package/2.guide/1.directory-structure/1.app/1.components.md +40 -23
  23. package/2.guide/1.directory-structure/1.app/1.composables.md +9 -9
  24. package/2.guide/1.directory-structure/1.app/1.layouts.md +12 -8
  25. package/2.guide/1.directory-structure/1.app/1.middleware.md +23 -17
  26. package/2.guide/1.directory-structure/1.app/1.pages.md +25 -23
  27. package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
  28. package/2.guide/1.directory-structure/1.app/1.utils.md +3 -3
  29. package/2.guide/1.directory-structure/1.app/3.app-config.md +7 -7
  30. package/2.guide/1.directory-structure/1.app/3.app.md +3 -3
  31. package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
  32. package/2.guide/1.directory-structure/1.content.md +4 -1
  33. package/2.guide/1.directory-structure/1.modules.md +5 -5
  34. package/2.guide/1.directory-structure/1.public.md +1 -1
  35. package/2.guide/1.directory-structure/1.server.md +30 -30
  36. package/2.guide/1.directory-structure/1.shared.md +3 -3
  37. package/2.guide/1.directory-structure/2.env.md +3 -3
  38. package/2.guide/1.directory-structure/2.nuxtrc.md +1 -1
  39. package/2.guide/1.directory-structure/3.nuxt-config.md +1 -1
  40. package/2.guide/2.concepts/1.auto-imports.md +15 -15
  41. package/2.guide/2.concepts/10.nuxt-lifecycle.md +7 -7
  42. package/2.guide/2.concepts/2.vuejs-development.md +9 -9
  43. package/2.guide/2.concepts/3.rendering.md +17 -15
  44. package/2.guide/2.concepts/4.server-engine.md +1 -1
  45. package/2.guide/2.concepts/5.modules.md +3 -3
  46. package/2.guide/2.concepts/7.esm.md +16 -14
  47. package/2.guide/2.concepts/8.typescript.md +4 -4
  48. package/2.guide/3.going-further/1.events.md +3 -3
  49. package/2.guide/3.going-further/1.experimental-features.md +238 -77
  50. package/2.guide/3.going-further/1.features.md +44 -9
  51. package/2.guide/3.going-further/1.internals.md +15 -15
  52. package/2.guide/3.going-further/10.runtime-config.md +8 -8
  53. package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
  54. package/2.guide/3.going-further/2.hooks.md +11 -11
  55. package/2.guide/3.going-further/3.modules.md +83 -81
  56. package/2.guide/3.going-further/4.kit.md +5 -5
  57. package/2.guide/3.going-further/6.nuxt-app.md +4 -4
  58. package/2.guide/3.going-further/7.layers.md +51 -42
  59. package/2.guide/3.going-further/9.debugging.md +2 -2
  60. package/2.guide/4.recipes/1.custom-routing.md +19 -19
  61. package/2.guide/4.recipes/2.vite-plugin.md +3 -3
  62. package/2.guide/4.recipes/3.custom-usefetch.md +10 -10
  63. package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
  64. package/2.guide/5.best-practices/performance.md +13 -13
  65. package/3.api/1.components/1.client-only.md +6 -3
  66. package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
  67. package/3.api/1.components/11.teleports.md +5 -2
  68. package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
  69. package/3.api/1.components/13.nuxt-time.md +44 -17
  70. package/3.api/1.components/2.nuxt-page.md +4 -4
  71. package/3.api/1.components/3.nuxt-layout.md +13 -8
  72. package/3.api/1.components/4.nuxt-link.md +40 -20
  73. package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
  74. package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
  75. package/3.api/2.composables/on-prehydrate.md +2 -2
  76. package/3.api/2.composables/use-app-config.md +1 -1
  77. package/3.api/2.composables/use-async-data.md +14 -14
  78. package/3.api/2.composables/use-cookie.md +27 -19
  79. package/3.api/2.composables/use-error.md +2 -2
  80. package/3.api/2.composables/use-fetch.md +17 -17
  81. package/3.api/2.composables/use-head-safe.md +5 -5
  82. package/3.api/2.composables/use-head.md +3 -3
  83. package/3.api/2.composables/use-hydration.md +5 -5
  84. package/3.api/2.composables/use-lazy-async-data.md +2 -2
  85. package/3.api/2.composables/use-lazy-fetch.md +2 -2
  86. package/3.api/2.composables/use-loading-indicator.md +10 -10
  87. package/3.api/2.composables/use-nuxt-app.md +10 -10
  88. package/3.api/2.composables/use-nuxt-data.md +7 -7
  89. package/3.api/2.composables/use-preview-mode.md +12 -15
  90. package/3.api/2.composables/use-request-fetch.md +1 -1
  91. package/3.api/2.composables/use-request-headers.md +3 -3
  92. package/3.api/2.composables/use-response-header.md +7 -8
  93. package/3.api/2.composables/use-route-announcer.md +3 -3
  94. package/3.api/2.composables/use-router.md +6 -4
  95. package/3.api/2.composables/use-runtime-config.md +11 -11
  96. package/3.api/2.composables/use-runtime-hook.md +1 -1
  97. package/3.api/2.composables/use-seo-meta.md +3 -3
  98. package/3.api/2.composables/use-server-seo-meta.md +3 -3
  99. package/3.api/2.composables/use-state.md +4 -4
  100. package/3.api/3.utils/$fetch.md +6 -4
  101. package/3.api/3.utils/abort-navigation.md +2 -2
  102. package/3.api/3.utils/add-route-middleware.md +3 -3
  103. package/3.api/3.utils/call-once.md +5 -5
  104. package/3.api/3.utils/clear-error.md +2 -2
  105. package/3.api/3.utils/clear-nuxt-data.md +2 -2
  106. package/3.api/3.utils/clear-nuxt-state.md +2 -2
  107. package/3.api/3.utils/create-error.md +2 -2
  108. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  109. package/3.api/3.utils/define-nuxt-component.md +5 -5
  110. package/3.api/3.utils/define-nuxt-plugin.md +12 -12
  111. package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
  112. package/3.api/3.utils/define-page-meta.md +16 -16
  113. package/3.api/3.utils/define-route-rules.md +5 -5
  114. package/3.api/3.utils/navigate-to.md +10 -10
  115. package/3.api/3.utils/preload-components.md +1 -1
  116. package/3.api/3.utils/preload-route-components.md +2 -2
  117. package/3.api/3.utils/prerender-routes.md +2 -2
  118. package/3.api/3.utils/refresh-cookie.md +4 -4
  119. package/3.api/3.utils/refresh-nuxt-data.md +10 -5
  120. package/3.api/3.utils/reload-nuxt-app.md +3 -3
  121. package/3.api/3.utils/set-response-status.md +2 -2
  122. package/3.api/3.utils/show-error.md +3 -3
  123. package/3.api/3.utils/update-app-config.md +3 -2
  124. package/3.api/4.commands/generate.md +1 -1
  125. package/3.api/4.commands/prepare.md +4 -0
  126. package/3.api/4.commands/typecheck.md +1 -1
  127. package/3.api/5.kit/1.modules.md +36 -36
  128. package/3.api/5.kit/10.templates.md +8 -6
  129. package/3.api/5.kit/11.nitro.md +62 -62
  130. package/3.api/5.kit/12.resolving.md +2 -2
  131. package/3.api/5.kit/14.builder.md +1 -0
  132. package/3.api/5.kit/15.examples.md +2 -2
  133. package/3.api/5.kit/16.layers.md +26 -26
  134. package/3.api/5.kit/3.compatibility.md +12 -12
  135. package/3.api/5.kit/4.autoimports.md +12 -12
  136. package/3.api/5.kit/5.components.md +5 -5
  137. package/3.api/5.kit/6.context.md +3 -3
  138. package/3.api/5.kit/7.pages.md +4 -4
  139. package/3.api/5.kit/8.layout.md +1 -1
  140. package/3.api/5.kit/9.plugins.md +5 -4
  141. package/3.api/6.advanced/1.hooks.md +1 -1
  142. package/3.api/6.advanced/2.import-meta.md +3 -3
  143. package/3.api/6.nuxt-config.md +299 -864
  144. package/3.api/index.md +7 -7
  145. package/5.community/4.contribution.md +5 -5
  146. package/5.community/5.framework-contribution.md +1 -1
  147. package/6.bridge/1.overview.md +1 -1
  148. package/6.bridge/10.configuration.md +2 -1
  149. package/6.bridge/2.typescript.md +2 -2
  150. package/6.bridge/3.bridge-composition-api.md +4 -4
  151. package/6.bridge/4.plugins-and-middleware.md +5 -5
  152. package/6.bridge/5.nuxt3-compatible-api.md +12 -9
  153. package/6.bridge/6.meta.md +15 -14
  154. package/6.bridge/8.nitro.md +2 -2
  155. package/6.bridge/9.vite.md +3 -3
  156. package/7.migration/10.bundling.md +1 -1
  157. package/7.migration/11.server.md +3 -3
  158. package/7.migration/2.configuration.md +18 -16
  159. package/7.migration/20.module-authors.md +1 -1
  160. package/7.migration/4.meta.md +18 -15
  161. package/7.migration/5.plugins-and-middleware.md +8 -8
  162. package/7.migration/6.pages-and-layouts.md +20 -16
  163. package/7.migration/7.component-options.md +7 -7
  164. package/7.migration/8.runtime-config.md +4 -4
  165. package/package.json +1 -1
@@ -30,12 +30,12 @@ Use the [Nuxt DevTools](https://devtools.nuxt.com) to inspect this data in the *
30
30
  <script setup lang="ts">
31
31
  const { data } = await useFetch('/api/data')
32
32
 
33
- async function handleFormSubmit() {
33
+ async function handleFormSubmit () {
34
34
  const res = await $fetch('/api/submit', {
35
35
  method: 'POST',
36
36
  body: {
37
37
  // My form data
38
- }
38
+ },
39
39
  })
40
40
  }
41
41
  </script>
@@ -68,23 +68,23 @@ Nuxt includes the [ofetch](https://github.com/unjs/ofetch) library, and is auto-
68
68
 
69
69
  ```vue twoslash [pages/todos.vue]
70
70
  <script setup lang="ts">
71
- async function addTodo() {
71
+ async function addTodo () {
72
72
  const todo = await $fetch('/api/todos', {
73
73
  method: 'POST',
74
74
  body: {
75
75
  // My todo data
76
- }
76
+ },
77
77
  })
78
78
  }
79
79
  </script>
80
80
  ```
81
81
 
82
82
  ::warning
83
- Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](/docs/getting-started/data-fetching#the-need-for-usefetch-and-useasyncdata). :br
84
- It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](/docs/getting-started/data-fetching#useasyncdata) when fetching the initial component data.
83
+ Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](/docs/4.x/getting-started/data-fetching#the-need-for-usefetch-and-useasyncdata). :br
84
+ It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](/docs/4.x/getting-started/data-fetching#useasyncdata) when fetching the initial component data.
85
85
  ::
86
86
 
87
- ::read-more{to="/docs/api/utils/dollarfetch"}
87
+ ::read-more{to="/docs/4.x/api/utils/dollarfetch"}
88
88
  Read more about `$fetch`.
89
89
  ::
90
90
 
@@ -94,7 +94,7 @@ When calling `useFetch` on the server, Nuxt will use [`useRequestFetch`](/docs/4
94
94
 
95
95
  ```vue
96
96
  <script setup lang="ts">
97
- const { data } = await useFetch('/api/echo');
97
+ const { data } = await useFetch('/api/echo')
98
98
  </script>
99
99
  ```
100
100
 
@@ -109,7 +109,7 @@ Alternatively, the example below shows how to use [`useRequestHeaders`](/docs/4.
109
109
  <script setup lang="ts">
110
110
  const headers = useRequestHeaders(['cookie'])
111
111
 
112
- async function getCurrentUser() {
112
+ async function getCurrentUser () {
113
113
  return await $fetch('/api/me', { headers })
114
114
  }
115
115
  </script>
@@ -146,9 +146,9 @@ This composable is a wrapper around the [`useAsyncData`](/docs/4.x/api/composabl
146
146
 
147
147
  :video-accordion{title="Watch a video from Alexander Lichter to avoid using useFetch the wrong way" videoId="njsGVmcWviY"}
148
148
 
149
- :read-more{to="/docs/api/composables/use-fetch"}
149
+ :read-more{to="/docs/4.x/api/composables/use-fetch"}
150
150
 
151
- :link-example{to="/docs/examples/features/data-fetching"}
151
+ :link-example{to="/docs/4.x/examples/features/data-fetching"}
152
152
 
153
153
  ## `useAsyncData`
154
154
 
@@ -197,7 +197,7 @@ The `useAsyncData` composable is a great way to wrap and wait for multiple `$fet
197
197
  const { data: discounts, status } = await useAsyncData('cart-discount', async () => {
198
198
  const [coupons, offers] = await Promise.all([
199
199
  $fetch('/cart/coupons'),
200
- $fetch('/cart/offers')
200
+ $fetch('/cart/offers'),
201
201
  ])
202
202
 
203
203
  return { coupons, offers }
@@ -220,7 +220,7 @@ await useAsyncData(() => offersStore.getOffer(route.params.slug))
220
220
  ```
221
221
  ::
222
222
 
223
- ::read-more{to="/docs/api/composables/use-async-data"}
223
+ ::read-more{to="/docs/4.x/api/composables/use-async-data"}
224
224
  Read more about `useAsyncData`.
225
225
  ::
226
226
 
@@ -255,7 +255,7 @@ By default, data fetching composables will wait for the resolution of their asyn
255
255
  ```vue twoslash [app/app.vue]
256
256
  <script setup lang="ts">
257
257
  const { status, data: posts } = useFetch('/api/posts', {
258
- lazy: true
258
+ lazy: true,
259
259
  })
260
260
  </script>
261
261
 
@@ -280,11 +280,11 @@ const { status, data: posts } = useLazyFetch('/api/posts')
280
280
  </script>
281
281
  ```
282
282
 
283
- ::read-more{to="/docs/api/composables/use-lazy-fetch"}
283
+ ::read-more{to="/docs/4.x/api/composables/use-lazy-fetch"}
284
284
  Read more about `useLazyFetch`.
285
285
  ::
286
286
 
287
- ::read-more{to="/docs/api/composables/use-lazy-async-data"}
287
+ ::read-more{to="/docs/4.x/api/composables/use-lazy-async-data"}
288
288
  Read more about `useLazyAsyncData`.
289
289
  ::
290
290
 
@@ -303,11 +303,11 @@ const articles = await useFetch('/api/article')
303
303
  /* This call will only be performed on the client */
304
304
  const { status, data: comments } = useFetch('/api/comments', {
305
305
  lazy: true,
306
- server: false
306
+ server: false,
307
307
  })
308
308
  ```
309
309
 
310
- The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](/docs/getting-started/data-fetching#fetch).
310
+ The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](/docs/4.x/getting-started/data-fetching#fetch).
311
311
 
312
312
  ### Minimize payload size
313
313
 
@@ -317,7 +317,7 @@ The `pick` option helps you to minimize the payload size stored in your HTML doc
317
317
  <script setup lang="ts">
318
318
  /* only pick the fields used in your template */
319
319
  const { data: mountain } = await useFetch('/api/mountains/everest', {
320
- pick: ['title', 'description']
320
+ pick: ['title', 'description'],
321
321
  })
322
322
  </script>
323
323
 
@@ -333,7 +333,7 @@ If you need more control or map over several objects, you can use the `transform
333
333
  const { data: mountains } = await useFetch('/api/mountains', {
334
334
  transform: (mountains) => {
335
335
  return mountains.map(mountain => ({ title: mountain.title, description: mountain.description }))
336
- }
336
+ },
337
337
  })
338
338
  ```
339
339
 
@@ -406,7 +406,7 @@ You can use computed refs, plain refs or getter functions as keys, allowing for
406
406
  const userId = ref('123')
407
407
  const { data: user } = useAsyncData(
408
408
  computed(() => `user-${userId.value}`),
409
- () => fetchUser(userId.value)
409
+ () => fetchUser(userId.value),
410
410
  )
411
411
 
412
412
  // When userId changes, the data will be automatically refetched
@@ -426,12 +426,14 @@ const { data, error, execute, refresh } = await useFetch('/api/users')
426
426
  <template>
427
427
  <div>
428
428
  <p>{{ data }}</p>
429
- <button @click="() => refresh()">Refresh data</button>
429
+ <button @click="() => refresh()">
430
+ Refresh data
431
+ </button>
430
432
  </div>
431
433
  </template>
432
434
  ```
433
435
 
434
- The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](/docs/getting-started/data-fetching#not-immediate).
436
+ The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](/docs/4.x/getting-started/data-fetching#not-immediate).
435
437
 
436
438
  ::tip
437
439
  To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/4.x/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/4.x/api/utils/refresh-nuxt-data).
@@ -447,7 +449,9 @@ const { data, clear } = await useFetch('/api/users')
447
449
 
448
450
  const route = useRoute()
449
451
  watch(() => route.path, (path) => {
450
- if (path === '/') clear()
452
+ if (path === '/') {
453
+ clear()
454
+ }
451
455
  })
452
456
  </script>
453
457
  ```
@@ -462,7 +466,7 @@ const id = ref(1)
462
466
 
463
467
  const { data, error, refresh } = await useFetch('/api/users', {
464
468
  /* Changing the id will trigger a refetch */
465
- watch: [id]
469
+ watch: [id],
466
470
  })
467
471
  </script>
468
472
  ```
@@ -474,12 +478,12 @@ Note that **watching a reactive value won't change the URL fetched**. For exampl
474
478
  const id = ref(1)
475
479
 
476
480
  const { data, error, refresh } = await useFetch(`/api/users/${id.value}`, {
477
- watch: [id]
481
+ watch: [id],
478
482
  })
479
483
  </script>
480
484
  ```
481
485
 
482
- If you need to change the URL based on a reactive value, you may want to use a [computed URL](/docs/getting-started/data-fetching#computed-url) instead.
486
+ If you need to change the URL based on a reactive value, you may want to use a [computed URL](/docs/4.x/getting-started/data-fetching#computed-url) instead.
483
487
 
484
488
  When reactive fetch options are provided, they'll be automatically watched and trigger refetches. In some cases, it can be useful to opt-out of this behavior by specifying `watch: false`.
485
489
 
@@ -489,7 +493,7 @@ const id = ref(1)
489
493
  // Won't automatically refetch when id changes
490
494
  const { data, execute } = await useFetch('/api/users', {
491
495
  query: { id }, // id is watched by default
492
- watch: false, // disables automatic watching of id
496
+ watch: false, // disables automatic watching of id
493
497
  })
494
498
 
495
499
  // doesn't trigger refetch
@@ -506,31 +510,35 @@ const id = ref(null)
506
510
 
507
511
  const { data, status } = useLazyFetch('/api/user', {
508
512
  query: {
509
- user_id: id
510
- }
513
+ user_id: id,
514
+ },
511
515
  })
512
516
  </script>
513
517
  ```
514
518
 
515
519
  In the case of more complex URL construction, you may use a callback as a [computed getter](https://vuejs.org/guide/essentials/computed.html) that returns the URL string.
516
520
 
517
- Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](/docs/getting-started/data-fetching#not-immediate), and you can wait until the reactive element changes before fetching.
521
+ Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](/docs/4.x/getting-started/data-fetching#not-immediate), and you can wait until the reactive element changes before fetching.
518
522
 
519
523
  ```vue
520
524
  <script setup lang="ts">
521
525
  const id = ref(null)
522
526
 
523
527
  const { data, status } = useLazyFetch(() => `/api/users/${id.value}`, {
524
- immediate: false
528
+ immediate: false,
525
529
  })
526
530
 
527
- const pending = computed(() => status.value === 'pending');
531
+ const pending = computed(() => status.value === 'pending')
528
532
  </script>
529
533
 
530
534
  <template>
531
535
  <div>
532
536
  <!-- disable the input while fetching -->
533
- <input v-model="id" type="number" :disabled="pending"/>
537
+ <input
538
+ v-model="id"
539
+ type="number"
540
+ :disabled="pending"
541
+ >
534
542
 
535
543
  <div v-if="status === 'idle'">
536
544
  Type an user ID
@@ -547,7 +555,7 @@ const pending = computed(() => status.value === 'pending');
547
555
  </template>
548
556
  ```
549
557
 
550
- If you need to force a refresh when other reactive values change, you can also [watch other values](/docs/getting-started/data-fetching#watch).
558
+ If you need to force a refresh when other reactive values change, you can also [watch other values](/docs/4.x/getting-started/data-fetching#watch).
551
559
 
552
560
  ### Not immediate
553
561
 
@@ -558,13 +566,15 @@ With that, you will need both the `status` to handle the fetch lifecycle, and `e
558
566
  ```vue
559
567
  <script setup lang="ts">
560
568
  const { data, error, execute, status } = await useLazyFetch('/api/comments', {
561
- immediate: false
569
+ immediate: false,
562
570
  })
563
571
  </script>
564
572
 
565
573
  <template>
566
574
  <div v-if="status === 'idle'">
567
- <button @click="execute">Get data</button>
575
+ <button @click="execute">
576
+ Get data
577
+ </button>
568
578
  </div>
569
579
 
570
580
  <div v-else-if="status === 'pending'">
@@ -636,9 +646,9 @@ export default defineNuxtComponent({
636
646
  fetchKey: 'hello',
637
647
  async asyncData () {
638
648
  return {
639
- hello: await $fetch('/api/hello')
649
+ hello: await $fetch('/api/hello'),
640
650
  }
641
- }
651
+ },
642
652
  })
643
653
  </script>
644
654
  ```
@@ -647,7 +657,7 @@ export default defineNuxtComponent({
647
657
  Using `<script setup>` or `<script setup lang="ts">` are the recommended way of declaring Vue components in Nuxt.
648
658
  ::
649
659
 
650
- :read-more{to="/docs/api/utils/define-nuxt-component"}
660
+ :read-more{to="/docs/4.x/api/utils/define-nuxt-component"}
651
661
 
652
662
  ## Serializing Data From Server to Client
653
663
 
@@ -691,7 +701,7 @@ export default defineEventHandler(() => {
691
701
  const data = {
692
702
  createdAt: new Date(),
693
703
 
694
- toJSON() {
704
+ toJSON () {
695
705
  return {
696
706
  createdAt: {
697
707
  year: this.createdAt.getFullYear(),
@@ -703,7 +713,6 @@ export default defineEventHandler(() => {
703
713
  }
704
714
  return data
705
715
  })
706
-
707
716
  ```
708
717
 
709
718
  ```vue [app/app.vue]
@@ -734,9 +743,9 @@ export default defineEventHandler(() => {
734
743
  createdAt: new Date(),
735
744
 
736
745
  // Workaround the type conversion
737
- toJSON() {
746
+ toJSON () {
738
747
  return this
739
- }
748
+ },
740
749
  }
741
750
 
742
751
  // Serialize the output to string, using superjson
@@ -772,7 +781,7 @@ When consuming SSE via POST request, you need to handle the connection manually.
772
781
  const response = await $fetch<ReadableStream>('/chats/ask-ai', {
773
782
  method: 'POST',
774
783
  body: {
775
- query: "Hello AI, how are you?",
784
+ query: 'Hello AI, how are you?',
776
785
  },
777
786
  responseType: 'stream',
778
787
  })
@@ -784,8 +793,7 @@ const reader = response.pipeThrough(new TextDecoderStream()).getReader()
784
793
  while (true) {
785
794
  const { value, done } = await reader.read()
786
795
 
787
- if (done)
788
- break
796
+ if (done) { break }
789
797
 
790
798
  console.log('Received:', value)
791
799
  }
@@ -798,13 +806,13 @@ When requests don't rely on each other, you can make them in parallel with `Prom
798
806
  ```ts
799
807
  const { data } = await useAsyncData(() => {
800
808
  return Promise.all([
801
- $fetch("/api/comments/"),
802
- $fetch("/api/author/12")
803
- ]);
804
- });
809
+ $fetch('/api/comments/'),
810
+ $fetch('/api/author/12'),
811
+ ])
812
+ })
805
813
 
806
- const comments = computed(() => data.value?.[0]);
807
- const author = computed(() => data.value?.[1]);
814
+ const comments = computed(() => data.value?.[0])
815
+ const author = computed(() => data.value?.[1])
808
816
  ```
809
817
 
810
818
  :video-accordion{title="Watch a video from Vue School on parallel data fetching" videoId="1024262536" platform="vimeo"}
@@ -14,7 +14,7 @@ Nuxt provides the [`useState`](/docs/4.x/api/composables/use-state) composable t
14
14
  Because the data inside [`useState`](/docs/4.x/api/composables/use-state) will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
15
15
  ::
16
16
 
17
- ::read-more{to="/docs/api/composables/use-state"}
17
+ ::read-more{to="/docs/4.x/api/composables/use-state"}
18
18
  Read more about `useState` composable.
19
19
  ::
20
20
 
@@ -53,7 +53,7 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))
53
53
  </template>
54
54
  ```
55
55
 
56
- :link-example{to="/docs/examples/features/state-management"}
56
+ :link-example{to="/docs/4.x/examples/features/state-management"}
57
57
 
58
58
  ::note
59
59
  To globally invalidate cached state, see [`clearNuxtState`](/docs/4.x/api/utils/clear-nuxt-state) util.
@@ -77,7 +77,7 @@ await callOnce(async () => {
77
77
  This is similar to the [`nuxtServerInit` action](https://v2.nuxt.com/docs/directory-structure/store/#the-nuxtserverinit-action) in Nuxt 2, which allows filling the initial state of your store server-side before rendering the page.
78
78
  ::
79
79
 
80
- :read-more{to="/docs/api/utils/call-once"}
80
+ :read-more{to="/docs/4.x/api/utils/call-once"}
81
81
 
82
82
  ### Usage with Pinia
83
83
 
@@ -92,16 +92,16 @@ Make sure to install the Pinia module with `npx nuxt module add pinia` or follow
92
92
  export const useWebsiteStore = defineStore('websiteStore', {
93
93
  state: () => ({
94
94
  name: '',
95
- description: ''
95
+ description: '',
96
96
  }),
97
97
  actions: {
98
- async fetch() {
98
+ async fetch () {
99
99
  const infos = await $fetch('https://api.nuxt.com/modules/pinia')
100
100
 
101
101
  this.name = infos.name
102
102
  this.description = infos.description
103
- }
104
- }
103
+ },
104
+ },
105
105
  })
106
106
  ```
107
107
  ```vue [app/app.vue]
@@ -151,8 +151,8 @@ export const useLocales = () => {
151
151
  const locales = ref([
152
152
  'en-US',
153
153
  'en-GB',
154
- ...
155
- 'ja-JP-u-ca-japanese'
154
+ // ...,
155
+ 'ja-JP-u-ca-japanese',
156
156
  ])
157
157
  if (!locales.value.includes(locale.value)) {
158
158
  locales.value.unshift(locale.value)
@@ -177,8 +177,15 @@ const date = useLocaleDate(new Date('2016-10-26'))
177
177
  <h1>Nuxt birthday</h1>
178
178
  <p>{{ date }}</p>
179
179
  <label for="locale-chooser">Preview a different locale</label>
180
- <select id="locale-chooser" v-model="locale">
181
- <option v-for="loc of locales" :key="loc" :value="loc">
180
+ <select
181
+ id="locale-chooser"
182
+ v-model="locale"
183
+ >
184
+ <option
185
+ v-for="loc of locales"
186
+ :key="loc"
187
+ :value="loc"
188
+ >
182
189
  {{ loc }}
183
190
  </option>
184
191
  </select>
@@ -187,7 +194,7 @@ const date = useLocaleDate(new Date('2016-10-26'))
187
194
  ```
188
195
  ::
189
196
 
190
- :link-example{to="/docs/examples/advanced/locale"}
197
+ :link-example{to="/docs/4.x/examples/advanced/locale"}
191
198
 
192
199
  ## Shared State
193
200
 
@@ -53,7 +53,7 @@ This includes:
53
53
 
54
54
  ## Nitro Server Errors
55
55
 
56
- You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](/docs/getting-started/error-handling#error-page) section.
56
+ You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](/docs/4.x/getting-started/error-handling#error-page) section.
57
57
 
58
58
  ## Errors with JS Chunks
59
59
 
@@ -78,7 +78,7 @@ It can also occur on the client side when:
78
78
  - mounting your app if the error was not handled with `onErrorCaptured` or `vue:error` hook
79
79
  - the Vue app is initialized and mounted in browser (`app:mounted`).
80
80
 
81
- ::read-more{to="/docs/api/advanced/hooks"}
81
+ ::read-more{to="/docs/4.x/api/advanced/hooks"}
82
82
  Discover all the Nuxt lifecycle hooks.
83
83
  ::
84
84
 
@@ -91,7 +91,7 @@ Customize the default error page by adding `~/error.vue` in the source directory
91
91
  import type { NuxtError } from '#app'
92
92
 
93
93
  const props = defineProps({
94
- error: Object as () => NuxtError
94
+ error: Object as () => NuxtError,
95
95
  })
96
96
 
97
97
  const handleError = () => clearError({ redirect: '/' })
@@ -100,19 +100,21 @@ const handleError = () => clearError({ redirect: '/' })
100
100
  <template>
101
101
  <div>
102
102
  <h2>{{ error?.statusCode }}</h2>
103
- <button @click="handleError">Clear errors</button>
103
+ <button @click="handleError">
104
+ Clear errors
105
+ </button>
104
106
  </div>
105
107
  </template>
106
108
  ```
107
109
 
108
- ::read-more{to="/docs/guide/directory-structure/error"}
110
+ ::read-more{to="/docs/4.x/guide/directory-structure/error"}
109
111
  Read more about `error.vue` and its uses.
110
112
  ::
111
113
 
112
114
  For custom errors we highly recommend using `onErrorCaptured` composable that can be called in a page/component setup function or `vue:error` runtime nuxt hook that can be configured in a nuxt plugin.
113
115
 
114
116
  ```ts twoslash [plugins/error-handler.ts]
115
- export default defineNuxtPlugin(nuxtApp => {
117
+ export default defineNuxtPlugin((nuxtApp) => {
116
118
  nuxtApp.hook('vue:error', (err) => {
117
119
  //
118
120
  })
@@ -126,7 +128,7 @@ Make sure to check before using anything dependent on Nuxt plugins, such as `$ro
126
128
  ::
127
129
 
128
130
  ::note
129
- Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
131
+ Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/4.x/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
130
132
  ::
131
133
 
132
134
  ::note
@@ -143,7 +145,7 @@ function useError (): Ref<Error | { url, statusCode, statusMessage, message, des
143
145
 
144
146
  This function will return the global Nuxt error that is being handled.
145
147
 
146
- ::read-more{to="/docs/api/composables/use-error"}
148
+ ::read-more{to="/docs/4.x/api/composables/use-error"}
147
149
  Read more about `useError` composable.
148
150
  ::
149
151
 
@@ -156,7 +158,7 @@ function createError (err: string | { cause, data, message, name, stack, statusC
156
158
  Create an error object with additional metadata. You can pass a string to be set as the error `message` or an object containing error properties. It is usable in both the Vue and Server portions of your app, and is meant to be thrown.
157
159
 
158
160
  If you throw an error created with `createError`:
159
- - on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](/docs/getting-started/error-handling#clearerror).
161
+ - on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).
160
162
  - on client-side, it will throw a non-fatal error for you to handle. If you need to trigger a full-screen error page, then you can do this by setting `fatal: true`.
161
163
 
162
164
  ```vue twoslash [pages/movies/[slug\\].vue]
@@ -167,13 +169,13 @@ const { data } = await useFetch(`/api/movies/${route.params.slug}`)
167
169
  if (!data.value) {
168
170
  throw createError({
169
171
  statusCode: 404,
170
- statusMessage: 'Page Not Found'
172
+ statusMessage: 'Page Not Found',
171
173
  })
172
174
  }
173
175
  </script>
174
176
  ```
175
177
 
176
- ::read-more{to="/docs/api/utils/create-error"}
178
+ ::read-more{to="/docs/4.x/api/utils/create-error"}
177
179
  Read more about `createError` util.
178
180
  ::
179
181
 
@@ -183,11 +185,11 @@ Read more about `createError` util.
183
185
  function showError (err: string | Error | { statusCode, statusMessage }): Error
184
186
  ```
185
187
 
186
- You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/getting-started/error-handling#clearerror).
188
+ You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).
187
189
 
188
190
  It is recommended instead to use `throw createError()`.
189
191
 
190
- ::read-more{to="/docs/api/utils/show-error"}
192
+ ::read-more{to="/docs/4.x/api/utils/show-error"}
191
193
  Read more about `showError` util.
192
194
  ::
193
195
 
@@ -199,7 +201,7 @@ function clearError (options?: { redirect?: string }): Promise<void>
199
201
 
200
202
  This function will clear the currently handled Nuxt error. It also takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
201
203
 
202
- ::read-more{to="/docs/api/utils/clear-error"}
204
+ ::read-more{to="/docs/4.x/api/utils/clear-error"}
203
205
  Read more about `clearError` util.
204
206
  ::
205
207
 
@@ -230,4 +232,4 @@ If you navigate to another route, the error will be cleared automatically.
230
232
  </template>
231
233
  ```
232
234
 
233
- :link-example{to="/docs/examples/advanced/error-handling"}
235
+ :link-example{to="/docs/4.x/examples/advanced/error-handling"}
@@ -4,7 +4,7 @@ description: Build full-stack applications with Nuxt's server framework. You can
4
4
  navigation.icon: i-lucide-pc-case
5
5
  ---
6
6
 
7
- :read-more{to="/docs/guide/directory-structure/server"}
7
+ :read-more{to="/docs/4.x/guide/directory-structure/server"}
8
8
 
9
9
  ## Powered by Nitro
10
10
 
@@ -38,7 +38,7 @@ And you can directly return `text`, `json`, `html` or even a `stream`.
38
38
 
39
39
  Out-of-the-box, it supports **hot module replacement** and **auto-import** like the other parts of your Nuxt application.
40
40
 
41
- :read-more{to="/docs/guide/directory-structure/server"}
41
+ :read-more{to="/docs/4.x/guide/directory-structure/server"}
42
42
 
43
43
  ## Universal Deployment
44
44
 
@@ -59,7 +59,7 @@ Or for other runtimes:
59
59
  :card{icon="i-logos-bun" title="Bun" to="https://bun.sh" target="_blank"}
60
60
  ::
61
61
 
62
- :read-more{to="/docs/getting-started/deployment"}
62
+ :read-more{to="/docs/4.x/getting-started/deployment"}
63
63
 
64
64
  ## Hybrid Rendering
65
65
 
@@ -74,14 +74,14 @@ export default defineNuxtConfig({
74
74
  '/api/*': { cache: { maxAge: 60 * 60 } },
75
75
  // Redirection to avoid 404
76
76
  '/old-page': {
77
- redirect: { to: '/new-page', statusCode: 302 }
78
- }
77
+ redirect: { to: '/new-page', statusCode: 302 },
78
+ },
79
79
  // ...
80
- }
80
+ },
81
81
  })
82
82
  ```
83
83
 
84
- ::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering"}
84
+ ::read-more{to="/docs/4.x/guide/concepts/rendering#hybrid-rendering"}
85
85
  Learn about all available route rules are available to customize the rendering mode of your routes.
86
86
  ::
87
87
 
@@ -91,4 +91,4 @@ Some route rules (`appMiddleware`, `redirect` and `prerender`) also affect clien
91
91
 
92
92
  Nitro is used to build the app for server side rendering, as well as pre-rendering.
93
93
 
94
- :read-more{to="/docs/guide/concepts/rendering"}
94
+ :read-more{to="/docs/4.x/guide/concepts/rendering"}