@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 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 (139) hide show
  1. package/1.getting-started/03.configuration.md +19 -19
  2. package/1.getting-started/04.views.md +1 -1
  3. package/1.getting-started/05.assets.md +8 -2
  4. package/1.getting-started/06.styling.md +50 -40
  5. package/1.getting-started/07.routing.md +4 -4
  6. package/1.getting-started/08.seo-meta.md +46 -33
  7. package/1.getting-started/09.transitions.md +38 -33
  8. package/1.getting-started/10.data-fetching.md +47 -39
  9. package/1.getting-started/11.state-management.md +15 -8
  10. package/1.getting-started/12.error-handling.md +6 -4
  11. package/1.getting-started/13.server.md +3 -3
  12. package/1.getting-started/14.layers.md +18 -12
  13. package/1.getting-started/15.prerendering.md +24 -24
  14. package/1.getting-started/16.deployment.md +7 -7
  15. package/1.getting-started/17.testing.md +41 -41
  16. package/1.getting-started/18.upgrade.md +48 -66
  17. package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
  18. package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
  19. package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
  20. package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
  21. package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
  22. package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
  23. package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
  24. package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
  25. package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
  26. package/2.guide/1.directory-structure/1.content.md +4 -1
  27. package/2.guide/1.directory-structure/1.modules.md +4 -4
  28. package/2.guide/1.directory-structure/1.public.md +1 -1
  29. package/2.guide/1.directory-structure/1.server.md +28 -28
  30. package/2.guide/1.directory-structure/1.shared.md +1 -1
  31. package/2.guide/2.concepts/1.auto-imports.md +11 -11
  32. package/2.guide/2.concepts/2.vuejs-development.md +5 -5
  33. package/2.guide/2.concepts/3.rendering.md +14 -12
  34. package/2.guide/2.concepts/5.modules.md +2 -2
  35. package/2.guide/2.concepts/7.esm.md +14 -12
  36. package/2.guide/2.concepts/8.typescript.md +4 -4
  37. package/2.guide/3.going-further/1.events.md +2 -2
  38. package/2.guide/3.going-further/1.experimental-features.md +234 -73
  39. package/2.guide/3.going-further/1.features.md +44 -9
  40. package/2.guide/3.going-further/1.internals.md +15 -15
  41. package/2.guide/3.going-further/10.runtime-config.md +7 -7
  42. package/2.guide/3.going-further/2.hooks.md +8 -8
  43. package/2.guide/3.going-further/3.modules.md +76 -74
  44. package/2.guide/3.going-further/4.kit.md +3 -3
  45. package/2.guide/3.going-further/6.nuxt-app.md +1 -1
  46. package/2.guide/3.going-further/7.layers.md +50 -41
  47. package/2.guide/3.going-further/9.debugging.md +2 -2
  48. package/2.guide/4.recipes/1.custom-routing.md +19 -19
  49. package/2.guide/4.recipes/2.vite-plugin.md +3 -3
  50. package/2.guide/4.recipes/3.custom-usefetch.md +9 -9
  51. package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
  52. package/2.guide/5.best-practices/performance.md +8 -8
  53. package/3.api/1.components/1.client-only.md +6 -3
  54. package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
  55. package/3.api/1.components/11.teleports.md +4 -1
  56. package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
  57. package/3.api/1.components/13.nuxt-time.md +44 -17
  58. package/3.api/1.components/2.nuxt-page.md +2 -2
  59. package/3.api/1.components/3.nuxt-layout.md +9 -4
  60. package/3.api/1.components/4.nuxt-link.md +38 -18
  61. package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
  62. package/3.api/2.composables/on-prehydrate.md +2 -2
  63. package/3.api/2.composables/use-async-data.md +11 -11
  64. package/3.api/2.composables/use-cookie.md +26 -18
  65. package/3.api/2.composables/use-error.md +1 -1
  66. package/3.api/2.composables/use-fetch.md +13 -13
  67. package/3.api/2.composables/use-head-safe.md +5 -5
  68. package/3.api/2.composables/use-head.md +2 -2
  69. package/3.api/2.composables/use-hydration.md +5 -5
  70. package/3.api/2.composables/use-loading-indicator.md +10 -10
  71. package/3.api/2.composables/use-nuxt-app.md +9 -9
  72. package/3.api/2.composables/use-nuxt-data.md +7 -7
  73. package/3.api/2.composables/use-preview-mode.md +12 -15
  74. package/3.api/2.composables/use-request-fetch.md +1 -1
  75. package/3.api/2.composables/use-request-headers.md +3 -3
  76. package/3.api/2.composables/use-response-header.md +7 -8
  77. package/3.api/2.composables/use-route-announcer.md +3 -3
  78. package/3.api/2.composables/use-router.md +5 -3
  79. package/3.api/2.composables/use-runtime-config.md +6 -6
  80. package/3.api/2.composables/use-runtime-hook.md +1 -1
  81. package/3.api/2.composables/use-seo-meta.md +1 -1
  82. package/3.api/2.composables/use-server-seo-meta.md +1 -1
  83. package/3.api/2.composables/use-state.md +3 -3
  84. package/3.api/3.utils/$fetch.md +5 -3
  85. package/3.api/3.utils/abort-navigation.md +2 -2
  86. package/3.api/3.utils/add-route-middleware.md +3 -3
  87. package/3.api/3.utils/call-once.md +3 -3
  88. package/3.api/3.utils/clear-error.md +1 -1
  89. package/3.api/3.utils/clear-nuxt-data.md +2 -2
  90. package/3.api/3.utils/clear-nuxt-state.md +2 -2
  91. package/3.api/3.utils/create-error.md +1 -1
  92. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  93. package/3.api/3.utils/define-nuxt-component.md +5 -5
  94. package/3.api/3.utils/define-nuxt-plugin.md +11 -11
  95. package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
  96. package/3.api/3.utils/define-page-meta.md +14 -14
  97. package/3.api/3.utils/define-route-rules.md +3 -3
  98. package/3.api/3.utils/navigate-to.md +9 -9
  99. package/3.api/3.utils/preload-components.md +1 -1
  100. package/3.api/3.utils/prerender-routes.md +2 -2
  101. package/3.api/3.utils/refresh-cookie.md +3 -3
  102. package/3.api/3.utils/refresh-nuxt-data.md +9 -4
  103. package/3.api/3.utils/reload-nuxt-app.md +2 -2
  104. package/3.api/3.utils/set-response-status.md +1 -1
  105. package/3.api/3.utils/show-error.md +2 -2
  106. package/3.api/3.utils/update-app-config.md +2 -1
  107. package/3.api/4.commands/prepare.md +4 -0
  108. package/3.api/5.kit/1.modules.md +36 -36
  109. package/3.api/5.kit/10.templates.md +8 -6
  110. package/3.api/5.kit/11.nitro.md +62 -62
  111. package/3.api/5.kit/12.resolving.md +2 -2
  112. package/3.api/5.kit/14.builder.md +1 -0
  113. package/3.api/5.kit/15.examples.md +2 -2
  114. package/3.api/5.kit/16.layers.md +26 -26
  115. package/3.api/5.kit/3.compatibility.md +12 -12
  116. package/3.api/5.kit/4.autoimports.md +12 -12
  117. package/3.api/5.kit/5.components.md +5 -5
  118. package/3.api/5.kit/6.context.md +3 -3
  119. package/3.api/5.kit/7.pages.md +4 -4
  120. package/3.api/5.kit/8.layout.md +1 -1
  121. package/3.api/5.kit/9.plugins.md +5 -4
  122. package/3.api/6.advanced/2.import-meta.md +3 -3
  123. package/3.api/6.nuxt-config.md +293 -858
  124. package/6.bridge/1.overview.md +1 -1
  125. package/6.bridge/10.configuration.md +2 -1
  126. package/6.bridge/2.typescript.md +2 -2
  127. package/6.bridge/3.bridge-composition-api.md +2 -2
  128. package/6.bridge/4.plugins-and-middleware.md +5 -5
  129. package/6.bridge/5.nuxt3-compatible-api.md +11 -8
  130. package/6.bridge/6.meta.md +15 -14
  131. package/6.bridge/8.nitro.md +2 -2
  132. package/6.bridge/9.vite.md +3 -3
  133. package/7.migration/2.configuration.md +17 -15
  134. package/7.migration/4.meta.md +17 -14
  135. package/7.migration/5.plugins-and-middleware.md +5 -5
  136. package/7.migration/6.pages-and-layouts.md +15 -11
  137. package/7.migration/7.component-options.md +3 -3
  138. package/7.migration/8.runtime-config.md +3 -3
  139. package/package.json +1 -1
@@ -54,7 +54,7 @@ export default defineNuxtConfig({
54
54
  pathPrefix: false, // [!code ++]
55
55
  },
56
56
  ],
57
- });
57
+ })
58
58
  ```
59
59
 
60
60
  This registers the components using the same strategy as used in Nuxt 2. For example, `~/components/Some/MyComponent.vue` will be usable as `<MyComponent>` and not `<SomeMyComponent>`.
@@ -116,7 +116,12 @@ const show = ref(false)
116
116
  <div>
117
117
  <h1>Mountains</h1>
118
118
  <LazyMountainsList v-if="show" />
119
- <button v-if="!show" @click="show = true">Show List</button>
119
+ <button
120
+ v-if="!show"
121
+ @click="show = true"
122
+ >
123
+ Show List
124
+ </button>
120
125
  </div>
121
126
  </template>
122
127
  ```
@@ -235,9 +240,10 @@ Hydrates the component based on a boolean condition.
235
240
  <LazyMyComponent :hydrate-when="isReady" />
236
241
  </div>
237
242
  </template>
243
+
238
244
  <script setup lang="ts">
239
245
  const isReady = ref(false)
240
- function myFunction() {
246
+ function myFunction () {
241
247
  // trigger custom hydration strategy...
242
248
  isReady.value = true
243
249
  }
@@ -263,13 +269,16 @@ All delayed hydration components emit a `@hydrated` event when they are hydrated
263
269
  ```vue [app/pages/index.vue]
264
270
  <template>
265
271
  <div>
266
- <LazyMyComponent hydrate-on-visible @hydrated="onHydrate" />
272
+ <LazyMyComponent
273
+ hydrate-on-visible
274
+ @hydrated="onHydrate"
275
+ />
267
276
  </div>
268
277
  </template>
269
278
 
270
279
  <script setup lang="ts">
271
- function onHydrate() {
272
- console.log("Component has been hydrated!")
280
+ function onHydrate () {
281
+ console.log('Component has been hydrated!')
273
282
  }
274
283
  </script>
275
284
  ```
@@ -297,7 +306,7 @@ You can also explicitly import components from `#components` if you want or need
297
306
 
298
307
  ```vue [app/pages/index.vue]
299
308
  <script setup lang="ts">
300
- import { NuxtLink, LazyMountainsList } from '#components'
309
+ import { LazyMountainsList, NuxtLink } from '#components'
301
310
 
302
311
  const show = ref(false)
303
312
  </script>
@@ -306,7 +315,12 @@ const show = ref(false)
306
315
  <div>
307
316
  <h1>Mountains</h1>
308
317
  <LazyMountainsList v-if="show" />
309
- <button v-if="!show" @click="show = true">Show List</button>
318
+ <button
319
+ v-if="!show"
320
+ @click="show = true"
321
+ >
322
+ Show List
323
+ </button>
310
324
  <NuxtLink to="/">Home</NuxtLink>
311
325
  </div>
312
326
  </template>
@@ -333,8 +347,8 @@ export default defineNuxtConfig({
333
347
  //
334
348
  // ~/components/Btn.vue => <Btn />
335
349
  // ~/components/base/Btn.vue => <BaseBtn />
336
- '~/components'
337
- ]
350
+ '~/components',
351
+ ],
338
352
  })
339
353
  ```
340
354
 
@@ -352,7 +366,7 @@ If you want to auto-import components from an npm package, you can use [`addComp
352
366
  import { addComponent, defineNuxtModule } from '@nuxt/kit'
353
367
 
354
368
  export default defineNuxtModule({
355
- setup() {
369
+ setup () {
356
370
  // import { MyComponent as MyAutoImportedComponent } from 'my-npm-package'
357
371
  addComponent({
358
372
  name: 'MyAutoImportedComponent',
@@ -385,8 +399,8 @@ export default defineNuxtConfig({
385
399
  {
386
400
  path: '~/components',
387
401
  extensions: ['.vue'], // [!code ++]
388
- }
389
- ]
402
+ },
403
+ ],
390
404
  })
391
405
  ```
392
406
 
@@ -443,8 +457,8 @@ Server components are currently experimental and in order to use them, you need
443
457
  ```ts twoslash [nuxt.config.ts]
444
458
  export default defineNuxtConfig({
445
459
  experimental: {
446
- componentIslands: true
447
- }
460
+ componentIslands: true,
461
+ },
448
462
  })
449
463
  ```
450
464
 
@@ -498,7 +512,10 @@ You can partially hydrate a component by setting a `nuxt-client` attribute on th
498
512
  <div>
499
513
  <HighlightedMarkdown markdown="# Headline" />
500
514
  <!-- Counter will be loaded and hydrated client-side -->
501
- <Counter nuxt-client :count="5" />
515
+ <Counter
516
+ nuxt-client
517
+ :count="5"
518
+ />
502
519
  </div>
503
520
  </template>
504
521
  ```
@@ -573,10 +590,10 @@ Imagine a directory structure like this:
573
590
  Then in `awesome-ui/nuxt.ts` you can use the `addComponentsDir` hook:
574
591
 
575
592
  ```ts twoslash
576
- import { createResolver, defineNuxtModule, addComponentsDir } from '@nuxt/kit'
593
+ import { addComponentsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
577
594
 
578
595
  export default defineNuxtModule({
579
- setup() {
596
+ setup () {
580
597
  const resolver = createResolver(import.meta.url)
581
598
 
582
599
  // Add ./components dir to the list
@@ -592,7 +609,7 @@ That's it! Now in your project, you can import your UI library as a Nuxt module
592
609
 
593
610
  ```ts twoslash [nuxt.config.ts]
594
611
  export default defineNuxtConfig({
595
- modules: ['awesome-ui/nuxt']
612
+ modules: ['awesome-ui/nuxt'],
596
613
  })
597
614
  ```
598
615
 
@@ -9,7 +9,7 @@ navigation.icon: i-vscode-icons-folder-type-src
9
9
 
10
10
  **Method 1:** Using named export
11
11
 
12
- ```js [app/composables/useFoo.ts]
12
+ ```ts [app/composables/useFoo.ts]
13
13
  export const useFoo = () => {
14
14
  return useState('foo', () => 'bar')
15
15
  }
@@ -17,7 +17,7 @@ export const useFoo = () => {
17
17
 
18
18
  **Method 2:** Using default export
19
19
 
20
- ```js [app/composables/use-foo.ts or composables/useFoo.ts]
20
+ ```ts [app/composables/use-foo.ts or composables/useFoo.ts]
21
21
  // It will be available as useFoo() (camelCase of file name without extension)
22
22
  export default function () {
23
23
  return useState('foo', () => 'bar')
@@ -62,7 +62,7 @@ If you create a composable without having the dev server running, TypeScript wil
62
62
 
63
63
  You can use a composable within another composable using auto imports:
64
64
 
65
- ```js [app/composables/test.ts]
65
+ ```ts [app/composables/test.ts]
66
66
  export const useFoo = () => {
67
67
  const nuxtApp = useNuxtApp()
68
68
  const bar = useBar()
@@ -73,7 +73,7 @@ export const useFoo = () => {
73
73
 
74
74
  You can access [plugin injections](/docs/4.x/guide/directory-structure/plugins#providing-helpers) from composables:
75
75
 
76
- ```js [app/composables/test.ts]
76
+ ```ts [app/composables/test.ts]
77
77
  export const useHello = () => {
78
78
  const nuxtApp = useNuxtApp()
79
79
  return nuxtApp.$hello
@@ -114,8 +114,8 @@ export default defineNuxtConfig({
114
114
  // ... or scan composables nested one level deep with a specific name and file extension
115
115
  '~/composables/*/index.{ts,js,mjs,mts}',
116
116
  // ... or scan all composables within given directory
117
- '~/composables/**'
118
- ]
119
- }
117
+ '~/composables/**',
118
+ ],
119
+ },
120
120
  })
121
121
  ```
@@ -69,7 +69,7 @@ Then you can use the `custom` layout in your page:
69
69
  ```vue twoslash [pages/about.vue]
70
70
  <script setup lang="ts">
71
71
  definePageMeta({
72
- layout: 'custom'
72
+ layout: 'custom',
73
73
  })
74
74
  </script>
75
75
  ```
@@ -83,7 +83,7 @@ You can directly override the default layout for all pages using the `name` prop
83
83
  ```vue [app/app.vue]
84
84
  <script setup lang="ts">
85
85
  // You might choose this based on an API call or logged-in status
86
- const layout = "custom";
86
+ const layout = 'custom'
87
87
  </script>
88
88
 
89
89
  <template>
@@ -122,12 +122,14 @@ function enableCustomLayout () {
122
122
  }
123
123
  definePageMeta({
124
124
  layout: false,
125
- });
125
+ })
126
126
  </script>
127
127
 
128
128
  <template>
129
129
  <div>
130
- <button @click="enableCustomLayout">Update layout</button>
130
+ <button @click="enableCustomLayout">
131
+ Update layout
132
+ </button>
131
133
  </div>
132
134
  </template>
133
135
  ```
@@ -150,7 +152,9 @@ definePageMeta({
150
152
  <template>
151
153
  <div>
152
154
  <NuxtLayout name="custom">
153
- <template #header> Some header template content. </template>
155
+ <template #header>
156
+ Some header template content.
157
+ </template>
154
158
 
155
159
  The rest of the page
156
160
  </NuxtLayout>
@@ -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>
@@ -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,7 +28,7 @@ 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
 
@@ -38,7 +38,7 @@ export default defineComponent({
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,7 +223,7 @@ 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
  ```
@@ -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
  ```
@@ -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>
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
  ```