@nuxt/docs 4.1.1 → 4.1.3

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 (200) hide show
  1. package/1.getting-started/01.introduction.md +6 -6
  2. package/1.getting-started/02.installation.md +2 -1
  3. package/1.getting-started/03.configuration.md +37 -37
  4. package/1.getting-started/04.views.md +9 -9
  5. package/1.getting-started/05.assets.md +15 -9
  6. package/1.getting-started/06.styling.md +58 -48
  7. package/1.getting-started/07.routing.md +17 -17
  8. package/1.getting-started/08.seo-meta.md +59 -46
  9. package/1.getting-started/09.transitions.md +49 -44
  10. package/1.getting-started/10.data-fetching.md +104 -81
  11. package/1.getting-started/11.state-management.md +27 -20
  12. package/1.getting-started/12.error-handling.md +22 -20
  13. package/1.getting-started/13.server.md +8 -8
  14. package/1.getting-started/14.layers.md +22 -16
  15. package/1.getting-started/15.prerendering.md +32 -32
  16. package/1.getting-started/16.deployment.md +10 -10
  17. package/1.getting-started/17.testing.md +44 -44
  18. package/1.getting-started/18.upgrade.md +53 -71
  19. package/2.guide/0.index.md +7 -7
  20. package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
  21. package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
  22. package/2.guide/1.directory-structure/0.output.md +18 -0
  23. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
  24. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
  25. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +49 -28
  26. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
  27. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
  28. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
  29. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
  30. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
  31. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
  32. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
  33. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
  34. package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
  35. package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
  36. package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
  37. package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
  38. package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
  39. package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
  40. package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
  41. package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
  42. package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
  43. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
  44. package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
  45. package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
  46. package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
  47. package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
  48. package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
  49. package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
  50. package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
  51. package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
  52. package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
  53. package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
  54. package/2.guide/{1.concepts → 2.concepts}/7.esm.md +17 -15
  55. package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
  56. package/2.guide/3.going-further/1.events.md +3 -3
  57. package/2.guide/3.going-further/1.experimental-features.md +246 -85
  58. package/2.guide/3.going-further/1.features.md +44 -9
  59. package/2.guide/3.going-further/1.internals.md +25 -25
  60. package/2.guide/3.going-further/10.runtime-config.md +12 -12
  61. package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
  62. package/2.guide/3.going-further/2.hooks.md +14 -14
  63. package/2.guide/3.going-further/3.modules.md +96 -94
  64. package/2.guide/3.going-further/4.kit.md +7 -7
  65. package/2.guide/3.going-further/6.nuxt-app.md +8 -8
  66. package/2.guide/3.going-further/7.layers.md +62 -53
  67. package/2.guide/3.going-further/9.debugging.md +2 -2
  68. package/2.guide/4.recipes/1.custom-routing.md +30 -30
  69. package/2.guide/4.recipes/2.vite-plugin.md +4 -4
  70. package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
  71. package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
  72. package/2.guide/5.best-practices/hydration.md +4 -4
  73. package/2.guide/5.best-practices/performance.md +17 -17
  74. package/3.api/1.components/1.client-only.md +6 -3
  75. package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
  76. package/3.api/1.components/10.nuxt-picture.md +1 -1
  77. package/3.api/1.components/11.teleports.md +5 -2
  78. package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
  79. package/3.api/1.components/13.nuxt-time.md +44 -17
  80. package/3.api/1.components/2.nuxt-page.md +6 -6
  81. package/3.api/1.components/3.nuxt-layout.md +15 -10
  82. package/3.api/1.components/4.nuxt-link.md +42 -22
  83. package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
  84. package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
  85. package/3.api/2.composables/on-prehydrate.md +2 -2
  86. package/3.api/2.composables/use-app-config.md +1 -1
  87. package/3.api/2.composables/use-async-data.md +20 -20
  88. package/3.api/2.composables/use-cookie.md +29 -21
  89. package/3.api/2.composables/use-error.md +2 -2
  90. package/3.api/2.composables/use-fetch.md +58 -32
  91. package/3.api/2.composables/use-head-safe.md +7 -7
  92. package/3.api/2.composables/use-head.md +5 -5
  93. package/3.api/2.composables/use-hydration.md +6 -6
  94. package/3.api/2.composables/use-lazy-async-data.md +4 -4
  95. package/3.api/2.composables/use-lazy-fetch.md +4 -4
  96. package/3.api/2.composables/use-loading-indicator.md +12 -12
  97. package/3.api/2.composables/use-nuxt-app.md +22 -22
  98. package/3.api/2.composables/use-nuxt-data.md +8 -8
  99. package/3.api/2.composables/use-preview-mode.md +15 -18
  100. package/3.api/2.composables/use-request-event.md +1 -1
  101. package/3.api/2.composables/use-request-fetch.md +3 -3
  102. package/3.api/2.composables/use-request-header.md +1 -1
  103. package/3.api/2.composables/use-request-headers.md +4 -4
  104. package/3.api/2.composables/use-request-url.md +1 -1
  105. package/3.api/2.composables/use-response-header.md +9 -10
  106. package/3.api/2.composables/use-route-announcer.md +4 -4
  107. package/3.api/2.composables/use-route.md +1 -1
  108. package/3.api/2.composables/use-router.md +10 -8
  109. package/3.api/2.composables/use-runtime-config.md +11 -11
  110. package/3.api/2.composables/use-runtime-hook.md +2 -2
  111. package/3.api/2.composables/use-seo-meta.md +4 -4
  112. package/3.api/2.composables/use-server-seo-meta.md +6 -6
  113. package/3.api/2.composables/use-state.md +5 -5
  114. package/3.api/3.utils/$fetch.md +10 -8
  115. package/3.api/3.utils/abort-navigation.md +3 -3
  116. package/3.api/3.utils/add-route-middleware.md +5 -5
  117. package/3.api/3.utils/call-once.md +6 -6
  118. package/3.api/3.utils/clear-error.md +3 -3
  119. package/3.api/3.utils/clear-nuxt-data.md +3 -3
  120. package/3.api/3.utils/clear-nuxt-state.md +3 -3
  121. package/3.api/3.utils/create-error.md +2 -2
  122. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  123. package/3.api/3.utils/define-nuxt-component.md +5 -5
  124. package/3.api/3.utils/define-nuxt-plugin.md +13 -13
  125. package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
  126. package/3.api/3.utils/define-page-meta.md +23 -23
  127. package/3.api/3.utils/define-route-rules.md +7 -7
  128. package/3.api/3.utils/navigate-to.md +11 -11
  129. package/3.api/3.utils/prefetch-components.md +1 -1
  130. package/3.api/3.utils/preload-components.md +1 -1
  131. package/3.api/3.utils/preload-route-components.md +2 -2
  132. package/3.api/3.utils/prerender-routes.md +3 -3
  133. package/3.api/3.utils/refresh-cookie.md +4 -4
  134. package/3.api/3.utils/refresh-nuxt-data.md +12 -7
  135. package/3.api/3.utils/reload-nuxt-app.md +3 -3
  136. package/3.api/3.utils/set-page-layout.md +1 -1
  137. package/3.api/3.utils/set-response-status.md +3 -3
  138. package/3.api/3.utils/show-error.md +5 -5
  139. package/3.api/3.utils/update-app-config.md +4 -3
  140. package/3.api/4.commands/add.md +1 -1
  141. package/3.api/4.commands/analyze.md +2 -1
  142. package/3.api/4.commands/build.md +2 -1
  143. package/3.api/4.commands/dev.md +5 -4
  144. package/3.api/4.commands/generate.md +3 -2
  145. package/3.api/4.commands/init.md +3 -2
  146. package/3.api/4.commands/module.md +4 -4
  147. package/3.api/4.commands/prepare.md +7 -2
  148. package/3.api/4.commands/preview.md +5 -4
  149. package/3.api/4.commands/test.md +40 -0
  150. package/3.api/4.commands/typecheck.md +5 -3
  151. package/3.api/4.commands/upgrade.md +3 -3
  152. package/3.api/5.kit/1.modules.md +36 -36
  153. package/3.api/5.kit/10.runtime-config.md +1 -1
  154. package/3.api/5.kit/10.templates.md +8 -6
  155. package/3.api/5.kit/11.nitro.md +62 -62
  156. package/3.api/5.kit/12.resolving.md +2 -2
  157. package/3.api/5.kit/14.builder.md +1 -0
  158. package/3.api/5.kit/15.examples.md +2 -2
  159. package/3.api/5.kit/16.layers.md +26 -26
  160. package/3.api/5.kit/3.compatibility.md +14 -14
  161. package/3.api/5.kit/4.autoimports.md +13 -13
  162. package/3.api/5.kit/5.components.md +7 -8
  163. package/3.api/5.kit/6.context.md +3 -3
  164. package/3.api/5.kit/7.pages.md +7 -7
  165. package/3.api/5.kit/8.layout.md +2 -2
  166. package/3.api/5.kit/9.plugins.md +5 -4
  167. package/3.api/6.advanced/1.hooks.md +3 -3
  168. package/3.api/6.advanced/2.import-meta.md +3 -3
  169. package/3.api/6.nuxt-config.md +300 -865
  170. package/3.api/index.md +7 -7
  171. package/5.community/2.getting-help.md +1 -1
  172. package/5.community/3.reporting-bugs.md +1 -1
  173. package/5.community/4.contribution.md +11 -11
  174. package/5.community/5.framework-contribution.md +4 -4
  175. package/5.community/6.roadmap.md +1 -1
  176. package/6.bridge/1.overview.md +13 -13
  177. package/6.bridge/10.configuration.md +2 -1
  178. package/6.bridge/2.typescript.md +3 -3
  179. package/6.bridge/3.bridge-composition-api.md +8 -8
  180. package/6.bridge/4.plugins-and-middleware.md +9 -9
  181. package/6.bridge/5.nuxt3-compatible-api.md +20 -17
  182. package/6.bridge/6.meta.md +21 -20
  183. package/6.bridge/7.runtime-config.md +1 -1
  184. package/6.bridge/8.nitro.md +3 -3
  185. package/6.bridge/9.vite.md +4 -4
  186. package/7.migration/1.overview.md +2 -2
  187. package/7.migration/10.bundling.md +1 -1
  188. package/7.migration/11.server.md +3 -3
  189. package/7.migration/2.configuration.md +23 -21
  190. package/7.migration/20.module-authors.md +7 -7
  191. package/7.migration/3.auto-imports.md +3 -3
  192. package/7.migration/4.meta.md +21 -18
  193. package/7.migration/5.plugins-and-middleware.md +8 -8
  194. package/7.migration/6.pages-and-layouts.md +28 -24
  195. package/7.migration/7.component-options.md +18 -18
  196. package/7.migration/8.runtime-config.md +7 -7
  197. package/package.json +1 -1
  198. package/2.guide/2.directory-structure/0.output.md +0 -18
  199. /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
  200. /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
@@ -4,17 +4,17 @@ description: Nuxt provides powerful state management libraries and the useState
4
4
  navigation.icon: i-lucide-database
5
5
  ---
6
6
 
7
- Nuxt provides the [`useState`](/docs/api/composables/use-state) composable to create a reactive and SSR-friendly shared state across components.
7
+ Nuxt provides the [`useState`](/docs/4.x/api/composables/use-state) composable to create a reactive and SSR-friendly shared state across components.
8
8
 
9
- [`useState`](/docs/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core.html#ref) replacement. Its value will be preserved after server-side rendering (during client-side hydration) and shared across all components using a unique key.
9
+ [`useState`](/docs/4.x/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core.html#ref) replacement. Its value will be preserved after server-side rendering (during client-side hydration) and shared across all components using a unique key.
10
10
 
11
11
  :video-accordion{title="Watch a video from Alexander Lichter about why and when to use useState" videoId="mv0WcBABcIk"}
12
12
 
13
13
  ::important
14
- Because the data inside [`useState`](/docs/api/composables/use-state) will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
14
+ Because the data inside [`useState`](/docs/4.x/api/composables/use-state) will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
15
15
  ::
16
16
 
17
- ::read-more{to="/docs/api/composables/use-state"}
17
+ ::read-more{to="/docs/4.x/api/composables/use-state"}
18
18
  Read more about `useState` composable.
19
19
  ::
20
20
 
@@ -53,15 +53,15 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))
53
53
  </template>
54
54
  ```
55
55
 
56
- :link-example{to="/docs/examples/features/state-management"}
56
+ :link-example{to="/docs/4.x/examples/features/state-management"}
57
57
 
58
58
  ::note
59
- To globally invalidate cached state, see [`clearNuxtState`](/docs/api/utils/clear-nuxt-state) util.
59
+ To globally invalidate cached state, see [`clearNuxtState`](/docs/4.x/api/utils/clear-nuxt-state) util.
60
60
  ::
61
61
 
62
62
  ### Initializing State
63
63
 
64
- Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/guide/directory-structure/app) component with the [`callOnce`](/docs/api/utils/call-once) util to do so.
64
+ Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/4.x/guide/directory-structure/app) component with the [`callOnce`](/docs/4.x/api/utils/call-once) util to do so.
65
65
 
66
66
  ```vue twoslash [app/app.vue]
67
67
  <script setup lang="ts">
@@ -77,7 +77,7 @@ await callOnce(async () => {
77
77
  This is similar to the [`nuxtServerInit` action](https://v2.nuxt.com/docs/directory-structure/store/#the-nuxtserverinit-action) in Nuxt 2, which allows filling the initial state of your store server-side before rendering the page.
78
78
  ::
79
79
 
80
- :read-more{to="/docs/api/utils/call-once"}
80
+ :read-more{to="/docs/4.x/api/utils/call-once"}
81
81
 
82
82
  ### Usage with Pinia
83
83
 
@@ -88,20 +88,20 @@ Make sure to install the Pinia module with `npx nuxt module add pinia` or follow
88
88
  ::
89
89
 
90
90
  ::code-group
91
- ```ts [stores/website.ts]
91
+ ```ts [app/stores/website.ts]
92
92
  export const useWebsiteStore = defineStore('websiteStore', {
93
93
  state: () => ({
94
94
  name: '',
95
- description: ''
95
+ description: '',
96
96
  }),
97
97
  actions: {
98
- async fetch() {
98
+ async fetch () {
99
99
  const infos = await $fetch('https://api.nuxt.com/modules/pinia')
100
100
 
101
101
  this.name = infos.name
102
102
  this.description = infos.description
103
- }
104
- }
103
+ },
104
+ },
105
105
  })
106
106
  ```
107
107
  ```vue [app/app.vue]
@@ -151,8 +151,8 @@ export const useLocales = () => {
151
151
  const locales = ref([
152
152
  'en-US',
153
153
  'en-GB',
154
- ...
155
- 'ja-JP-u-ca-japanese'
154
+ // ...,
155
+ 'ja-JP-u-ca-japanese',
156
156
  ])
157
157
  if (!locales.value.includes(locale.value)) {
158
158
  locales.value.unshift(locale.value)
@@ -177,8 +177,15 @@ const date = useLocaleDate(new Date('2016-10-26'))
177
177
  <h1>Nuxt birthday</h1>
178
178
  <p>{{ date }}</p>
179
179
  <label for="locale-chooser">Preview a different locale</label>
180
- <select id="locale-chooser" v-model="locale">
181
- <option v-for="loc of locales" :key="loc" :value="loc">
180
+ <select
181
+ id="locale-chooser"
182
+ v-model="locale"
183
+ >
184
+ <option
185
+ v-for="loc of locales"
186
+ :key="loc"
187
+ :value="loc"
188
+ >
182
189
  {{ loc }}
183
190
  </option>
184
191
  </select>
@@ -187,11 +194,11 @@ const date = useLocaleDate(new Date('2016-10-26'))
187
194
  ```
188
195
  ::
189
196
 
190
- :link-example{to="/docs/examples/advanced/locale"}
197
+ :link-example{to="/docs/4.x/examples/advanced/locale"}
191
198
 
192
199
  ## Shared State
193
200
 
194
- By using [auto-imported composables](/docs/guide/directory-structure/app/composables) we can define global type-safe states and import them across the app.
201
+ By using [auto-imported composables](/docs/4.x/guide/directory-structure/app/composables) we can define global type-safe states and import them across the app.
195
202
 
196
203
  ```ts twoslash [composables/states.ts]
197
204
  export const useColor = () => useState<string>('color', () => 'pink')
@@ -214,7 +221,7 @@ const color = useColor() // Same as useState('color')
214
221
 
215
222
  ## Using third-party libraries
216
223
 
217
- Nuxt **used to rely** on the Vuex library to provide global state management. If you are migrating from Nuxt 2, please head to [the migration guide](/docs/migration/configuration#vuex).
224
+ Nuxt **used to rely** on the Vuex library to provide global state management. If you are migrating from Nuxt 2, please head to [the migration guide](/docs/4.x/migration/configuration#vuex).
218
225
 
219
226
  Nuxt is not opinionated about state management, so feel free to choose the right solution for your needs. There are multiple integrations with the most popular state management libraries, including:
220
227
 
@@ -8,7 +8,7 @@ Nuxt is a full-stack framework, which means there are several sources of unpreve
8
8
 
9
9
  - Errors during the Vue rendering lifecycle (SSR & CSR)
10
10
  - Server and client startup errors (SSR + CSR)
11
- - Errors during Nitro server lifecycle ([`server/`](/docs/guide/directory-structure/server) directory)
11
+ - Errors during Nitro server lifecycle ([`server/`](/docs/4.x/guide/directory-structure/server) directory)
12
12
  - Errors downloading JS chunks
13
13
 
14
14
  ::tip
@@ -19,7 +19,7 @@ Nuxt is a full-stack framework, which means there are several sources of unpreve
19
19
 
20
20
  You can hook into Vue errors using [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle.html#onerrorcaptured).
21
21
 
22
- In addition, Nuxt provides a [`vue:error`](/docs/api/advanced/hooks#app-hooks-runtime) hook that will be called if any errors propagate up to the top level.
22
+ In addition, Nuxt provides a [`vue:error`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook that will be called if any errors propagate up to the top level.
23
23
 
24
24
  If you are using an error reporting framework, you can provide a global handler through [`vueApp.config.errorHandler`](https://vuejs.org/api/application.html#app-config-errorhandler). It will receive all Vue errors, even if they are handled.
25
25
 
@@ -45,7 +45,7 @@ Note that the `vue:error` hook is based on [`onErrorCaptured`](https://vuejs.org
45
45
  Nuxt will call the `app:error` hook if there are any errors in starting your Nuxt application.
46
46
 
47
47
  This includes:
48
- - running [Nuxt plugins](/docs/guide/directory-structure/plugins)
48
+ - running [Nuxt plugins](/docs/4.x/guide/directory-structure/plugins)
49
49
  - processing `app:created` and `app:beforeMount` hooks
50
50
  - rendering your Vue app to HTML (during SSR)
51
51
  - mounting the app (on client-side), though you should handle this case with `onErrorCaptured` or with `vue:error`
@@ -53,7 +53,7 @@ This includes:
53
53
 
54
54
  ## Nitro Server Errors
55
55
 
56
- You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](#error-page) section.
56
+ You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](/docs/4.x/getting-started/error-handling#error-page) section.
57
57
 
58
58
  ## Errors with JS Chunks
59
59
 
@@ -78,7 +78,7 @@ It can also occur on the client side when:
78
78
  - mounting your app if the error was not handled with `onErrorCaptured` or `vue:error` hook
79
79
  - the Vue app is initialized and mounted in browser (`app:mounted`).
80
80
 
81
- ::read-more{to="/docs/api/advanced/hooks"}
81
+ ::read-more{to="/docs/4.x/api/advanced/hooks"}
82
82
  Discover all the Nuxt lifecycle hooks.
83
83
  ::
84
84
 
@@ -91,7 +91,7 @@ Customize the default error page by adding `~/error.vue` in the source directory
91
91
  import type { NuxtError } from '#app'
92
92
 
93
93
  const props = defineProps({
94
- error: Object as () => NuxtError
94
+ error: Object as () => NuxtError,
95
95
  })
96
96
 
97
97
  const handleError = () => clearError({ redirect: '/' })
@@ -100,33 +100,35 @@ const handleError = () => clearError({ redirect: '/' })
100
100
  <template>
101
101
  <div>
102
102
  <h2>{{ error?.statusCode }}</h2>
103
- <button @click="handleError">Clear errors</button>
103
+ <button @click="handleError">
104
+ Clear errors
105
+ </button>
104
106
  </div>
105
107
  </template>
106
108
  ```
107
109
 
108
- ::read-more{to="/docs/guide/directory-structure/error"}
110
+ ::read-more{to="/docs/4.x/guide/directory-structure/error"}
109
111
  Read more about `error.vue` and its uses.
110
112
  ::
111
113
 
112
114
  For custom errors we highly recommend using `onErrorCaptured` composable that can be called in a page/component setup function or `vue:error` runtime nuxt hook that can be configured in a nuxt plugin.
113
115
 
114
116
  ```ts twoslash [plugins/error-handler.ts]
115
- export default defineNuxtPlugin(nuxtApp => {
117
+ export default defineNuxtPlugin((nuxtApp) => {
116
118
  nuxtApp.hook('vue:error', (err) => {
117
119
  //
118
120
  })
119
121
  })
120
122
  ```
121
123
 
122
- When you are ready to remove the error page, you can call the [`clearError`](/docs/api/utils/clear-error) helper function, which takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
124
+ When you are ready to remove the error page, you can call the [`clearError`](/docs/4.x/api/utils/clear-error) helper function, which takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
123
125
 
124
126
  ::important
125
127
  Make sure to check before using anything dependent on Nuxt plugins, such as `$route` or `useRouter`, as if a plugin threw an error, then it won't be re-run until you clear the error.
126
128
  ::
127
129
 
128
130
  ::note
129
- Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](#useerror) in middleware to check if an error is being handled.
131
+ Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/4.x/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
130
132
  ::
131
133
 
132
134
  ::note
@@ -143,7 +145,7 @@ function useError (): Ref<Error | { url, statusCode, statusMessage, message, des
143
145
 
144
146
  This function will return the global Nuxt error that is being handled.
145
147
 
146
- ::read-more{to="/docs/api/composables/use-error"}
148
+ ::read-more{to="/docs/4.x/api/composables/use-error"}
147
149
  Read more about `useError` composable.
148
150
  ::
149
151
 
@@ -156,7 +158,7 @@ function createError (err: string | { cause, data, message, name, stack, statusC
156
158
  Create an error object with additional metadata. You can pass a string to be set as the error `message` or an object containing error properties. It is usable in both the Vue and Server portions of your app, and is meant to be thrown.
157
159
 
158
160
  If you throw an error created with `createError`:
159
- - on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](#clearerror).
161
+ - on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).
160
162
  - on client-side, it will throw a non-fatal error for you to handle. If you need to trigger a full-screen error page, then you can do this by setting `fatal: true`.
161
163
 
162
164
  ```vue twoslash [pages/movies/[slug\\].vue]
@@ -167,13 +169,13 @@ const { data } = await useFetch(`/api/movies/${route.params.slug}`)
167
169
  if (!data.value) {
168
170
  throw createError({
169
171
  statusCode: 404,
170
- statusMessage: 'Page Not Found'
172
+ statusMessage: 'Page Not Found',
171
173
  })
172
174
  }
173
175
  </script>
174
176
  ```
175
177
 
176
- ::read-more{to="/docs/api/utils/create-error"}
178
+ ::read-more{to="/docs/4.x/api/utils/create-error"}
177
179
  Read more about `createError` util.
178
180
  ::
179
181
 
@@ -183,11 +185,11 @@ Read more about `createError` util.
183
185
  function showError (err: string | Error | { statusCode, statusMessage }): Error
184
186
  ```
185
187
 
186
- You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](#clearerror).
188
+ You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).
187
189
 
188
190
  It is recommended instead to use `throw createError()`.
189
191
 
190
- ::read-more{to="/docs/api/utils/show-error"}
192
+ ::read-more{to="/docs/4.x/api/utils/show-error"}
191
193
  Read more about `showError` util.
192
194
  ::
193
195
 
@@ -199,13 +201,13 @@ function clearError (options?: { redirect?: string }): Promise<void>
199
201
 
200
202
  This function will clear the currently handled Nuxt error. It also takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
201
203
 
202
- ::read-more{to="/docs/api/utils/clear-error"}
204
+ ::read-more{to="/docs/4.x/api/utils/clear-error"}
203
205
  Read more about `clearError` util.
204
206
  ::
205
207
 
206
208
  ## Render Error in Component
207
209
 
208
- Nuxt also provides a [`<NuxtErrorBoundary>`](/docs/api/components/nuxt-error-boundary) component that allows you to handle client-side errors within your app, without replacing your entire site with an error page.
210
+ Nuxt also provides a [`<NuxtErrorBoundary>`](/docs/4.x/api/components/nuxt-error-boundary) component that allows you to handle client-side errors within your app, without replacing your entire site with an error page.
209
211
 
210
212
  This component is responsible for handling errors that occur within its default slot. On client-side, it will prevent the error from bubbling up to the top level, and will render the `#error` slot instead.
211
213
 
@@ -230,4 +232,4 @@ If you navigate to another route, the error will be cleared automatically.
230
232
  </template>
231
233
  ```
232
234
 
233
- :link-example{to="/docs/examples/advanced/error-handling"}
235
+ :link-example{to="/docs/4.x/examples/advanced/error-handling"}
@@ -4,7 +4,7 @@ description: Build full-stack applications with Nuxt's server framework. You can
4
4
  navigation.icon: i-lucide-pc-case
5
5
  ---
6
6
 
7
- :read-more{to="/docs/guide/directory-structure/server"}
7
+ :read-more{to="/docs/4.x/guide/directory-structure/server"}
8
8
 
9
9
  ## Powered by Nitro
10
10
 
@@ -38,7 +38,7 @@ And you can directly return `text`, `json`, `html` or even a `stream`.
38
38
 
39
39
  Out-of-the-box, it supports **hot module replacement** and **auto-import** like the other parts of your Nuxt application.
40
40
 
41
- :read-more{to="/docs/guide/directory-structure/server"}
41
+ :read-more{to="/docs/4.x/guide/directory-structure/server"}
42
42
 
43
43
  ## Universal Deployment
44
44
 
@@ -59,7 +59,7 @@ Or for other runtimes:
59
59
  :card{icon="i-logos-bun" title="Bun" to="https://bun.sh" target="_blank"}
60
60
  ::
61
61
 
62
- :read-more{to="/docs/getting-started/deployment"}
62
+ :read-more{to="/docs/4.x/getting-started/deployment"}
63
63
 
64
64
  ## Hybrid Rendering
65
65
 
@@ -74,14 +74,14 @@ export default defineNuxtConfig({
74
74
  '/api/*': { cache: { maxAge: 60 * 60 } },
75
75
  // Redirection to avoid 404
76
76
  '/old-page': {
77
- redirect: { to: '/new-page', statusCode: 302 }
78
- }
77
+ redirect: { to: '/new-page', statusCode: 302 },
78
+ },
79
79
  // ...
80
- }
80
+ },
81
81
  })
82
82
  ```
83
83
 
84
- ::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering"}
84
+ ::read-more{to="/docs/4.x/guide/concepts/rendering#hybrid-rendering"}
85
85
  Learn about all available route rules are available to customize the rendering mode of your routes.
86
86
  ::
87
87
 
@@ -91,4 +91,4 @@ Some route rules (`appMiddleware`, `redirect` and `prerender`) also affect clien
91
91
 
92
92
  Nitro is used to build the app for server side rendering, as well as pre-rendering.
93
93
 
94
- :read-more{to="/docs/guide/concepts/rendering"}
94
+ :read-more{to="/docs/4.x/guide/concepts/rendering"}
@@ -9,8 +9,8 @@ One of the core features of Nuxt is the layers and extending support. You can ex
9
9
  ## Use Cases
10
10
 
11
11
  - Share reusable configuration presets across projects using `nuxt.config` and `app.config`
12
- - Create a component library using [`app/components/`](/docs/guide/directory-structure/app/components) directory
13
- - Create utility and composable library using [`app/composables/`](/docs/guide/directory-structure/app/composables) and [`app/utils/`](/docs/guide/directory-structure/app/utils) directories
12
+ - Create a component library using [`app/components/`](/docs/4.x/guide/directory-structure/app/components) directory
13
+ - Create utility and composable library using [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/guide/directory-structure/app/utils) directories
14
14
  - Create Nuxt module presets
15
15
  - Share standard setup across projects
16
16
  - Create Nuxt themes
@@ -30,15 +30,18 @@ In addition, named layer aliases to the `srcDir` of each of these layers will au
30
30
  Named layer aliases were introduced in Nuxt v3.16.0.
31
31
  ::
32
32
 
33
- In addition, you can extend from a layer by adding the [extends](/docs/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file.
33
+ In addition, you can extend from a layer by adding the [extends](/docs/4.x/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/4.x/guide/directory-structure/nuxt-config) file.
34
34
 
35
35
  ```ts [nuxt.config.ts]
36
36
  export default defineNuxtConfig({
37
37
  extends: [
38
- '../base', // Extend from a local layer
39
- '@my-themes/awesome', // Extend from an installed npm package
40
- 'github:my-themes/awesome#v1', // Extend from a git repository
41
- ]
38
+ // Extend from a local layer
39
+ '../base',
40
+ // Extend from an installed npm package
41
+ '@my-themes/awesome',
42
+ // Extend from a git repository
43
+ 'github:my-themes/awesome#v1',
44
+ ],
42
45
  })
43
46
  ```
44
47
 
@@ -48,8 +51,8 @@ You can also pass an authentication token if you are extending from a private Gi
48
51
  export default defineNuxtConfig({
49
52
  extends: [
50
53
  // per layer configuration
51
- ['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }]
52
- ]
54
+ ['github:my-themes/private-awesome', { auth: process.env.GITHUB_TOKEN }],
55
+ ],
53
56
  })
54
57
  ```
55
58
 
@@ -61,13 +64,13 @@ export default defineNuxtConfig({
61
64
  extends: [
62
65
  [
63
66
  'github:my-themes/awesome',
64
- {
67
+ {
65
68
  meta: {
66
69
  name: 'my-awesome-theme',
67
70
  },
68
71
  },
69
72
  ],
70
- ]
73
+ ],
71
74
  })
72
75
  ```
73
76
 
@@ -86,17 +89,20 @@ When using multiple layers, it's important to understand how they override each
86
89
  ```ts [nuxt.config.ts]
87
90
  export default defineNuxtConfig({
88
91
  extends: [
89
- '../base', // Highest priority (among extends)
90
- '@my-themes/awesome', // Medium priority
91
- 'github:my-themes/awesome#v1', // Lower priority
92
- ]
92
+ // Highest priority (among extends)
93
+ '../base',
94
+ // Medium priority
95
+ '@my-themes/awesome',
96
+ // Lower priority
97
+ 'github:my-themes/awesome#v1',
98
+ ],
93
99
  // Your project has the highest priority
94
100
  })
95
101
  ```
96
102
 
97
103
  This means if multiple layers define the same component, configuration, or file, the one with higher priority will be used.
98
104
 
99
- ::read-more{to="/docs/guide/going-further/layers"}
105
+ ::read-more{to="/docs/4.x/guide/going-further/layers"}
100
106
  Read more about layers in the **Layer Author Guide**.
101
107
  ::
102
108
 
@@ -6,11 +6,11 @@ navigation.icon: i-lucide-file-code-2
6
6
 
7
7
  Nuxt allows for select pages from your application to be rendered at build time. Nuxt will serve the prebuilt pages when requested instead of generating them on the fly.
8
8
 
9
- :read-more{title="Nuxt rendering modes" to="/docs/guide/concepts/rendering"}
9
+ :read-more{title="Nuxt rendering modes" to="/docs/4.x/guide/concepts/rendering"}
10
10
 
11
11
  ## Crawl-based Pre-rendering
12
12
 
13
- Use the [`nuxt generate` command](/docs/api/commands/generate) to build and pre-render your application using the [Nitro](/docs/guide/concepts/server-engine) crawler. This command is similar to `nuxt build` with the `nitro.static` option set to `true`, or running `nuxt build --prerender`.
13
+ Use the [`nuxt generate` command](/docs/4.x/api/commands/generate) to build and pre-render your application using the [Nitro](/docs/4.x/guide/concepts/server-engine) crawler. This command is similar to `nuxt build` with the `nitro.static` option set to `true`, or running `nuxt build --prerender`.
14
14
 
15
15
  This will build your site, stand up a nuxt instance, and, by default, prerender the root page `/` along with any of your site's pages it links to, any of your site's pages they link to, and so on.
16
16
 
@@ -45,23 +45,23 @@ Working of the Nitro crawler:
45
45
 
46
46
  This is important to understand since pages that are not linked to a discoverable page can't be pre-rendered automatically.
47
47
 
48
- ::read-more{to="/docs/api/commands/generate#nuxt-generate"}
48
+ ::read-more{to="/docs/4.x/api/commands/generate#nuxt-generate"}
49
49
  Read more about the `nuxt generate` command.
50
50
  ::
51
51
 
52
52
  ### Selective Pre-rendering
53
53
 
54
- You can manually specify routes that [Nitro](/docs/guide/concepts/server-engine) will fetch and pre-render during the build or ignore routes that you don't want to pre-render like `/dynamic` in the `nuxt.config` file:
54
+ You can manually specify routes that [Nitro](/docs/4.x/guide/concepts/server-engine) will fetch and pre-render during the build or ignore routes that you don't want to pre-render like `/dynamic` in the `nuxt.config` file:
55
55
 
56
56
  ```ts twoslash [nuxt.config.ts]
57
57
  export default defineNuxtConfig({
58
58
  nitro: {
59
59
  prerender: {
60
- routes: ["/user/1", "/user/2"],
61
- ignore: ["/dynamic"],
60
+ routes: ['/user/1', '/user/2'],
61
+ ignore: ['/dynamic'],
62
62
  },
63
63
  },
64
- });
64
+ })
65
65
  ```
66
66
 
67
67
  You can combine this with the `crawlLinks` option to pre-render a set of routes that the crawler can't discover like your `/sitemap.xml` or `/robots.txt`:
@@ -71,10 +71,10 @@ export default defineNuxtConfig({
71
71
  nitro: {
72
72
  prerender: {
73
73
  crawlLinks: true,
74
- routes: ["/sitemap.xml", "/robots.txt"],
74
+ routes: ['/sitemap.xml', '/robots.txt'],
75
75
  },
76
76
  },
77
- });
77
+ })
78
78
  ```
79
79
 
80
80
  Setting `nitro.prerender` to `true` is similar to `nitro.prerender.crawlLinks` to `true`.
@@ -89,23 +89,23 @@ Lastly, you can manually configure this using routeRules.
89
89
  export default defineNuxtConfig({
90
90
  routeRules: {
91
91
  // Set prerender to true to configure it to be prerendered
92
- "/rss.xml": { prerender: true },
92
+ '/rss.xml': { prerender: true },
93
93
  // Set it to false to configure it to be skipped for prerendering
94
- "/this-DOES-NOT-get-prerendered": { prerender: false },
94
+ '/this-DOES-NOT-get-prerendered': { prerender: false },
95
95
  // Everything under /blog gets prerendered as long as it
96
96
  // is linked to from another page
97
- "/blog/**": { prerender: true },
97
+ '/blog/**': { prerender: true },
98
98
  },
99
- });
99
+ })
100
100
  ```
101
101
 
102
102
  ::read-more{to="https://nitro.build/config#routerules"}
103
103
  Read more about Nitro's `routeRules` configuration.
104
104
  ::
105
105
 
106
- As a shorthand, you can also configure this in a page file using [`defineRouteRules`](/docs/api/utils/define-route-rules).
106
+ As a shorthand, you can also configure this in a page file using [`defineRouteRules`](/docs/4.x/api/utils/define-route-rules).
107
107
 
108
- ::read-more{to="/docs/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
108
+ ::read-more{to="/docs/4.x/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
109
109
  This feature is experimental and in order to use it you must enable the `experimental.inlineRouteRules` option in your `nuxt.config`.
110
110
  ::
111
111
 
@@ -114,7 +114,7 @@ This feature is experimental and in order to use it you must enable the `experim
114
114
  // Or set at the page level
115
115
  defineRouteRules({
116
116
  prerender: true,
117
- });
117
+ })
118
118
  </script>
119
119
 
120
120
  <template>
@@ -130,21 +130,21 @@ This will be translated to:
130
130
  ```ts [nuxt.config.ts]
131
131
  export default defineNuxtConfig({
132
132
  routeRules: {
133
- "/": { prerender: true },
133
+ '/': { prerender: true },
134
134
  },
135
- });
135
+ })
136
136
  ```
137
137
 
138
138
  ## Runtime Prerender Configuration
139
139
 
140
140
  ### `prerenderRoutes`
141
141
 
142
- You can use this at runtime within a [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) to add more routes for Nitro to prerender.
142
+ You can use this at runtime within a [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context) to add more routes for Nitro to prerender.
143
143
 
144
144
  ```vue [app/pages/index.vue]
145
145
  <script setup>
146
- prerenderRoutes(["/some/other/url"]);
147
- prerenderRoutes("/api/content/article/my-article");
146
+ prerenderRoutes(['/some/other/url'])
147
+ prerenderRoutes('/api/content/article/my-article')
148
148
  </script>
149
149
 
150
150
  <template>
@@ -154,7 +154,7 @@ prerenderRoutes("/api/content/article/my-article");
154
154
  </template>
155
155
  ```
156
156
 
157
- :read-more{title="prerenderRoutes" to="/docs/api/utils/prerender-routes"}
157
+ :read-more{title="prerenderRoutes" to="/docs/4.x/api/utils/prerender-routes"}
158
158
 
159
159
  ### `prerender:routes` Nuxt hook
160
160
 
@@ -163,16 +163,16 @@ This is called before prerendering for additional routes to be registered.
163
163
  ```ts [nuxt.config.ts]
164
164
  export default defineNuxtConfig({
165
165
  hooks: {
166
- async "prerender:routes"(ctx) {
167
- const { pages } = await fetch("https://api.some-cms.com/pages").then(
168
- (res) => res.json(),
169
- );
166
+ async 'prerender:routes' (ctx) {
167
+ const { pages } = await fetch('https://api.some-cms.com/pages').then(
168
+ res => res.json(),
169
+ )
170
170
  for (const page of pages) {
171
- ctx.routes.add(`/${page.name}`);
171
+ ctx.routes.add(`/${page.name}`)
172
172
  }
173
173
  },
174
174
  },
175
- });
175
+ })
176
176
  ```
177
177
 
178
178
  ### `prerender:generate` Nitro hook
@@ -183,12 +183,12 @@ This is called for each route during prerendering. You can use this for fine-gra
183
183
  export default defineNuxtConfig({
184
184
  nitro: {
185
185
  hooks: {
186
- "prerender:generate"(route) {
187
- if (route.route?.includes("private")) {
188
- route.skip = true;
186
+ 'prerender:generate' (route) {
187
+ if (route.route?.includes('private')) {
188
+ route.skip = true
189
189
  }
190
190
  },
191
191
  },
192
192
  },
193
- });
193
+ })
194
194
  ```
@@ -48,9 +48,9 @@ module.exports = {
48
48
  port: '3000',
49
49
  exec_mode: 'cluster',
50
50
  instances: 'max',
51
- script: './.output/server/index.mjs'
52
- }
53
- ]
51
+ script: './.output/server/index.mjs',
52
+ },
53
+ ],
54
54
  }
55
55
  ```
56
56
 
@@ -71,9 +71,9 @@ By default, the workload gets distributed to the workers with the round robin st
71
71
  There are two ways to deploy a Nuxt application to any static hosting services:
72
72
 
73
73
  - Static site generation (SSG) with `ssr: true` pre-renders routes of your application at build time. (This is the default behavior when running `nuxt generate`.) It will also generate `/200.html` and `/404.html` single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host).
74
- - Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
74
+ - Alternatively, you can prerender your site with `ssr: false` (static single-page app). This will produce HTML pages with an empty `<div id="__nuxt"></div>` where your Vue app would normally be rendered. You will lose many SEO benefits of prerendering your site, so it is suggested instead to use [`<ClientOnly>`](/docs/4.x/api/components/client-only) to wrap the portions of your site that cannot be server rendered (if any).
75
75
 
76
- :read-more{title="Nuxt prerendering" to="/docs/getting-started/prerendering"}
76
+ :read-more{title="Nuxt prerendering" to="/docs/4.x/getting-started/prerendering"}
77
77
 
78
78
  ### Client-side Only Rendering
79
79
 
@@ -81,7 +81,7 @@ If you don't want to pre-render your routes, another way of using static hosting
81
81
 
82
82
  ```ts twoslash [nuxt.config.ts]
83
83
  export default defineNuxtConfig({
84
- ssr: false
84
+ ssr: false,
85
85
  })
86
86
  ```
87
87
 
@@ -95,13 +95,13 @@ Nuxt can be deployed to several cloud providers with a minimal amount of configu
95
95
 
96
96
  In addition to Node.js servers and static hosting services, a Nuxt project can be deployed with several well-tested presets and minimal amount of configuration.
97
97
 
98
- You can explicitly set the desired preset in the [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file:
98
+ You can explicitly set the desired preset in the [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) file:
99
99
 
100
- ```js twoslash [nuxt.config.ts]
100
+ ```ts twoslash [nuxt.config.ts]
101
101
  export default defineNuxtConfig({
102
102
  nitro: {
103
- preset: 'node-server'
104
- }
103
+ preset: 'node-server',
104
+ },
105
105
  })
106
106
  ```
107
107