@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
@@ -20,7 +20,7 @@ It automatically generates a key based on URL and fetch options, provides type h
20
20
  ```vue [app/pages/modules.vue]
21
21
  <script setup lang="ts">
22
22
  const { data, status, error, refresh, clear } = await useFetch('/api/modules', {
23
- pick: ['title']
23
+ pick: ['title'],
24
24
  })
25
25
  </script>
26
26
  ```
@@ -38,7 +38,7 @@ Using the `query` option, you can add search parameters to your query. This opti
38
38
  ```ts
39
39
  const param1 = ref('value1')
40
40
  const { data, status, error, refresh } = await useFetch('/api/modules', {
41
- query: { param1, param2: 'value2' }
41
+ query: { param1, param2: 'value2' },
42
42
  })
43
43
  ```
44
44
 
@@ -48,21 +48,21 @@ You can also use [interceptors](https://github.com/unjs/ofetch#%EF%B8%8F-interce
48
48
 
49
49
  ```ts
50
50
  const { data, status, error, refresh, clear } = await useFetch('/api/auth/login', {
51
- onRequest({ request, options }) {
51
+ onRequest ({ request, options }) {
52
52
  // Set the request headers
53
53
  // note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile
54
54
  options.headers.set('Authorization', '...')
55
55
  },
56
- onRequestError({ request, options, error }) {
56
+ onRequestError ({ request, options, error }) {
57
57
  // Handle the request errors
58
58
  },
59
- onResponse({ request, response, options }) {
59
+ onResponse ({ request, response, options }) {
60
60
  // Process the response data
61
61
  localStorage.setItem('token', response._data.token)
62
62
  },
63
- onResponseError({ request, response, options }) {
63
+ onResponseError ({ request, response, options }) {
64
64
  // Handle the response errors
65
- }
65
+ },
66
66
  })
67
67
  ```
68
68
 
@@ -96,7 +96,7 @@ If you encounter the `data` variable destructured from a `useFetch` returns a st
96
96
 
97
97
  :video-accordion{title="Watch the video from Alexander Lichter to avoid using useFetch the wrong way" videoId="njsGVmcWviY"}
98
98
 
99
- :read-more{to="/docs/getting-started/data-fetching"}
99
+ :read-more{to="/docs/4.x/getting-started/data-fetching"}
100
100
 
101
101
  ### Reactive Fetch Options
102
102
 
@@ -105,7 +105,7 @@ Fetch options can be provided as reactive, supporting `computed`, `ref` and [com
105
105
  ```ts
106
106
  const searchQuery = ref('initial')
107
107
  const { data } = await useFetch('/api/search', {
108
- query: { q: searchQuery }
108
+ query: { q: searchQuery },
109
109
  })
110
110
  // triggers a refetch: /api/search?q=new%20search
111
111
  searchQuery.value = 'new search'
@@ -117,7 +117,7 @@ If needed, you can opt out of this behavior using `watch: false`:
117
117
  const searchQuery = ref('initial')
118
118
  const { data } = await useFetch('/api/search', {
119
119
  query: { q: searchQuery },
120
- watch: false
120
+ watch: false,
121
121
  })
122
122
  // does not trigger a refetch
123
123
  searchQuery.value = 'new search'
@@ -126,7 +126,7 @@ searchQuery.value = 'new search'
126
126
  ## Type
127
127
 
128
128
  ```ts [Signature]
129
- function useFetch<DataT, ErrorT>(
129
+ export function useFetch<DataT, ErrorT> (
130
130
  url: string | Request | Ref<string | Request> | (() => string | Request),
131
131
  options?: UseFetchOptions<DataT>
132
132
  ): Promise<AsyncData<DataT, ErrorT>>
@@ -201,7 +201,7 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
201
201
  | `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
202
202
  | `deep` | `boolean` | `false` | Return data in a deep ref object. |
203
203
  | `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
204
- | `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. See [Custom useFetch in Nuxt](/docs/guide/recipes/custom-usefetch) |
204
+ | `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. See [Custom useFetch in Nuxt](/docs/4.x/guide/recipes/custom-usefetch) |
205
205
 
206
206
  ::note
207
207
  All fetch options can be given a `computed` or `ref` value. These will be watched and new requests made automatically with any new values if they are updated.
@@ -210,9 +210,9 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
210
210
  **getCachedData default:**
211
211
 
212
212
  ```ts
213
- const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
214
- ? nuxtApp.payload.data[key]
215
- : nuxtApp.static.data[key]
213
+ const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
214
+ ? nuxtApp.payload.data[key]
215
+ : nuxtApp.static.data[key]
216
216
  ```
217
217
  This only caches data when `experimental.payloadExtraction` in `nuxt.config` is enabled.
218
218
 
@@ -240,6 +240,6 @@ If you have not fetched data on the server (for example, with `server: false`),
240
240
 
241
241
  ### Examples
242
242
 
243
- :link-example{to="/docs/examples/advanced/use-custom-fetch-composable"}
243
+ :link-example{to="/docs/4.x/examples/advanced/use-custom-fetch-composable"}
244
244
 
245
- :link-example{to="/docs/examples/features/data-fetching"}
245
+ :link-example{to="/docs/4.x/examples/features/data-fetching"}
@@ -17,11 +17,11 @@ You can pass all the same values as [`useHead`](/docs/4.x/api/composables/use-he
17
17
  ```ts
18
18
  useHeadSafe({
19
19
  script: [
20
- { id: 'xss-script', innerHTML: 'alert("xss")' }
20
+ { id: 'xss-script', innerHTML: 'alert("xss")' },
21
21
  ],
22
22
  meta: [
23
- { 'http-equiv': 'refresh', content: '0;javascript:alert(1)' }
24
- ]
23
+ { 'http-equiv': 'refresh', 'content': '0;javascript:alert(1)' },
24
+ ],
25
25
  })
26
26
  // Will safely generate
27
27
  // <script id="xss-script"></script>
@@ -34,8 +34,8 @@ Read more on the `Unhead` documentation.
34
34
 
35
35
  ## Type
36
36
 
37
- ```ts
38
- useHeadSafe(input: MaybeComputedRef<HeadSafe>): void
37
+ ```ts [Signature]
38
+ export function useHeadSafe (input: MaybeComputedRef<HeadSafe>): void
39
39
  ```
40
40
 
41
41
  The list of allowed values is:
@@ -10,12 +10,12 @@ links:
10
10
 
11
11
  The [`useHead`](/docs/4.x/api/composables/use-head) composable function allows you to manage your head tags in a programmatic and reactive way, powered by [Unhead](https://unhead.unjs.io). If the data comes from a user or other untrusted source, we recommend you check out [`useHeadSafe`](/docs/4.x/api/composables/use-head-safe).
12
12
 
13
- :read-more{to="/docs/getting-started/seo-meta"}
13
+ :read-more{to="/docs/4.x/getting-started/seo-meta"}
14
14
 
15
15
  ## Type
16
16
 
17
- ```ts
18
- useHead(meta: MaybeComputedRef<MetaObject>): void
17
+ ```ts [Signature]
18
+ export function useHead (meta: MaybeComputedRef<MetaObject>): void
19
19
  ```
20
20
 
21
21
  Below are the non-reactive types for [`useHead`](/docs/4.x/api/composables/use-head) .
@@ -47,9 +47,9 @@ export default defineNuxtPlugin((nuxtApp) => {
47
47
  const myStore = new MyStore()
48
48
 
49
49
  useHydration(
50
- 'myStoreState',
51
- () => myStore.getState(),
52
- (data) => myStore.setState(data)
50
+ 'myStoreState',
51
+ () => myStore.getState(),
52
+ data => myStore.setState(data),
53
53
  )
54
54
  })
55
55
  ```
@@ -57,8 +57,8 @@ export default defineNuxtPlugin((nuxtApp) => {
57
57
 
58
58
  ## Type
59
59
 
60
- ```ts [signature]
61
- useHydration <T> (key: string, get: () => T, set: (value: T) => void) => void
60
+ ```ts [Signature]
61
+ export function useHydration<T> (key: string, get: () => T, set: (value: T) => void): void
62
62
  ```
63
63
 
64
64
  ## Parameters
@@ -16,7 +16,7 @@ By default, [`useAsyncData`](/docs/4.x/api/composables/use-async-data) blocks na
16
16
  `useLazyAsyncData` has the same signature as [`useAsyncData`](/docs/4.x/api/composables/use-async-data).
17
17
  ::
18
18
 
19
- :read-more{to="/docs/api/composables/use-async-data"}
19
+ :read-more{to="/docs/4.x/api/composables/use-async-data"}
20
20
 
21
21
  ## Example
22
22
 
@@ -44,4 +44,4 @@ watch(count, (newCount) => {
44
44
  `useLazyAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyAsyncData`.
45
45
  ::
46
46
 
47
- :read-more{to="/docs/getting-started/data-fetching"}
47
+ :read-more{to="/docs/4.x/getting-started/data-fetching"}
@@ -20,7 +20,7 @@ By default, [`useFetch`](/docs/4.x/api/composables/use-fetch) blocks navigation
20
20
  Awaiting `useLazyFetch` in this mode only ensures the call is initialized. On client-side navigation, data may not be immediately available, and you should make sure to handle the pending state in your app.
21
21
  ::
22
22
 
23
- :read-more{to="/docs/api/composables/use-fetch"}
23
+ :read-more{to="/docs/4.x/api/composables/use-fetch"}
24
24
 
25
25
  ## Example
26
26
 
@@ -52,4 +52,4 @@ watch(posts, (newPosts) => {
52
52
  `useLazyFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyFetch`.
53
53
  ::
54
54
 
55
- :read-more{to="/docs/getting-started/data-fetching"}
55
+ :read-more{to="/docs/4.x/getting-started/data-fetching"}
@@ -58,20 +58,20 @@ Used by `finish()`. Clear all timers and intervals used by the composable.
58
58
 
59
59
  ```vue
60
60
  <script setup lang="ts">
61
- const { progress, isLoading, start, finish, clear } = useLoadingIndicator({
62
- duration: 2000,
63
- throttle: 200,
64
- // This is how progress is calculated by default
65
- estimatedProgress: (duration, elapsed) => (2 / Math.PI * 100) * Math.atan(elapsed / duration * 100 / 50)
66
- })
61
+ const { progress, isLoading, start, finish, clear } = useLoadingIndicator({
62
+ duration: 2000,
63
+ throttle: 200,
64
+ // This is how progress is calculated by default
65
+ estimatedProgress: (duration, elapsed) => (2 / Math.PI * 100) * Math.atan(elapsed / duration * 100 / 50),
66
+ })
67
67
  </script>
68
68
  ```
69
69
 
70
70
  ```vue
71
71
  <script setup lang="ts">
72
- const { start, set } = useLoadingIndicator()
73
- // same as set(0, { force: true })
74
- // set the progress to 0, and show loading immediately
75
- start({ force: true })
72
+ const { start, set } = useLoadingIndicator()
73
+ // same as set(0, { force: true })
74
+ // set the progress to 0, and show loading immediately
75
+ start({ force: true })
76
76
  </script>
77
77
  ```
@@ -34,9 +34,9 @@ By default, the shared runtime context of Nuxt is namespaced under the [`buildId
34
34
 
35
35
  `provide` function accepts `name` and `value` parameters.
36
36
 
37
- ```js
37
+ ```ts
38
38
  const nuxtApp = useNuxtApp()
39
- nuxtApp.provide('hello', (name) => `Hello ${name}!`)
39
+ nuxtApp.provide('hello', name => `Hello ${name}!`)
40
40
 
41
41
  // Prints "Hello name!"
42
42
  console.log(nuxtApp.$hello('name'))
@@ -112,7 +112,7 @@ Nuxt exposes the following properties through `ssrContext`:
112
112
  </script>
113
113
  ```
114
114
  ```ts [server/api/count.ts]
115
- export default defineEventHandler(event => {
115
+ export default defineEventHandler((event) => {
116
116
  return { count: 1 }
117
117
  })
118
118
  ```
@@ -173,7 +173,7 @@ export default defineComponent({
173
173
  // ...
174
174
  }
175
175
  })
176
- }
176
+ },
177
177
  })
178
178
  ```
179
179
 
@@ -204,7 +204,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
204
204
 
205
205
  #### Usage
206
206
 
207
- ```js
207
+ ```ts
208
208
  const result = nuxtApp.runWithContext(() => functionWithContext())
209
209
  ```
210
210
 
@@ -218,14 +218,14 @@ Vue.js Composition API (and Nuxt composables similarly) work by depending on an
218
218
 
219
219
  What it does mean? The Composition API and Nuxt Composables are only available during lifecycle and in same tick before any async operation:
220
220
 
221
- ```js
221
+ ```ts
222
222
  // --- Vue internal ---
223
223
  const _vueInstance = null
224
224
  const getCurrentInstance = () => _vueInstance
225
225
  // ---
226
226
 
227
227
  // Vue / Nuxt sets a global variable referencing to current component in _vueInstance when calling setup()
228
- async function setup() {
228
+ async function setup () {
229
229
  getCurrentInstance() // Works
230
230
  await someAsyncOperation() // Vue unsets the context in same tick before async operation!
231
231
  getCurrentInstance() // null
@@ -236,7 +236,7 @@ The classic solution to this, is caching the current instance on first call to a
236
236
 
237
237
  To overcome this limitation, Vue does some behind the scenes work when compiling our application code and restores context after each call for `<script setup>`:
238
238
 
239
- ```js
239
+ ```ts
240
240
  const __instance = getCurrentInstance() // Generated by Vue compiler
241
241
  getCurrentInstance() // Works!
242
242
  await someAsyncOperation() // Vue unsets the context
@@ -268,7 +268,7 @@ Using a new experimental feature, it is possible to enable native async context
268
268
  Native async context support works currently in Bun and Node.
269
269
  ::
270
270
 
271
- :read-more{to="/docs/guide/going-further/experimental-features#asynccontext"}
271
+ :read-more{to="/docs/4.x/guide/going-further/experimental-features#asynccontext"}
272
272
 
273
273
  ## tryUseNuxtApp
274
274
 
@@ -279,7 +279,7 @@ You can use it for composables that do not require `nuxtApp`, or to simply check
279
279
  Example usage:
280
280
 
281
281
  ```ts [composable.ts]
282
- export function useStandType() {
282
+ export function useStandType () {
283
283
  // Always works on the client
284
284
  if (tryUseNuxtApp()) {
285
285
  return useRuntimeConfig().public.STAND_TYPE
@@ -50,10 +50,10 @@ const route = useRoute()
50
50
 
51
51
  const { data } = useLazyFetch(`/api/posts/${route.params.id}`, {
52
52
  key: `post-${route.params.id}`,
53
- default() {
53
+ default () {
54
54
  // Find the individual post from the cache and set it as the default value.
55
55
  return posts.value.find(post => post.id === route.params.id)
56
- }
56
+ },
57
57
  })
58
58
  </script>
59
59
  ```
@@ -80,10 +80,10 @@ let previousTodos = []
80
80
  const { data: todos } = useNuxtData('todos')
81
81
 
82
82
  async function addTodo () {
83
- return $fetch('/api/addTodo', {
83
+ await $fetch('/api/addTodo', {
84
84
  method: 'post',
85
85
  body: {
86
- todo: newTodo.value
86
+ todo: newTodo.value,
87
87
  },
88
88
  onRequest () {
89
89
  // Store the previously cached value to restore if fetch fails.
@@ -99,7 +99,7 @@ async function addTodo () {
99
99
  async onResponse () {
100
100
  // Invalidate todos in the background if the request succeeded.
101
101
  await refreshNuxtData('todos')
102
- }
102
+ },
103
103
  })
104
104
  }
105
105
  </script>
@@ -107,6 +107,6 @@ async function addTodo () {
107
107
 
108
108
  ## Type
109
109
 
110
- ```ts
111
- useNuxtData<DataT = any> (key: string): { data: Ref<DataT | undefined> }
110
+ ```ts [Signature]
111
+ export function useNuxtData<DataT = any> (key: string): { data: Ref<DataT | undefined> }
112
112
  ```
@@ -14,7 +14,7 @@ Preview mode allows you to see how your changes would be displayed on a live sit
14
14
 
15
15
  You can use the built-in `usePreviewMode` composable to access and control preview state in Nuxt. If the composable detects preview mode it will automatically force any updates necessary for [`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`useFetch`](/docs/4.x/api/composables/use-fetch) to rerender preview content.
16
16
 
17
- ```js
17
+ ```ts
18
18
  const { enabled, state } = usePreviewMode()
19
19
  ```
20
20
 
@@ -24,13 +24,14 @@ const { enabled, state } = usePreviewMode()
24
24
 
25
25
  You can specify a custom way to enable preview mode. By default the `usePreviewMode` composable will enable preview mode if there is a `preview` param in url that is equal to `true` (for example, `http://localhost:3000?preview=true`). You can wrap the `usePreviewMode` into custom composable, to keep options consistent across usages and prevent any errors.
26
26
 
27
- ```js
27
+ ```ts
28
28
  export function useMyPreviewMode () {
29
+ const route = useRoute()
29
30
  return usePreviewMode({
30
31
  shouldEnable: () => {
31
32
  return !!route.query.customPreview
32
- }
33
- });
33
+ },
34
+ })
34
35
  }
35
36
  ```
36
37
 
@@ -38,13 +39,13 @@ export function useMyPreviewMode () {
38
39
 
39
40
  `usePreviewMode` will try to store the value of a `token` param from url in state. You can modify this state and it will be available for all [`usePreviewMode`](/docs/4.x/api/composables/use-preview-mode) calls.
40
41
 
41
- ```js
42
+ ```ts
42
43
  const data1 = ref('data1')
43
44
 
44
45
  const { enabled, state } = usePreviewMode({
45
46
  getState: (currentState) => {
46
47
  return { data1, data2: 'data2' }
47
- }
48
+ },
48
49
  })
49
50
  ```
50
51
 
@@ -60,14 +61,14 @@ When preview mode is disabled, the composable will attach a callback to call `re
60
61
 
61
62
  You can specify custom callbacks to be triggered by providing your own functions for the `onEnable` and `onDisable` options.
62
63
 
63
- ```js
64
+ ```ts
64
65
  const { enabled, state } = usePreviewMode({
65
66
  onEnable: () => {
66
67
  console.log('preview mode has been enabled')
67
68
  },
68
69
  onDisable: () => {
69
70
  console.log('preview mode has been disabled')
70
- }
71
+ },
71
72
  })
72
73
  ```
73
74
 
@@ -81,8 +82,8 @@ const { enabled, state } = usePreviewMode()
81
82
 
82
83
  const { data } = await useFetch('/api/preview', {
83
84
  query: {
84
- apiKey: state.token
85
- }
85
+ apiKey: state.token,
86
+ },
86
87
  })
87
88
  </script>
88
89
 
@@ -107,11 +108,7 @@ npx nuxt generate
107
108
  npx nuxt preview
108
109
  ```
109
110
 
110
- Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once:
111
-
112
- ```js
113
- ?preview=true
114
- ```
111
+ Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once, for example `http://localhost:3000/?preview=true`.
115
112
 
116
113
  ::note
117
114
  `usePreviewMode` should be tested locally with `nuxt generate` and then `nuxt preview` rather than `nuxt dev`. (The [preview command](/docs/4.x/api/commands/preview) is not related to preview mode.)
@@ -33,7 +33,7 @@ const { data: forwarded } = await useAsyncData(() => requestFetch('/api/cookies'
33
33
 
34
34
  // This will NOT forward anything
35
35
  // Result: { cookies: {} }
36
- const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
36
+ const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
37
37
  </script>
38
38
  ```
39
39
 
@@ -10,12 +10,12 @@ links:
10
10
 
11
11
  You can use built-in [`useRequestHeaders`](/docs/4.x/api/composables/use-request-headers) composable to access the incoming request headers within your pages, components, and plugins.
12
12
 
13
- ```js
13
+ ```ts
14
14
  // Get all request headers
15
15
  const headers = useRequestHeaders()
16
16
 
17
17
  // Get only cookie request header
18
- const headers = useRequestHeaders(['cookie'])
18
+ const { cookie } = useRequestHeaders(['cookie'])
19
19
  ```
20
20
 
21
21
  ::tip
@@ -31,7 +31,7 @@ The example below adds the `authorization` request header to an isomorphic `$fet
31
31
  ```vue [app/pages/some-page.vue]
32
32
  <script setup lang="ts">
33
33
  const { data } = await useFetch('/api/confidential', {
34
- headers: useRequestHeaders(['authorization'])
34
+ headers: useRequestHeaders(['authorization']),
35
35
  })
36
36
  </script>
37
37
  ```
@@ -16,8 +16,8 @@ You can use the built-in [`useResponseHeader`](/docs/4.x/api/composables/use-res
16
16
 
17
17
  ```ts
18
18
  // Set a custom response header
19
- const header = useResponseHeader('X-My-Header');
20
- header.value = 'my-value';
19
+ const header = useResponseHeader('X-My-Header')
20
+ header.value = 'my-value'
21
21
  ```
22
22
 
23
23
  ## Example
@@ -27,8 +27,8 @@ We can use `useResponseHeader` to easily set a response header on a per-page bas
27
27
  ```vue [app/pages/test.vue]
28
28
  <script setup>
29
29
  // pages/test.vue
30
- const header = useResponseHeader('X-My-Header');
31
- header.value = 'my-value';
30
+ const header = useResponseHeader('X-My-Header')
31
+ header.value = 'my-value'
32
32
  </script>
33
33
 
34
34
  <template>
@@ -41,8 +41,7 @@ We can use `useResponseHeader` for example in Nuxt [middleware](/docs/4.x/guide/
41
41
 
42
42
  ```ts [app/middleware/my-header-middleware.ts]
43
43
  export default defineNuxtRouteMiddleware((to, from) => {
44
- const header = useResponseHeader('X-My-Always-Header');
45
- header.value = `I'm Always here!`;
46
- });
47
-
44
+ const header = useResponseHeader('X-My-Always-Header')
45
+ header.value = `I'm Always here!`
46
+ })
48
47
  ```
@@ -53,8 +53,8 @@ Sets the message with `politeness = "assertive"`
53
53
 
54
54
  ```vue [app/pages/index.vue]
55
55
  <script setup lang="ts">
56
- const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
57
- politeness: 'assertive'
58
- })
56
+ const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
57
+ politeness: 'assertive',
58
+ })
59
59
  </script>
60
60
  ```
@@ -18,7 +18,9 @@ If you only need the router instance within your template, use `$router`:
18
18
 
19
19
  ```vue [app/pages/index.vue]
20
20
  <template>
21
- <button @click="$router.back()">Back</button>
21
+ <button @click="$router.back()">
22
+ Back
23
+ </button>
22
24
  </template>
23
25
  ```
24
26
 
@@ -64,8 +66,8 @@ const router = useRouter()
64
66
  router.back()
65
67
  router.forward()
66
68
  router.go(3)
67
- router.push({ path: "/home" })
68
- router.replace({ hash: "#bio" })
69
+ router.push({ path: '/home' })
70
+ router.replace({ hash: '#bio' })
69
71
  ```
70
72
 
71
73
  ::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/History" target="_blank"}
@@ -78,7 +80,7 @@ Read more about the browser's History API.
78
80
 
79
81
  However, Nuxt has a concept of **route middleware** that simplifies the implementation of navigation guards and provides a better developer experience.
80
82
 
81
- :read-more{to="/docs/guide/directory-structure/app/middleware"}
83
+ :read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
82
84
 
83
85
  ## Promise and Error Handling
84
86
 
@@ -22,7 +22,7 @@ export default defineEventHandler((event) => {
22
22
  })
23
23
  ```
24
24
 
25
- :read-more{to="/docs/guide/going-further/runtime-config"}
25
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
26
26
 
27
27
  ## Define Runtime Config
28
28
 
@@ -38,9 +38,9 @@ export default defineNuxtConfig({
38
38
 
39
39
  // Public keys that are exposed to the client
40
40
  public: {
41
- apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api'
42
- }
43
- }
41
+ apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api',
42
+ },
43
+ },
44
44
  })
45
45
  ```
46
46
 
@@ -48,7 +48,7 @@ export default defineNuxtConfig({
48
48
  Variables that need to be accessible on the server are added directly inside `runtimeConfig`. Variables that need to be accessible on both the client and the server are defined in `runtimeConfig.public`.
49
49
  ::
50
50
 
51
- :read-more{to="/docs/guide/going-further/runtime-config"}
51
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
52
52
 
53
53
  ## Access Runtime Config
54
54
 
@@ -63,11 +63,11 @@ export default defineEventHandler(async (event) => {
63
63
  baseURL: config.public.apiBase,
64
64
  headers: {
65
65
  // Access a private variable (only available on the server)
66
- Authorization: `Bearer ${config.apiSecret}`
67
- }
66
+ Authorization: `Bearer ${config.apiSecret}`,
67
+ },
68
68
  })
69
69
  return result
70
- }
70
+ })
71
71
  ```
72
72
 
73
73
  In this example, since `apiBase` is defined within the `public` namespace, it is universally accessible on both server and client-side, while `apiSecret` **is only accessible on the server-side**.
@@ -76,7 +76,7 @@ In this example, since `apiBase` is defined within the `public` namespace, it is
76
76
 
77
77
  It is possible to update runtime config values using a matching environment variable name prefixed with `NUXT_`.
78
78
 
79
- :read-more{to="/docs/guide/going-further/runtime-config"}
79
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
80
80
 
81
81
  ### Using the `.env` File
82
82
 
@@ -95,7 +95,7 @@ Any environment variables set within `.env` file are accessed using `process.env
95
95
  In **production runtime**, you should use platform environment variables and `.env` is not used.
96
96
  ::
97
97
 
98
- :read-more{to="/docs/guide/directory-structure/env"}
98
+ :read-more{to="/docs/4.x/guide/directory-structure/env"}
99
99
 
100
100
  ## `app` namespace
101
101
 
@@ -139,4 +139,4 @@ export default defineEventHandler((event) => {
139
139
  })
140
140
  ```
141
141
 
142
- :read-more{to="/docs/guide/going-further/runtime-config"}
142
+ :read-more{to="/docs/4.x/guide/going-further/runtime-config"}
@@ -13,7 +13,7 @@ This composable is available in Nuxt v3.14+.
13
13
  ::
14
14
 
15
15
  ```ts [signature]
16
- function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(
16
+ function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> (
17
17
  name: THookName,
18
18
  fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never
19
19
  ): void
@@ -14,7 +14,7 @@ This helps you avoid common mistakes, such as using `name` instead of `property`
14
14
  This is the recommended way to add meta tags to your site as it is XSS safe and has full TypeScript support.
15
15
  ::
16
16
 
17
- :read-more{to="/docs/getting-started/seo-meta"}
17
+ :read-more{to="/docs/4.x/getting-started/seo-meta"}
18
18
 
19
19
  ## Usage
20
20
 
@@ -39,7 +39,7 @@ const title = ref('My title')
39
39
 
40
40
  useSeoMeta({
41
41
  title,
42
- description: () => `This is a description for the ${title.value} page`
42
+ description: () => `This is a description for the ${title.value} page`,
43
43
  })
44
44
  </script>
45
45
  ```
@@ -48,7 +48,7 @@ useSeoMeta({
48
48
 
49
49
  There are over 100 parameters. See the [full list of parameters in the source code](https://github.com/harlan-zw/zhead/blob/main/packages/zhead/src/metaFlat.ts#L1035).
50
50
 
51
- :read-more{to="/docs/getting-started/seo-meta"}
51
+ :read-more{to="/docs/4.x/getting-started/seo-meta"}
52
52
 
53
53
  ## Performance
54
54