@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
@@ -58,8 +58,8 @@ Possible return values are:
58
58
  * `return abortNavigation()` - stops the current navigation
59
59
  * `return abortNavigation(error)` - rejects the current navigation with an error
60
60
 
61
- :read-more{to="/docs/api/utils/navigate-to"}
62
- :read-more{to="/docs/api/utils/abort-navigation"}
61
+ :read-more{to="/docs/4.x/api/utils/navigate-to"}
62
+ :read-more{to="/docs/4.x/api/utils/abort-navigation"}
63
63
 
64
64
  ::important
65
65
  We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards) may work but there may be breaking changes in future.
@@ -90,7 +90,7 @@ definePageMeta({
90
90
  },
91
91
  'auth',
92
92
  ],
93
- });
93
+ })
94
94
  </script>
95
95
  ```
96
96
 
@@ -125,14 +125,20 @@ If your site is server-rendered or generated, middleware for the initial page wi
125
125
  However, if you want to avoid this behaviour you can do so:
126
126
 
127
127
  ```ts twoslash [middleware/example.ts]
128
- export default defineNuxtRouteMiddleware(to => {
128
+ export default defineNuxtRouteMiddleware((to) => {
129
129
  // skip middleware on server
130
- if (import.meta.server) return
130
+ if (import.meta.server) {
131
+ return
132
+ }
131
133
  // skip middleware on client side entirely
132
- if (import.meta.client) return
134
+ if (import.meta.client) {
135
+ return
136
+ }
133
137
  // or only skip middleware on initial client load
134
138
  const nuxtApp = useNuxtApp()
135
- if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) return
139
+ if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) {
140
+ return
141
+ }
136
142
  })
137
143
  ```
138
144
 
@@ -155,10 +161,10 @@ This leads to the **same issue as above**, so you should structure your function
155
161
  ::code-group
156
162
  ```ts twoslash [middleware/access-route.ts]
157
163
  // @errors: 2304
158
- export default defineNuxtRouteMiddleware(to => {
164
+ export default defineNuxtRouteMiddleware((to) => {
159
165
  // passing the route to the function to avoid calling `useRoute()` in middleware
160
166
  doSomethingWithRoute(to)
161
-
167
+
162
168
  // ❌ this will output a warning and is NOT recommended
163
169
  callsRouteInternally()
164
170
  })
@@ -166,14 +172,14 @@ export default defineNuxtRouteMiddleware(to => {
166
172
 
167
173
  ```ts twoslash [utils/handle-route.ts]
168
174
  // providing the route as an argument so that it can be used in middleware correctly
169
- export function doSomethingWithRoute(route = useRoute()) {
175
+ export function doSomethingWithRoute (route = useRoute()) {
170
176
  // ...
171
177
  }
172
178
  ```
173
179
  ```ts twoslash [utils/dont-do-this.ts]
174
180
  // ❌ this function is not suitable for use in middleware
175
- export function callsRouteInternally() {
176
- const route = useRoute()
181
+ export function callsRouteInternally () {
182
+ const route = useRoute()
177
183
  // ...
178
184
  }
179
185
  ```
@@ -208,7 +214,7 @@ In your page file, you can reference this route middleware:
208
214
  ```vue twoslash
209
215
  <script setup lang="ts">
210
216
  definePageMeta({
211
- middleware: ["auth"]
217
+ middleware: ['auth'],
212
218
  // or middleware: 'auth'
213
219
  })
214
220
  </script>
@@ -216,7 +222,7 @@ definePageMeta({
216
222
 
217
223
  Now, before navigation to that page can complete, the `auth` route middleware will be run.
218
224
 
219
- :link-example{to="/docs/examples/routing/middleware"}
225
+ :link-example{to="/docs/4.x/examples/routing/middleware"}
220
226
 
221
227
  ## Setting Middleware at Build Time
222
228
 
@@ -230,7 +236,7 @@ export default defineNuxtConfig({
230
236
  'pages:extend' (pages) {
231
237
  function setMiddleware (pages: NuxtPage[]) {
232
238
  for (const page of pages) {
233
- if (/* some condition */ true) {
239
+ if (/* some condition */ Math.random() > 0.5) {
234
240
  page.meta ||= {}
235
241
  // Note that this will override any middleware set in `definePageMeta` in the page
236
242
  page.meta.middleware = ['named']
@@ -241,7 +247,7 @@ export default defineNuxtConfig({
241
247
  }
242
248
  }
243
249
  setMiddleware(pages)
244
- }
245
- }
250
+ },
251
+ },
246
252
  })
247
253
  ```
@@ -28,17 +28,17 @@ Nuxt will automatically create a route for every page in your `~/pages/` directo
28
28
  export default defineComponent({
29
29
  render () {
30
30
  return h('h1', 'Index page')
31
- }
31
+ },
32
32
  })
33
33
  ```
34
34
 
35
35
  ```tsx twoslash [pages/index.tsx]
36
- // https://nuxt.com/docs/examples/advanced/jsx
36
+ // https://nuxt.com/docs/4.x/examples/advanced/jsx
37
37
  // https://vuejs.org/guide/extras/render-function.html#jsx-tsx
38
38
  export default defineComponent({
39
39
  render () {
40
40
  return <h1>Index page</h1>
41
- }
41
+ },
42
42
  })
43
43
  ```
44
44
 
@@ -177,10 +177,10 @@ This file tree will generate these routes:
177
177
  {
178
178
  path: 'child',
179
179
  component: '~/pages/parent/child.vue',
180
- name: 'parent-child'
181
- }
182
- ]
183
- }
180
+ name: 'parent-child',
181
+ },
182
+ ],
183
+ },
184
184
  ]
185
185
  ```
186
186
 
@@ -197,7 +197,9 @@ To display the `child.vue` component, you have to insert the `<NuxtPage>` compon
197
197
 
198
198
  ```vue {}[pages/parent/child.vue]
199
199
  <script setup lang="ts">
200
- const props = defineProps(['foobar'])
200
+ const props = defineProps({
201
+ foobar: String,
202
+ })
201
203
 
202
204
  console.log(props.foobar)
203
205
  </script>
@@ -221,12 +223,12 @@ Or alternatively:
221
223
  ```vue twoslash {}[pages/parent/child.vue]
222
224
  <script setup lang="ts">
223
225
  definePageMeta({
224
- key: route => route.fullPath
226
+ key: route => route.fullPath,
225
227
  })
226
228
  </script>
227
229
  ```
228
230
 
229
- :link-example{to="/docs/examples/routing/pages"}
231
+ :link-example{to="/docs/4.x/examples/routing/pages"}
230
232
 
231
233
  ## Route Groups
232
234
 
@@ -251,7 +253,7 @@ You might want to define metadata for each route in your app. You can do this us
251
253
  ```vue twoslash
252
254
  <script setup lang="ts">
253
255
  definePageMeta({
254
- title: 'My home page'
256
+ title: 'My home page',
255
257
  })
256
258
  </script>
257
259
  ```
@@ -279,8 +281,8 @@ Make sure not to reference any reactive data or functions that cause side effect
279
281
  <script setup lang="ts">
280
282
  import { someData } from '~/utils/example'
281
283
 
282
- function validateIdParam(route) {
283
- return route.params.id && !isNaN(Number(route.params.id))
284
+ function validateIdParam (route) {
285
+ return route.params.id && !Number.isNaN(Number(route.params.id))
284
286
  }
285
287
 
286
288
  const title = ref('')
@@ -288,7 +290,7 @@ const title = ref('')
288
290
  definePageMeta({
289
291
  validate: validateIdParam,
290
292
  someData,
291
- title, // do not do this, the ref will be hoisted out of the component
293
+ title, // do not do this, the ref will be hoisted out of the component
292
294
  })
293
295
  </script>
294
296
  ```
@@ -311,7 +313,7 @@ You can set a default value for this property [in your `nuxt.config`](/docs/4.x/
311
313
 
312
314
  #### `key`
313
315
 
314
- [See above](/docs/guide/directory-structure/app/pages#child-route-keys).
316
+ [See above](/docs/4.x/guide/directory-structure/app/pages#child-route-keys).
315
317
 
316
318
  #### `layout`
317
319
 
@@ -368,7 +370,7 @@ A simple link to the `index.vue` page in your `app/pages` folder:
368
370
  </template>
369
371
  ```
370
372
 
371
- ::read-more{to="/docs/api/components/nuxt-link"}
373
+ ::read-more{to="/docs/4.x/api/components/nuxt-link"}
372
374
  Learn more about `<NuxtLink>` usage.
373
375
  ::
374
376
 
@@ -382,16 +384,16 @@ Make sure to always `await` on `navigateTo` or chain its result by returning fro
382
384
 
383
385
  ```vue twoslash
384
386
  <script setup lang="ts">
385
- const name = ref('');
386
- const type = ref(1);
387
+ const name = ref('')
388
+ const type = ref(1)
387
389
 
388
- function navigate(){
390
+ function navigate () {
389
391
  return navigateTo({
390
392
  path: '/search',
391
393
  query: {
392
394
  name: name.value,
393
- type: type.value
394
- }
395
+ type: type.value,
396
+ },
395
397
  })
396
398
  }
397
399
  </script>
@@ -413,7 +415,7 @@ Server-only pages must have a single root element. (HTML comments are considered
413
415
 
414
416
  As your app gets bigger and more complex, your routing might require more flexibility. For this reason, Nuxt directly exposes the router, routes and router options for customization in different ways.
415
417
 
416
- :read-more{to="/docs/guide/recipes/custom-routing"}
418
+ :read-more{to="/docs/4.x/guide/recipes/custom-routing"}
417
419
 
418
420
  ## Multiple Pages Directories
419
421
 
@@ -441,4 +443,4 @@ export default defineNuxtConfig({
441
443
  })
442
444
  ```
443
445
 
444
- :read-more{to="/docs/guide/going-further/layers"}
446
+ :read-more{to="/docs/4.x/guide/going-further/layers"}
@@ -36,8 +36,8 @@ To add plugins in subdirectories, you can use the [`app/plugins`](/docs/4.x/api/
36
36
  export default defineNuxtConfig({
37
37
  plugins: [
38
38
  '~/plugins/bar/baz',
39
- '~/plugins/bar/foz'
40
- ]
39
+ '~/plugins/bar/foz',
40
+ ],
41
41
  })
42
42
  ```
43
43
 
@@ -46,7 +46,7 @@ export default defineNuxtConfig({
46
46
  The only argument passed to a plugin is [`nuxtApp`](/docs/4.x/api/composables/use-nuxt-app).
47
47
 
48
48
  ```ts twoslash [plugins/hello.ts]
49
- export default defineNuxtPlugin(nuxtApp => {
49
+ export default defineNuxtPlugin((nuxtApp) => {
50
50
  // Doing something with nuxtApp
51
51
  })
52
52
  ```
@@ -64,15 +64,15 @@ export default defineNuxtPlugin({
64
64
  },
65
65
  hooks: {
66
66
  // You can directly register Nuxt app runtime hooks here
67
- 'app:created'() {
67
+ 'app:created' () {
68
68
  const nuxtApp = useNuxtApp()
69
69
  // do something in the hook
70
- }
70
+ },
71
71
  },
72
72
  env: {
73
73
  // Set this value to `false` if you don't want the plugin to run when rendering server-only or island components.
74
- islands: true
75
- }
74
+ islands: true,
75
+ },
76
76
  })
77
77
  ```
78
78
 
@@ -114,7 +114,7 @@ export default defineNuxtPlugin({
114
114
  parallel: true,
115
115
  async setup (nuxtApp) {
116
116
  // the next plugin will be executed immediately
117
- }
117
+ },
118
118
  })
119
119
  ```
120
120
 
@@ -128,7 +128,7 @@ export default defineNuxtPlugin({
128
128
  dependsOn: ['my-plugin'],
129
129
  async setup (nuxtApp) {
130
130
  // this plugin will wait for the end of `my-plugin`'s execution before it runs
131
- }
131
+ },
132
132
  })
133
133
  ```
134
134
 
@@ -165,8 +165,8 @@ If you would like to provide a helper on the [`NuxtApp`](/docs/4.x/api/composabl
165
165
  export default defineNuxtPlugin(() => {
166
166
  return {
167
167
  provide: {
168
- hello: (msg: string) => `Hello ${msg}!`
169
- }
168
+ hello: (msg: string) => `Hello ${msg}!`,
169
+ },
170
170
  }
171
171
  })
172
172
  ```
@@ -176,10 +176,10 @@ export default defineNuxtPlugin({
176
176
  setup () {
177
177
  return {
178
178
  provide: {
179
- hello: (msg: string) => `Hello ${msg}!`
180
- }
179
+ hello: (msg: string) => `Hello ${msg}!`,
180
+ },
181
181
  }
182
- }
182
+ },
183
183
  })
184
184
  ```
185
185
  ::
@@ -267,8 +267,8 @@ import VueGtag, { trackRouter } from 'vue-gtag-next'
267
267
  export default defineNuxtPlugin((nuxtApp) => {
268
268
  nuxtApp.vueApp.use(VueGtag, {
269
269
  property: {
270
- id: 'GA_MEASUREMENT_ID'
271
- }
270
+ id: 'GA_MEASUREMENT_ID',
271
+ },
272
272
  })
273
273
  trackRouter(useRouter())
274
274
  })
@@ -287,7 +287,7 @@ export default defineNuxtPlugin((nuxtApp) => {
287
287
  getSSRProps (binding, vnode) {
288
288
  // you can provide SSR-specific props here
289
289
  return {}
290
- }
290
+ },
291
291
  })
292
292
  })
293
293
  ```
@@ -14,7 +14,7 @@ The main purpose of the [`app/utils/` directory](/docs/4.x/guide/directory-struc
14
14
  ```ts twoslash [utils/index.ts]
15
15
  export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
16
16
  notation: 'compact',
17
- maximumFractionDigits: 1
17
+ maximumFractionDigits: 1,
18
18
  })
19
19
  ```
20
20
 
@@ -35,9 +35,9 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
35
35
  </template>
36
36
  ```
37
37
 
38
- :read-more{to="/docs/guide/concepts/auto-imports"}
38
+ :read-more{to="/docs/4.x/guide/concepts/auto-imports"}
39
39
 
40
- :link-example{to="/docs/examples/features/auto-imports"}
40
+ :link-example{to="/docs/4.x/examples/features/auto-imports"}
41
41
 
42
42
  ::tip
43
43
  The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) directory.
@@ -11,7 +11,7 @@ You can easily provide runtime app configuration using `app.config.ts` file. It
11
11
 
12
12
  ```ts twoslash [app/app.config.ts]
13
13
  export default defineAppConfig({
14
- foo: 'bar'
14
+ foo: 'bar',
15
15
  })
16
16
  ```
17
17
 
@@ -30,8 +30,8 @@ To expose config and environment variables to the rest of your app, you will nee
30
30
  ```ts twoslash [app/app.config.ts]
31
31
  export default defineAppConfig({
32
32
  theme: {
33
- primaryColor: '#ababab'
34
- }
33
+ primaryColor: '#ababab',
34
+ },
35
35
  })
36
36
  ```
37
37
 
@@ -59,7 +59,7 @@ console.log(appConfig) // { foo: 'baz' }
59
59
  </script>
60
60
  ```
61
61
 
62
- ::read-more{to="/docs/api/utils/update-app-config"}
62
+ ::read-more{to="/docs/4.x/api/utils/update-app-config"}
63
63
  Read more about the `updateAppConfig` utility.
64
64
  ::
65
65
 
@@ -157,9 +157,9 @@ While it's possible to use Vite plugins in the Nitro config as a workaround, thi
157
157
  export default defineNuxtConfig({
158
158
  nitro: {
159
159
  vite: {
160
- plugins: [vue()]
161
- }
162
- }
160
+ plugins: [vue()],
161
+ },
162
+ },
163
163
  })
164
164
  ```
165
165
 
@@ -21,7 +21,7 @@ With Nuxt, the [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) dir
21
21
  </template>
22
22
  ```
23
23
 
24
- :link-example{to="/docs/examples/hello-world"}
24
+ :link-example{to="/docs/4.x/examples/hello-world"}
25
25
 
26
26
  ### Usage with Pages
27
27
 
@@ -51,7 +51,7 @@ You can also define the common structure of your application directly in `app.vu
51
51
  Remember that `app.vue` acts as the main component of your Nuxt application. Anything you add to it (JS and CSS) will be global and included in every page.
52
52
  ::
53
53
 
54
- ::read-more{to="/docs/guide/directory-structure/app/pages"}
54
+ ::read-more{to="/docs/4.x/guide/directory-structure/app/pages"}
55
55
  Learn more about how to structure your pages using the `app/pages/` directory.
56
56
  ::
57
57
 
@@ -67,6 +67,6 @@ When your application requires different layouts for different pages, you can us
67
67
  </template>
68
68
  ```
69
69
 
70
- ::read-more{to="/docs/guide/directory-structure/app/layouts"}
70
+ ::read-more{to="/docs/4.x/guide/directory-structure/app/layouts"}
71
71
  Learn more about how to structure your layouts using the `app/layouts/` directory.
72
72
  ::
@@ -12,7 +12,7 @@ During the lifespan of your application, some errors may appear unexpectedly at
12
12
  import type { NuxtError } from '#app'
13
13
 
14
14
  const props = defineProps({
15
- error: Object as () => NuxtError
15
+ error: Object as () => NuxtError,
16
16
  })
17
17
  </script>
18
18
 
@@ -32,7 +32,7 @@ The error page has a single prop - `error` which contains an error for you to ha
32
32
 
33
33
  The `error` object provides the following fields:
34
34
  ```ts
35
- {
35
+ interface NuxtError {
36
36
  statusCode: number
37
37
  fatal: boolean
38
38
  unhandled: boolean
@@ -49,7 +49,7 @@ throw createError({
49
49
  statusCode: 404,
50
50
  statusMessage: 'Page Not Found',
51
51
  data: {
52
- myCustomField: true
53
- }
52
+ myCustomField: true,
53
+ },
54
54
  })
55
55
  ```
@@ -50,7 +50,10 @@ const { data: page } = await useAsyncData(route.path, () => {
50
50
  <div>
51
51
  <header><!-- ... --></header>
52
52
 
53
- <ContentRenderer v-if="page" :value="page" />
53
+ <ContentRenderer
54
+ v-if="page"
55
+ :value="page"
56
+ />
54
57
 
55
58
  <footer><!-- ... --></footer>
56
59
  </div>
@@ -18,11 +18,11 @@ You don't need to add those local modules to your [`nuxt.config.ts`](/docs/4.x/g
18
18
  ```ts twoslash [modules/hello/index.ts]
19
19
  // `nuxt/kit` is a helper subpath import you can use when defining local modules
20
20
  // that means you do not need to add `@nuxt/kit` to your project's dependencies
21
- import { createResolver, defineNuxtModule, addServerHandler } from 'nuxt/kit'
21
+ import { addServerHandler, createResolver, defineNuxtModule } from 'nuxt/kit'
22
22
 
23
23
  export default defineNuxtModule({
24
24
  meta: {
25
- name: 'hello'
25
+ name: 'hello',
26
26
  },
27
27
  setup () {
28
28
  const resolver = createResolver(import.meta.url)
@@ -30,9 +30,9 @@ export default defineNuxtModule({
30
30
  // Add an API route
31
31
  addServerHandler({
32
32
  route: '/api/hello',
33
- handler: resolver.resolve('./runtime/api-route')
33
+ handler: resolver.resolve('./runtime/api-route'),
34
34
  })
35
- }
35
+ },
36
36
  })
37
37
  ```
38
38
 
@@ -59,7 +59,7 @@ modules/
59
59
  2.second-module.ts
60
60
  ```
61
61
 
62
- :read-more{to="/docs/guide/going-further/modules"}
62
+ :read-more{to="/docs/4.x/guide/going-further/modules"}
63
63
 
64
64
  ::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/creating-your-first-module-from-scratch?friend=nuxt" target="_blank"}
65
65
  Watch Vue School video about Nuxt private modules.
@@ -17,7 +17,7 @@ Files contained within the `public/` directory are served at the root and are no
17
17
  ```vue [app/app.vue]
18
18
  <script setup lang="ts">
19
19
  useSeoMeta({
20
- ogImage: '/og-image.png'
20
+ ogImage: '/og-image.png',
21
21
  })
22
22
  </script>
23
23
  ```
@@ -24,7 +24,7 @@ The handler can directly return JSON data, a `Promise`, or use `event.node.res.e
24
24
  ```ts twoslash [server/api/hello.ts]
25
25
  export default defineEventHandler((event) => {
26
26
  return {
27
- hello: 'world'
27
+ hello: 'world',
28
28
  }
29
29
  })
30
30
  ```
@@ -115,9 +115,9 @@ For example, you can define a custom handler utility that wraps the original han
115
115
  import type { EventHandler, EventHandlerRequest } from 'h3'
116
116
 
117
117
  export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
118
- handler: EventHandler<T, D>
118
+ handler: EventHandler<T, D>,
119
119
  ): EventHandler<T, D> =>
120
- defineEventHandler<T>(async event => {
120
+ defineEventHandler<T>(async (event) => {
121
121
  try {
122
122
  // do something before the route handler
123
123
  const response = await handler(event)
@@ -234,10 +234,10 @@ You can now universally call this API using:
234
234
 
235
235
  ```vue [app/app.vue]
236
236
  <script setup lang="ts">
237
- async function submit() {
237
+ async function submit () {
238
238
  const { body } = await $fetch('/api/submit', {
239
239
  method: 'post',
240
- body: { test: 123 }
240
+ body: { test: 123 },
241
241
  })
242
242
  }
243
243
  </script>
@@ -273,7 +273,7 @@ To return other error codes, throw an exception with [`createError`](/docs/4.x/a
273
273
 
274
274
  ```ts [server/api/validation/[id\\].ts]
275
275
  export default defineEventHandler((event) => {
276
- const id = parseInt(event.context.params.id) as number
276
+ const id = Number.parseInt(event.context.params.id) as number
277
277
 
278
278
  if (!Number.isInteger(id)) {
279
279
  throw createError({
@@ -306,8 +306,8 @@ export default defineEventHandler(async (event) => {
306
306
 
307
307
  const repo = await $fetch('https://api.github.com/repos/nuxt/nuxt', {
308
308
  headers: {
309
- Authorization: `token ${config.githubToken}`
310
- }
309
+ Authorization: `token ${config.githubToken}`,
310
+ },
311
311
  })
312
312
 
313
313
  return repo
@@ -316,8 +316,8 @@ export default defineEventHandler(async (event) => {
316
316
  ```ts [nuxt.config.ts]
317
317
  export default defineNuxtConfig({
318
318
  runtimeConfig: {
319
- githubToken: ''
320
- }
319
+ githubToken: '',
320
+ },
321
321
  })
322
322
  ```
323
323
  ```ini [.env]
@@ -363,8 +363,8 @@ The `event.waitUntil` method accepts a promise that will be awaited before the h
363
363
 
364
364
  ```ts [server/api/background-task.ts]
365
365
  const timeConsumingBackgroundTask = async () => {
366
- await new Promise((resolve) => setTimeout(resolve, 1000))
367
- };
366
+ await new Promise(resolve => setTimeout(resolve, 1000))
367
+ }
368
368
 
369
369
  export default eventHandler((event) => {
370
370
  // schedule a background task without blocking the response
@@ -372,7 +372,7 @@ export default eventHandler((event) => {
372
372
 
373
373
  // immediately send the response to the client
374
374
  return 'done'
375
- });
375
+ })
376
376
  ```
377
377
 
378
378
  ## Advanced Usage
@@ -388,11 +388,11 @@ This is an advanced option. Custom config can affect production deployments, as
388
388
  ```ts [nuxt.config.ts]
389
389
  export default defineNuxtConfig({
390
390
  // https://nitro.build/config
391
- nitro: {}
391
+ nitro: {},
392
392
  })
393
393
  ```
394
394
 
395
- :read-more{to="/docs/guide/concepts/server-engine"}
395
+ :read-more{to="/docs/4.x/guide/concepts/server-engine"}
396
396
 
397
397
  ### Nested Router
398
398
 
@@ -454,7 +454,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
454
454
 
455
455
  ### Server Storage
456
456
 
457
- Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/guide/directory-structure/server#server-plugins).
457
+ Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/4.x/guide/directory-structure/server#server-plugins).
458
458
 
459
459
  **Example of adding a Redis storage:**
460
460
 
@@ -468,14 +468,14 @@ export default defineNuxtConfig({
468
468
  driver: 'redis',
469
469
  /* redis connector options */
470
470
  port: 6379, // Redis port
471
- host: "127.0.0.1", // Redis host
472
- username: "", // needs Redis >= 6
473
- password: "",
471
+ host: '127.0.0.1', // Redis host
472
+ username: '', // needs Redis >= 6
473
+ password: '',
474
474
  db: 0, // Defaults to 0
475
- tls: {} // tls/ssl
476
- }
477
- }
478
- }
475
+ tls: {}, // tls/ssl
476
+ },
477
+ },
478
+ },
479
479
  })
480
480
  ```
481
481
 
@@ -511,11 +511,11 @@ export default defineNitroPlugin(() => {
511
511
 
512
512
  // Dynamically pass in credentials from runtime configuration, or other sources
513
513
  const driver = redisDriver({
514
- base: 'redis',
515
- host: useRuntimeConfig().redis.host,
516
- port: useRuntimeConfig().redis.port,
517
- /* other redis connector options */
518
- })
514
+ base: 'redis',
515
+ host: useRuntimeConfig().redis.host,
516
+ port: useRuntimeConfig().redis.port,
517
+ /* other redis connector options */
518
+ })
519
519
 
520
520
  // Mount driver
521
521
  storage.mount('redis', driver)
@@ -529,8 +529,8 @@ export default defineNuxtConfig({
529
529
  host: '',
530
530
  port: 0,
531
531
  /* other redis connector options */
532
- }
533
- }
532
+ },
533
+ },
534
534
  })
535
535
  ```
536
536
  ::