@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e

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 (214) hide show
  1. package/1.getting-started/01.introduction.md +8 -8
  2. package/1.getting-started/02.installation.md +2 -4
  3. package/1.getting-started/03.configuration.md +16 -16
  4. package/1.getting-started/04.views.md +8 -8
  5. package/1.getting-started/05.assets.md +10 -10
  6. package/1.getting-started/06.styling.md +10 -10
  7. package/1.getting-started/07.routing.md +15 -15
  8. package/1.getting-started/08.seo-meta.md +15 -15
  9. package/1.getting-started/09.transitions.md +10 -10
  10. package/1.getting-started/10.data-fetching.md +61 -47
  11. package/1.getting-started/11.state-management.md +11 -11
  12. package/1.getting-started/12.error-handling.md +20 -18
  13. package/1.getting-started/13.server.md +7 -7
  14. package/1.getting-started/14.layers.md +6 -6
  15. package/1.getting-started/15.prerendering.md +22 -28
  16. package/1.getting-started/16.deployment.md +22 -6
  17. package/1.getting-started/17.testing.md +200 -21
  18. package/1.getting-started/18.upgrade.md +78 -278
  19. package/2.directory-structure/0.nuxt.md +2 -2
  20. package/2.directory-structure/0.output.md +3 -3
  21. package/2.directory-structure/1.app/1.assets.md +3 -3
  22. package/2.directory-structure/1.app/1.components.md +26 -109
  23. package/2.directory-structure/1.app/1.composables.md +5 -5
  24. package/2.directory-structure/1.app/1.layouts.md +10 -10
  25. package/2.directory-structure/1.app/1.middleware.md +14 -10
  26. package/2.directory-structure/1.app/1.pages.md +25 -20
  27. package/2.directory-structure/1.app/1.plugins.md +7 -7
  28. package/2.directory-structure/1.app/1.utils.md +9 -5
  29. package/2.directory-structure/1.app/3.app-config.md +7 -7
  30. package/2.directory-structure/1.app/3.app.md +6 -6
  31. package/2.directory-structure/1.app/3.error.md +1 -1
  32. package/2.directory-structure/1.content.md +1 -1
  33. package/2.directory-structure/1.layers.md +13 -13
  34. package/2.directory-structure/1.modules.md +3 -3
  35. package/2.directory-structure/1.node_modules.md +1 -1
  36. package/2.directory-structure/1.server.md +33 -14
  37. package/2.directory-structure/1.shared.md +7 -5
  38. package/2.directory-structure/1.test.md +25 -0
  39. package/2.directory-structure/2.env.md +7 -7
  40. package/2.directory-structure/2.nuxtignore.md +3 -3
  41. package/2.directory-structure/2.nuxtrc.md +3 -3
  42. package/2.directory-structure/3.nuxt-config.md +2 -2
  43. package/2.directory-structure/3.tsconfig.md +21 -11
  44. package/2.directory-structure/index.md +29 -25
  45. package/3.guide/0.index.md +6 -6
  46. package/3.guide/1.concepts/1.rendering.md +76 -12
  47. package/3.guide/1.concepts/10.vuejs-development.md +73 -8
  48. package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
  49. package/3.guide/1.concepts/3.auto-imports.md +11 -11
  50. package/3.guide/1.concepts/4.server-engine.md +6 -6
  51. package/3.guide/1.concepts/5.modules.md +4 -4
  52. package/3.guide/1.concepts/6.server-components.md +198 -0
  53. package/3.guide/1.concepts/7.esm.md +5 -5
  54. package/3.guide/1.concepts/8.typescript.md +9 -9
  55. package/3.guide/2.best-practices/accessibility.md +155 -0
  56. package/3.guide/2.best-practices/hydration.md +5 -5
  57. package/3.guide/2.best-practices/performance.md +13 -9
  58. package/3.guide/3.ai/1.mcp.md +104 -19
  59. package/3.guide/4.modules/2.module-anatomy.md +5 -5
  60. package/3.guide/4.modules/3.recipes-basics.md +8 -8
  61. package/3.guide/4.modules/4.module-dependencies.md +1 -1
  62. package/3.guide/4.modules/5.recipes-advanced.md +6 -8
  63. package/3.guide/4.modules/6.testing.md +2 -2
  64. package/3.guide/4.modules/7.best-practices.md +2 -2
  65. package/3.guide/4.modules/9.server-compatibility.md +215 -0
  66. package/3.guide/4.modules/index.md +9 -9
  67. package/3.guide/5.recipes/1.custom-routing.md +15 -11
  68. package/3.guide/5.recipes/2.vite-plugin.md +3 -3
  69. package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
  70. package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
  71. package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
  72. package/3.guide/6.going-further/1.events.md +1 -1
  73. package/3.guide/6.going-further/1.experimental-features.md +254 -22
  74. package/3.guide/6.going-further/1.features.md +42 -6
  75. package/3.guide/6.going-further/1.internals.md +10 -10
  76. package/3.guide/6.going-further/10.runtime-config.md +28 -6
  77. package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
  78. package/3.guide/6.going-further/2.hooks.md +6 -6
  79. package/3.guide/6.going-further/4.kit.md +4 -4
  80. package/3.guide/6.going-further/5.server-imports.md +221 -0
  81. package/3.guide/6.going-further/6.nuxt-app.md +7 -7
  82. package/3.guide/6.going-further/7.layers.md +13 -13
  83. package/3.guide/6.going-further/8.builders.md +38 -14
  84. package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
  85. package/4.api/1.components/10.nuxt-picture.md +1 -1
  86. package/4.api/1.components/11.teleports.md +1 -1
  87. package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
  88. package/4.api/1.components/14.nuxt-announcer.md +3 -3
  89. package/4.api/1.components/2.nuxt-page.md +5 -5
  90. package/4.api/1.components/3.nuxt-layout.md +8 -8
  91. package/4.api/1.components/4.nuxt-link.md +6 -4
  92. package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
  93. package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
  94. package/4.api/1.components/8.nuxt-island.md +5 -5
  95. package/4.api/2.composables/create-use-async-data.md +51 -8
  96. package/4.api/2.composables/create-use-fetch.md +126 -9
  97. package/4.api/2.composables/use-announcer.md +3 -3
  98. package/4.api/2.composables/use-app-config.md +1 -1
  99. package/4.api/2.composables/use-async-data.md +19 -11
  100. package/4.api/2.composables/use-cookie.md +22 -6
  101. package/4.api/2.composables/use-error.md +1 -1
  102. package/4.api/2.composables/use-fetch.md +14 -10
  103. package/4.api/2.composables/use-head-safe.md +2 -2
  104. package/4.api/2.composables/use-head.md +2 -2
  105. package/4.api/2.composables/use-hydration.md +1 -1
  106. package/4.api/2.composables/use-layout.md +1 -1
  107. package/4.api/2.composables/use-lazy-async-data.md +8 -8
  108. package/4.api/2.composables/use-lazy-fetch.md +11 -11
  109. package/4.api/2.composables/use-loading-indicator.md +2 -2
  110. package/4.api/2.composables/use-nuxt-app.md +13 -13
  111. package/4.api/2.composables/use-nuxt-data.md +1 -1
  112. package/4.api/2.composables/use-preview-mode.md +3 -3
  113. package/4.api/2.composables/use-request-event.md +29 -3
  114. package/4.api/2.composables/use-request-fetch.md +2 -2
  115. package/4.api/2.composables/use-request-header.md +1 -1
  116. package/4.api/2.composables/use-request-headers.md +1 -1
  117. package/4.api/2.composables/use-request-url.md +1 -1
  118. package/4.api/2.composables/use-response-header.md +2 -2
  119. package/4.api/2.composables/use-route-announcer.md +4 -2
  120. package/4.api/2.composables/use-route.md +2 -2
  121. package/4.api/2.composables/use-router.md +5 -5
  122. package/4.api/2.composables/use-runtime-config.md +5 -5
  123. package/4.api/2.composables/use-runtime-hook.md +1 -1
  124. package/4.api/2.composables/use-seo-meta.md +3 -3
  125. package/4.api/2.composables/use-server-seo-meta.md +5 -5
  126. package/4.api/2.composables/use-state.md +4 -4
  127. package/4.api/3.utils/$fetch.md +5 -5
  128. package/4.api/3.utils/abort-navigation.md +1 -1
  129. package/4.api/3.utils/add-route-middleware.md +2 -2
  130. package/4.api/3.utils/call-once.md +3 -3
  131. package/4.api/3.utils/clear-error.md +2 -2
  132. package/4.api/3.utils/clear-nuxt-data.md +1 -1
  133. package/4.api/3.utils/clear-nuxt-state.md +2 -2
  134. package/4.api/3.utils/create-error.md +19 -1
  135. package/4.api/3.utils/define-nuxt-plugin.md +2 -2
  136. package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
  137. package/4.api/3.utils/define-page-meta.md +12 -12
  138. package/4.api/3.utils/define-route-rules.md +4 -4
  139. package/4.api/3.utils/define-use-async-data-addon.md +57 -0
  140. package/4.api/3.utils/define-use-fetch-addon.md +168 -0
  141. package/4.api/3.utils/navigate-to.md +6 -2
  142. package/4.api/3.utils/prefetch-components.md +1 -1
  143. package/4.api/3.utils/preload-route-components.md +2 -2
  144. package/4.api/3.utils/prerender-routes.md +3 -3
  145. package/4.api/3.utils/refresh-cookie.md +1 -1
  146. package/4.api/3.utils/refresh-nuxt-data.md +3 -3
  147. package/4.api/3.utils/reload-nuxt-app.md +1 -1
  148. package/4.api/3.utils/set-page-layout.md +1 -1
  149. package/4.api/3.utils/set-response-status.md +2 -2
  150. package/4.api/3.utils/show-error.md +3 -3
  151. package/4.api/3.utils/update-app-config.md +2 -2
  152. package/4.api/4.commands/README.md +9 -0
  153. package/4.api/5.kit/1.modules.md +3 -3
  154. package/4.api/5.kit/10.runtime-config.md +1 -1
  155. package/4.api/5.kit/10.templates.md +42 -0
  156. package/4.api/5.kit/12.nitro.md +59 -18
  157. package/4.api/5.kit/14.logging.md +56 -2
  158. package/4.api/5.kit/15.builder.md +1 -1
  159. package/4.api/5.kit/18.dependencies.md +90 -0
  160. package/4.api/5.kit/2.programmatic.md +78 -1
  161. package/4.api/5.kit/3.compatibility.md +2 -2
  162. package/4.api/5.kit/4.autoimports.md +13 -13
  163. package/4.api/5.kit/5.components.md +3 -3
  164. package/4.api/5.kit/6.context.md +2 -2
  165. package/4.api/5.kit/7.pages.md +35 -4
  166. package/4.api/5.kit/8.layout.md +1 -1
  167. package/4.api/6.advanced/1.hooks.md +6 -3
  168. package/4.api/6.nuxt-config.md +44 -21
  169. package/4.api/index.md +7 -7
  170. package/5.community/2.getting-help.md +1 -1
  171. package/5.community/3.reporting-bugs.md +1 -1
  172. package/5.community/4.contribution.md +14 -12
  173. package/5.community/5.framework-contribution.md +4 -4
  174. package/5.community/6.roadmap.md +6 -6
  175. package/6.bridge/1.overview.md +12 -12
  176. package/6.bridge/2.typescript.md +1 -1
  177. package/6.bridge/3.bridge-composition-api.md +6 -6
  178. package/6.bridge/4.plugins-and-middleware.md +4 -4
  179. package/6.bridge/5.nuxt3-compatible-api.md +9 -9
  180. package/6.bridge/6.meta.md +5 -5
  181. package/6.bridge/7.runtime-config.md +1 -1
  182. package/6.bridge/8.nitro.md +1 -1
  183. package/6.bridge/9.vite.md +1 -1
  184. package/7.migration/1.overview.md +2 -2
  185. package/7.migration/10.bundling.md +1 -1
  186. package/7.migration/11.server.md +3 -3
  187. package/7.migration/2.configuration.md +6 -6
  188. package/7.migration/20.module-authors.md +7 -7
  189. package/7.migration/3.auto-imports.md +3 -3
  190. package/7.migration/4.meta.md +4 -4
  191. package/7.migration/5.plugins-and-middleware.md +3 -3
  192. package/7.migration/6.pages-and-layouts.md +13 -13
  193. package/7.migration/7.component-options.md +15 -15
  194. package/7.migration/8.runtime-config.md +4 -4
  195. package/README.md +1 -1
  196. package/errors/e8007.md +28 -0
  197. package/package.json +2 -2
  198. package/4.api/4.commands/.navigation.yml +0 -3
  199. package/4.api/4.commands/add.md +0 -112
  200. package/4.api/4.commands/analyze.md +0 -42
  201. package/4.api/4.commands/build-module.md +0 -42
  202. package/4.api/4.commands/build.md +0 -48
  203. package/4.api/4.commands/cleanup.md +0 -38
  204. package/4.api/4.commands/dev.md +0 -61
  205. package/4.api/4.commands/devtools.md +0 -38
  206. package/4.api/4.commands/generate.md +0 -43
  207. package/4.api/4.commands/info.md +0 -33
  208. package/4.api/4.commands/init.md +0 -50
  209. package/4.api/4.commands/module.md +0 -84
  210. package/4.api/4.commands/prepare.md +0 -41
  211. package/4.api/4.commands/preview.md +0 -44
  212. package/4.api/4.commands/test.md +0 -40
  213. package/4.api/4.commands/typecheck.md +0 -44
  214. package/4.api/4.commands/upgrade.md +0 -37
@@ -8,7 +8,7 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- ::read-more{to="/docs/4.x/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
11
+ ::read-more{to="/docs/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
12
12
  This feature is experimental and in order to use it you must enable the `experimental.inlineRouteRules` option in your `nuxt.config`.
13
13
  ::
14
14
 
@@ -37,7 +37,7 @@ export default defineNuxtConfig({
37
37
  ```
38
38
 
39
39
  ::note
40
- When running [`nuxt build`](/docs/4.x/api/commands/build), the home page will be pre-rendered in `.output/public/index.html` and statically served.
40
+ When running [`nuxt build`](/docs/api/commands/build), the home page will be pre-rendered in `.output/public/index.html` and statically served.
41
41
  ::
42
42
 
43
43
  ## Notes
@@ -48,8 +48,8 @@ When running [`nuxt build`](/docs/4.x/api/commands/build), the home page will be
48
48
 
49
49
  If a page path cannot be converted to an equivalent route rule pattern (for example, a param with a regular expression like `/:id(\d+)`, a partial segment like `/prefix-:id`, or a repeatable param like `/:slug+`), the rules for that page are **not** applied and Nuxt warns during build. In that case, define the rules explicitly in `nitro.routeRules` in your `nuxt.config`.
50
50
 
51
- For more control, such as if you are using a custom `path` or `alias` set in the page's [`definePageMeta`](/docs/4.x/api/utils/define-page-meta), you should set `routeRules` directly within your `nuxt.config`.
51
+ For more control, such as if you are using a custom `path` or `alias` set in the page's [`definePageMeta`](/docs/api/utils/define-page-meta), you should set `routeRules` directly within your `nuxt.config`.
52
52
 
53
- ::read-more{to="/docs/4.x/guide/concepts/rendering#hybrid-rendering" icon="i-lucide-medal"}
53
+ ::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering" icon="i-lucide-medal"}
54
54
  Read more about the `routeRules`.
55
55
  ::
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: 'defineUseAsyncDataAddon'
3
+ description: Define a reusable addon that extends composables created with createUseAsyncData.
4
+ minimalVersion: "4.6"
5
+ links:
6
+ - label: Source
7
+ icon: i-simple-icons-github
8
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/addons.ts
9
+ size: xs
10
+ ---
11
+
12
+ `defineUseAsyncDataAddon` defines a reusable extension for `useAsyncData` composables created with [`createUseAsyncData`](/docs/api/composables/create-use-async-data).
13
+
14
+ An addon can declare custom call-site options, wrap the handler with middleware, attach custom reactive logic or extend the returned object.
15
+
16
+ :read-more{to="/docs/api/utils/define-use-fetch-addon" title="defineUseFetchAddon: Addons for useAsyncData work the same way as useFetch addons"}
17
+
18
+ ## Usage
19
+
20
+ For example, an addon adding a `pollEvery` option that refreshes the data on an interval:
21
+
22
+ ```ts [app/composables/usePolledAsyncData.ts]
23
+ const polling = defineUseAsyncDataAddon({
24
+ setup: (options: UseAsyncDataAddonOptions<{ pollEvery?: number }>) => {
25
+ if (import.meta.server || !options.pollEvery) { return }
26
+ return (asyncData) => {
27
+ const interval = setInterval(() => asyncData.refresh(), options.pollEvery)
28
+ onScopeDispose(() => clearInterval(interval))
29
+ }
30
+ },
31
+ })
32
+
33
+ export const usePolledAsyncData = createUseAsyncData({ addons: [polling] })
34
+ ```
35
+
36
+ ```vue [app/pages/index.vue]
37
+ <script setup lang="ts">
38
+ // refreshes the data every 30 seconds
39
+ const { data } = await usePolledAsyncData(
40
+ 'mountains',
41
+ () => $fetch('https://api.nuxtjs.dev/mountains'),
42
+ { pollEvery: 30_000 },
43
+ )
44
+ </script>
45
+ ```
46
+
47
+ ::note
48
+ Addons run in the order of the `addons` array, with middleware from the first addon as the outermost wrapper. Listing the same addon object more than once runs it only once.
49
+ ::
50
+
51
+ ## Type
52
+
53
+ ```ts [Signature]
54
+ function defineUseAsyncDataAddon<Opts extends Record<string, any> = {}, Ext = {}> (addon: {
55
+ setup: (options: UseAsyncDataAddonOptions<Opts>) => ((asyncData: AsyncDataAddonInstance) => Ext | void) | void
56
+ }): UseAsyncDataAddon<Opts, Ext>
57
+ ```
@@ -0,0 +1,168 @@
1
+ ---
2
+ title: 'defineUseFetchAddon'
3
+ description: Define a reusable addon that extends composables created with createUseFetch.
4
+ minimalVersion: "4.6"
5
+ links:
6
+ - label: Source
7
+ icon: i-simple-icons-github
8
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/addons.ts
9
+ size: xs
10
+ ---
11
+
12
+ `defineUseFetchAddon` defines a reusable extension for `useFetch` composables created with [`createUseFetch`](/docs/api/composables/create-use-fetch).
13
+
14
+ An addon can declare custom call-site options, wrap the handler with middleware, attach custom reactive logic or extend the returned object.
15
+
16
+ ## Usage
17
+
18
+ Pass addons to `createUseFetch` via the `addons` array.
19
+
20
+ This addon attaches custom logic: a watcher that refreshes the data whenever the window regains focus and gates it behind a custom `refreshOnFocus` option:
21
+
22
+ ```ts [app/composables/useCustomFetch.ts]
23
+ const refreshOnFocus = defineUseFetchAddon({
24
+ // augment the call-site options for the custom useFetch instance 👇
25
+ setup: (options: UseFetchAddonOptions<{ refreshOnFocus?: boolean }>) => {
26
+ // 👈 run code *before* calling `useAsyncData` in `useFetch`
27
+ if (import.meta.server || !options.refreshOnFocus) { return }
28
+
29
+ return (asyncData) => {
30
+ // 👈 run code *after* calling `useAsyncData` in `useFetch`
31
+ const focused = useWindowFocus()
32
+ watch(focused, (focused) => {
33
+ if (focused) { asyncData.refresh() }
34
+ })
35
+
36
+ return { focused } // 👈 extend the returned object with a new property
37
+ }
38
+ },
39
+ })
40
+
41
+ export const useCustomFetch = createUseFetch({ addons: [refreshOnFocus] })
42
+ ```
43
+
44
+ ```vue [app/pages/index.vue]
45
+ <script setup lang="ts">
46
+ const { data } = await useCustomFetch('/some-endpoint', { refreshOnFocus: true })
47
+ </script>
48
+ ```
49
+
50
+ The addon's `setup` function runs on every call of the composable, and receives the merged options (factory defaults plus caller options).
51
+
52
+ ::note
53
+ Addons run in the order of the `addons` array, with middleware from the first addon as the outermost wrapper. Listing the same addon object more than once runs it only once.
54
+ ::
55
+
56
+ ## Custom Options
57
+
58
+ Declare custom options by annotating the `setup` `options` parameter with `UseFetchAddonOptions<{ ... }>`. The options become part of the created composable's signature, fully typed for callers:
59
+
60
+ ```ts [app/composables/useCustomFetch.ts]
61
+ const auth = defineUseFetchAddon({
62
+ setup: (options: UseFetchAddonOptions<{ auth?: MaybeRefOrGetter<boolean> }>) => {
63
+ const { token } = useTokenStore()
64
+ options.auth ??= true
65
+ options.onRequest.push(({ options: fetchOptions }) => {
66
+ if (!toValue(options.auth)) { return }
67
+ fetchOptions.headers.set('Authorization', `Bearer ${token.value}`)
68
+ })
69
+ },
70
+ })
71
+
72
+ export const useCustomFetch = createUseFetch({ addons: [auth] })
73
+ ```
74
+
75
+ ```vue [app/pages/index.vue]
76
+ <script setup lang="ts">
77
+ // `auth` is typed
78
+ const { data } = await useCustomFetch('/public-endpoint', { auth: false })
79
+ </script>
80
+ ```
81
+
82
+ Custom options stay in the merged options object, so they are also passed to `$fetch` along with the request options, which ignores keys it does not recognise.
83
+
84
+ ## Extending the Return Value
85
+
86
+ If `setup` returns a function, that function is called with the async data instance. Any object it returns is merged into the composable's return value:
87
+
88
+ ```ts
89
+ const timestamps = defineUseFetchAddon({
90
+ setup: () => {
91
+ const refreshedAt = ref<Date>()
92
+
93
+ return (asyncData) => {
94
+ watch(asyncData.status, (status) => {
95
+ if (status === 'success') { refreshedAt.value = new Date() }
96
+ }, { immediate: true })
97
+
98
+ return { refreshedAt: readonly(refreshedAt) }
99
+ }
100
+ },
101
+ })
102
+
103
+ export const useCustomFetch = createUseFetch({ addons: [timestamps] })
104
+ ```
105
+
106
+ ```vue [app/pages/index.vue]
107
+ <script setup lang="ts">
108
+ // `refreshedAt` is typed
109
+ const { data, refreshedAt } = await useCustomFetch('/modules')
110
+ </script>
111
+ ```
112
+
113
+ ## Middleware
114
+
115
+ Middleware wraps the execution of the request handler. Call `next()` to continue the chain (and get the resolved data), or throw to abort. Middleware from the first addon is the outermost wrapper:
116
+
117
+ ```ts
118
+ const minDuration = defineUseFetchAddon({
119
+ setup: (options: UseFetchAddonOptions<{ minDuration?: number }>) => {
120
+ options.middleware.push(async (next) => {
121
+ const [result] = await Promise.all([
122
+ next(),
123
+ new Promise(resolve => setTimeout(resolve, toValue(options.minDuration) ?? 300)),
124
+ ])
125
+ return result
126
+ })
127
+ },
128
+ })
129
+ ```
130
+
131
+ ## Contributing to the Auto-Generated Key
132
+
133
+ Custom options are **not** part of the auto-generated key by default. If a custom option affects the response, provide a `key` resolver so calls with different values do not share a cached entry. Return a serializable value, or `undefined` to contribute nothing:
134
+
135
+ ```ts
136
+ const scoped = defineUseFetchAddon({
137
+ setup: (options: UseFetchAddonOptions<{ scope?: string }>) => {
138
+ options.scope ??= 'default'
139
+ // ...
140
+ },
141
+ key: options => toValue(options.scope),
142
+ })
143
+ ```
144
+
145
+ ::warning
146
+ Declare `setup` before `key`. TypeScript infers the custom options from the `setup` parameter annotation, and a `key` resolver written before a `setup` that returns an extension function is checked first and typed with empty options.
147
+ ::
148
+
149
+ ## Wrapping `then`, `catch` and `finally`
150
+
151
+ As an advanced escape hatch, the extension object may include `then`, `catch` or `finally` functions. These are not merged into the instance. Instead they wrap the corresponding method of the awaitable promise, receiving the original method as their first argument.
152
+
153
+ ::note
154
+ When several addons wrap the same method, the wrappers are composed in the order of the `addons` array: the first addon's wrapper wraps all the following ones, just as its middleware would.
155
+ ::
156
+
157
+ ## Type
158
+
159
+ ```ts [Signature]
160
+ function defineUseFetchAddon<Opts extends Record<string, any> = {}, Ext = {}> (addon: {
161
+ setup: (options: UseFetchAddonOptions<Opts>) => ((asyncData: AsyncDataAddonInstance) => Ext | void) | void
162
+ key?: (options: UseFetchAddonOptions<Opts>) => SerializableValue
163
+ }): UseFetchAddon<Opts, Ext>
164
+ ```
165
+
166
+ ::note
167
+ `middleware`, `onRequest`, `onRequestError`, `onResponse` and `onResponseError` are always normalized to arrays, so interceptors from the caller and from other addons are preserved.
168
+ ::
@@ -10,7 +10,7 @@ links:
10
10
 
11
11
  ## Usage
12
12
 
13
- `navigateTo` is available on both server side and client side. It can be used within the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context), or directly, to perform page navigation.
13
+ `navigateTo` is available on both server side and client side. It can be used within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context), or directly, to perform page navigation.
14
14
 
15
15
  ::warning
16
16
  Make sure to always use `await` or `return` on result of `navigateTo` when calling it.
@@ -41,6 +41,10 @@ await navigateTo({
41
41
  </script>
42
42
  ```
43
43
 
44
+ ::note
45
+ Calling `navigateTo` does not stop execution of the rest of your `<script setup>` code. If you want a successful navigation to return early from `setup()`, enable [`experimental.navigateToEarlyReturn`](/docs/guide/going-further/experimental-features#navigatetoearlyreturn).
46
+ ::
47
+
44
48
  ### Within Route Middleware
45
49
 
46
50
  ```ts
@@ -68,7 +72,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
68
72
 
69
73
  In this case, `navigateTo` will be executed but not returned, which may lead to unexpected behavior.
70
74
 
71
- :read-more{to="/docs/4.x/directory-structure/app/middleware"}
75
+ :read-more{to="/docs/directory-structure/app/middleware"}
72
76
 
73
77
  ### Navigating to an External URL
74
78
 
@@ -20,7 +20,7 @@ await prefetchComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
20
20
  ```
21
21
 
22
22
  ::note
23
- Current implementation behaves exactly the same as [`preloadComponents`](/docs/4.x/api/utils/preload-components) by preloading components instead of just prefetching we are working to improve this behavior.
23
+ Current implementation behaves exactly the same as [`preloadComponents`](/docs/api/utils/preload-components) by preloading components instead of just prefetching we are working to improve this behavior.
24
24
  ::
25
25
 
26
26
  ::note
@@ -14,7 +14,7 @@ Preloading routes loads the components of a given route that the user might navi
14
14
  Nuxt already automatically preloads the necessary routes if you're using the `NuxtLink` component.
15
15
  ::
16
16
 
17
- :read-more{to="/docs/4.x/api/components/nuxt-link"}
17
+ :read-more{to="/docs/api/components/nuxt-link"}
18
18
 
19
19
  ## Example
20
20
 
@@ -34,7 +34,7 @@ const submit = async () => {
34
34
  }
35
35
  ```
36
36
 
37
- :read-more{to="/docs/4.x/api/utils/navigate-to"}
37
+ :read-more{to="/docs/api/utils/navigate-to"}
38
38
 
39
39
  ::note
40
40
  On server, `preloadRouteComponents` will have no effect.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: 'prerenderRoutes'
3
- description: prerenderRoutes hints to Nitro to prerender an additional route.
3
+ description: prerenderRoutes hints that an additional route should be prerendered.
4
4
  minimalVersion: "3.8"
5
5
  links:
6
6
  - label: Source
@@ -9,10 +9,10 @@ links:
9
9
  size: xs
10
10
  ---
11
11
 
12
- When prerendering, you can hint to Nitro to prerender additional paths, even if their URLs do not show up in the HTML of the generated page.
12
+ When prerendering, you can hint that additional paths should be prerendered, even if their URLs do not show up in the HTML of the generated page. Nuxt collects the hints and passes them to your server builder's prerenderer (Nitro by default).
13
13
 
14
14
  ::important
15
- `prerenderRoutes` can only be called within the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context).
15
+ `prerenderRoutes` can only be called within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
16
16
  ::
17
17
 
18
18
  ::note
@@ -34,7 +34,7 @@ const loggedIn = computed(() => !!tokenCookie.value)
34
34
  </script>
35
35
  ```
36
36
 
37
- ::note{to="/docs/4.x/guide/going-further/experimental-features#cookiestore"}
37
+ ::note{to="/docs/guide/going-further/experimental-features#cookiestore"}
38
38
  Since [Nuxt v3.12.0](https://github.com/nuxt/nuxt/releases/tag/v3.12.0), the experimental `cookieStore` option is enabled by default. It automatically refreshes the `useCookie` value when cookies change in the browser.
39
39
  ::
40
40
 
@@ -8,7 +8,7 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- `refreshNuxtData` is used to refetch all or specific `asyncData` instances, including those from [`useAsyncData`](/docs/4.x/api/composables/use-async-data), [`useLazyAsyncData`](/docs/4.x/api/composables/use-lazy-async-data), [`useFetch`](/docs/4.x/api/composables/use-fetch), and [`useLazyFetch`](/docs/4.x/api/composables/use-lazy-fetch).
11
+ `refreshNuxtData` is used to refetch all or specific `asyncData` instances, including those from [`useAsyncData`](/docs/api/composables/use-async-data), [`useLazyAsyncData`](/docs/api/composables/use-lazy-async-data), [`useFetch`](/docs/api/composables/use-fetch), and [`useLazyFetch`](/docs/api/composables/use-lazy-fetch).
12
12
 
13
13
  ::note
14
14
  If your component is cached by `<KeepAlive>` and enters a deactivated state, the `asyncData` inside the component will still be refetched until the component is unmounted.
@@ -22,7 +22,7 @@ export function refreshNuxtData (keys?: string | string[])
22
22
 
23
23
  ## Parameters
24
24
 
25
- * `keys`: A single string or an array of strings as `keys` that are used to fetch the data. This parameter is **optional**. All [`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`useFetch`](/docs/4.x/api/composables/use-fetch) keys are re-fetched when no `keys` are explicitly specified.
25
+ * `keys`: A single string or an array of strings as `keys` that are used to fetch the data. This parameter is **optional**. All [`useAsyncData`](/docs/api/composables/use-async-data) and [`useFetch`](/docs/api/composables/use-fetch) keys are re-fetched when no `keys` are explicitly specified.
26
26
 
27
27
  ## Return Values
28
28
 
@@ -93,4 +93,4 @@ async function refresh () {
93
93
  If you have access to the `asyncData` instance, it is recommended to use its `refresh` or `execute` method as the preferred way to refetch the data.
94
94
  ::
95
95
 
96
- :read-more{to="/docs/4.x/getting-started/data-fetching"}
96
+ :read-more{to="/docs/getting-started/data-fetching"}
@@ -15,7 +15,7 @@ links:
15
15
 
16
16
  By default, it will also save the current `state` of your app (that is, any state you could access with `useState`).
17
17
 
18
- ::read-more{to="/docs/4.x/guide/going-further/experimental-features#restorestate" icon="i-lucide-star"}
18
+ ::read-more{to="/docs/guide/going-further/experimental-features#restorestate" icon="i-lucide-star"}
19
19
  You can enable experimental restoration of this state by enabling the `experimental.restoreState` option in your `nuxt.config` file.
20
20
  ::
21
21
 
@@ -9,7 +9,7 @@ links:
9
9
  ---
10
10
 
11
11
  ::important
12
- `setPageLayout` allows you to dynamically change the layout of a page. It relies on access to the Nuxt context and therefore can only be called within the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context).
12
+ `setPageLayout` allows you to dynamically change the layout of a page. It relies on access to the Nuxt context and therefore can only be called within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
13
13
  ::
14
14
 
15
15
  ```ts [app/middleware/custom-layout.ts]
@@ -13,7 +13,7 @@ Nuxt provides composables and utilities for first-class server-side-rendering su
13
13
  `setResponseStatus` sets the status (and optionally the statusText) of the response.
14
14
 
15
15
  ::important
16
- `setResponseStatus` can only be called in the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context).
16
+ `setResponseStatus` can only be called in the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
17
17
  ::
18
18
 
19
19
  ```ts
@@ -33,4 +33,4 @@ if (event) {
33
33
  In the browser, `setResponseStatus` will have no effect.
34
34
  ::
35
35
 
36
- :read-more{to="/docs/4.x/getting-started/error-handling"}
36
+ :read-more{to="/docs/getting-started/error-handling"}
@@ -8,7 +8,7 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- Within the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context) you can use `showError` to show an error.
11
+ Within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) you can use `showError` to show an error.
12
12
 
13
13
  **Parameters:**
14
14
 
@@ -22,10 +22,10 @@ showError({
22
22
  })
23
23
  ```
24
24
 
25
- The error is set in the state using [`useError()`](/docs/4.x/api/composables/use-error) to create a reactive and SSR-friendly shared error state across components.
25
+ The error is set in the state using [`useError()`](/docs/api/composables/use-error) to create a reactive and SSR-friendly shared error state across components.
26
26
 
27
27
  ::tip
28
28
  `showError` calls the `app:error` hook.
29
29
  ::
30
30
 
31
- :read-more{to="/docs/4.x/getting-started/error-handling"}
31
+ :read-more{to="/docs/getting-started/error-handling"}
@@ -9,7 +9,7 @@ links:
9
9
  ---
10
10
 
11
11
  ::note
12
- Updates the [`app.config`](/docs/4.x/directory-structure/app/app-config) using deep assignment. Existing (nested) properties will be preserved.
12
+ Updates the [`app.config`](/docs/directory-structure/app/app-config) using deep assignment. Existing (nested) properties will be preserved.
13
13
  ::
14
14
 
15
15
  ## Usage
@@ -25,4 +25,4 @@ updateAppConfig(newAppConfig)
25
25
  console.log(appConfig) // { foo: 'baz' }
26
26
  ```
27
27
 
28
- :read-more{to="/docs/4.x/directory-structure/app/app-config"}
28
+ :read-more{to="/docs/directory-structure/app/app-config"}
@@ -0,0 +1,9 @@
1
+ ---
2
+ navigation: false
3
+ ---
4
+
5
+ # Nuxt CLI Commands
6
+
7
+ The Nuxt CLI command reference now lives in the `docs/` directory of <https://github.com/nuxt/cli>, which is the source of truth for these pages.
8
+
9
+ Editing files in this directory has no effect on the website. Please open your pull request against `nuxt/cli` instead.
@@ -62,7 +62,7 @@ export function defineNuxtModule<TOptions extends ModuleOptions> (): {
62
62
  | `defaults` | `T \| ((nuxt: Nuxt) => T)`{lang="ts"} | `false` | Default options for the module. If a function is provided, it will be called with the Nuxt instance as the first argument. |
63
63
  | `schema` | `T` | `false` | Schema for the module options. If provided, options will be applied to the schema. |
64
64
  | `hooks` | `Partial<NuxtHooks>`{lang="ts"} | `false` | Hooks to be installed for the module. If provided, the module will install the hooks. |
65
- | `moduleDependencies` | `Record<string, ModuleDependency> \| ((nuxt: Nuxt) => Record<string, ModuleDependency>)`{lang="ts"} | `false` | Dependencies on other modules with version constraints and configuration. Can be an object or a function that receives the Nuxt instance. See [example](/docs/4.x/api/kit/modules#specifying-module-dependencies). |
65
+ | `moduleDependencies` | `Record<string, ModuleDependency> \| ((nuxt: Nuxt) => Record<string, ModuleDependency>)`{lang="ts"} | `false` | Dependencies on other modules with version constraints and configuration. Can be an object or a function that receives the Nuxt instance. See [example](/docs/api/kit/modules#specifying-module-dependencies). |
66
66
  | `onInstall` | `(nuxt: Nuxt) => Awaitable<void>`{lang="ts"} | `false` | Lifecycle hook called when the module is first installed. Requires `meta.name` and `meta.version` to be defined. |
67
67
  | `onUpgrade` | `(nuxt: Nuxt, options: T, previousVersion: string) => Awaitable<void>`{lang="ts"} | `false` | Lifecycle hook called when the module is upgraded to a newer version. Requires `meta.name` and `meta.version` to be defined. |
68
68
  | `setup` | `(this: void, resolvedOptions: T, nuxt: Nuxt) => Awaitable<void \| false \| ModuleSetupInstallResult>`{lang="ts"} | `false` | Setup function for the module. If provided, the module will call the setup function. |
@@ -113,7 +113,7 @@ export default defineNuxtConfig({
113
113
  ```
114
114
 
115
115
  ::tip
116
- This is particularly useful when you want to disable modules inherited from [Nuxt layers](/docs/4.x/guide/going-further/layers#disabling-modules-from-layers).
116
+ This is particularly useful when you want to disable modules inherited from [Nuxt layers](/docs/guide/going-further/layers#disabling-modules-from-layers).
117
117
  ::
118
118
 
119
119
  #### Defining Module Compatibility Requirements
@@ -337,7 +337,7 @@ export default defineNuxtModule({
337
337
  ## `installModule`
338
338
 
339
339
  ::callout{type="warning"}
340
- **Deprecated:** Use the [`moduleDependencies`](/docs/4.x/api/kit/modules#specifying-module-dependencies) option in `defineNuxtModule` instead. The `installModule` function will be removed (or may become non-blocking) in a future version.
340
+ **Deprecated:** Use the [`moduleDependencies`](/docs/api/kit/modules#specifying-module-dependencies) option in `defineNuxtModule` instead. The `installModule` function will be removed (or may become non-blocking) in a future version.
341
341
  ::
342
342
 
343
343
  Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to `inlineOptions` and they will be passed to the module's `setup` function.
@@ -10,7 +10,7 @@ links:
10
10
 
11
11
  ## `useRuntimeConfig`
12
12
 
13
- At build-time, it is possible to access the resolved Nuxt [runtime config](/docs/4.x/guide/going-further/runtime-config).
13
+ At build-time, it is possible to access the resolved Nuxt [runtime config](/docs/guide/going-further/runtime-config).
14
14
 
15
15
  ### Type
16
16
 
@@ -56,6 +56,7 @@ function addTemplate (template: NuxtTemplate | string): ResolvedNuxtTemplate
56
56
  | `options` | `Options` | `false` | Options to pass to the template. |
57
57
  | `getContents` | `(data: Options) => string \| Promise<string>`{lang="ts"} | `false` | A function that will be called with the `options` object. It should return a string or a promise that resolves to a string. If `src` is provided, this function will be ignored. |
58
58
  | `write` | `boolean` | `false` | If set to `true`, the template will be written to the destination file. Otherwise, the template will be used only in virtual filesystem. |
59
+ | `dependsOn` | `Array<'pages' \| 'plugins'> \| ((change: { event, path }, ctx: { nuxt, app, options }) => boolean)`{lang="ts"} | `false` | The watched inputs the output of the template can depend on, beyond `nuxt.options` and the resolved structure of the app. Set to `[]` if the template never reads the contents of a watched file, so that Nuxt can skip recompiling it in dev mode when a file changes without any file being added or removed. List well-known keys if the template reads those sources, or pass a function to decide per change. A template that declares nothing is regenerated on every change. |
59
60
 
60
61
  ### Example
61
62
 
@@ -82,6 +83,47 @@ export default defineNuxtModule({
82
83
  })
83
84
  ```
84
85
 
86
+ #### Skipping Regeneration in Development
87
+
88
+ By default, Nuxt recompiles a template on every watched file event because it cannot know what
89
+ the template reads. If your template is built only from configuration and from which files exist,
90
+ declare that so Nuxt can leave it alone when a file is edited:
91
+
92
+ ```ts twoslash [module.ts]
93
+ import { addTemplate, defineNuxtModule } from '@nuxt/kit'
94
+
95
+ export default defineNuxtModule({
96
+ setup (options, nuxt) {
97
+ addTemplate({
98
+ filename: 'my-module/config.mjs',
99
+ dependsOn: [],
100
+ getContents: () => 'export default ' + JSON.stringify(options),
101
+ })
102
+ },
103
+ })
104
+ ```
105
+
106
+ If the template reads well-known sources, declare them by key:
107
+
108
+ ```ts
109
+ addTemplate({
110
+ filename: 'my-module/routes.mjs',
111
+ dependsOn: ['pages'],
112
+ getContents: ({ app }) => generateRoutes(app.pages),
113
+ })
114
+ ```
115
+
116
+ And if it reads files Nuxt doesn't know about, say a set of YAML files you scan yourself, pass a
117
+ function instead:
118
+
119
+ ```ts
120
+ addTemplate({
121
+ filename: 'my-module/content.mjs',
122
+ dependsOn: ({ path }) => path.endsWith('.yaml'),
123
+ getContents: () => generateContents(),
124
+ })
125
+ ```
126
+
85
127
  In the module above, we generate a virtual file named `meta.config.mjs`. In the runtime plugin, we can import it using the `#build` alias:
86
128
 
87
129
  ```ts [runtime/plugin.ts]