@nuxt/docs 4.0.0-alpha.1 → 4.0.0-alpha.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 (46) hide show
  1. package/1.getting-started/10.data-fetching.md +2 -2
  2. package/1.getting-started/13.server.md +1 -1
  3. package/1.getting-started/15.prerendering.md +1 -1
  4. package/1.getting-started/17.testing.md +1 -1
  5. package/1.getting-started/18.upgrade.md +132 -3
  6. package/2.guide/1.concepts/3.rendering.md +1 -1
  7. package/2.guide/1.concepts/4.server-engine.md +2 -2
  8. package/2.guide/1.concepts/8.typescript.md +32 -5
  9. package/2.guide/2.directory-structure/1.app/.navigation.yml +5 -0
  10. package/2.guide/2.directory-structure/{1.pages.md → 1.app/1.pages.md} +1 -1
  11. package/2.guide/2.directory-structure/1.server.md +2 -12
  12. package/2.guide/2.directory-structure/3.tsconfig.md +14 -3
  13. package/2.guide/3.going-further/1.experimental-features.md +2 -1
  14. package/2.guide/3.going-further/11.nightly-release-channel.md +2 -2
  15. package/2.guide/3.going-further/3.modules.md +0 -2
  16. package/2.guide/4.recipes/1.custom-routing.md +5 -5
  17. package/3.api/1.components/4.nuxt-link.md +4 -0
  18. package/3.api/2.composables/on-prehydrate.md +21 -12
  19. package/3.api/2.composables/use-async-data.md +1 -1
  20. package/3.api/2.composables/use-cookie.md +67 -125
  21. package/3.api/2.composables/use-error.md +30 -7
  22. package/3.api/2.composables/use-fetch.md +70 -73
  23. package/3.api/2.composables/use-nuxt-app.md +1 -1
  24. package/3.api/3.utils/define-nuxt-plugin.md +102 -0
  25. package/3.api/3.utils/define-page-meta.md +1 -1
  26. package/3.api/5.kit/11.nitro.md +47 -0
  27. package/3.api/5.kit/13.logging.md +1 -1
  28. package/3.api/5.kit/4.autoimports.md +8 -8
  29. package/3.api/5.kit/6.context.md +1 -1
  30. package/3.api/6.advanced/1.hooks.md +8 -8
  31. package/3.api/6.nuxt-config.md +26 -49
  32. package/5.community/6.roadmap.md +17 -12
  33. package/6.bridge/2.typescript.md +2 -0
  34. package/7.migration/2.configuration.md +13 -2
  35. package/7.migration/7.component-options.md +1 -1
  36. package/package.json +1 -1
  37. /package/2.guide/2.directory-structure/{1.assets.md → 1.app/1.assets.md} +0 -0
  38. /package/2.guide/2.directory-structure/{1.components.md → 1.app/1.components.md} +0 -0
  39. /package/2.guide/2.directory-structure/{1.composables.md → 1.app/1.composables.md} +0 -0
  40. /package/2.guide/2.directory-structure/{1.layouts.md → 1.app/1.layouts.md} +0 -0
  41. /package/2.guide/2.directory-structure/{1.middleware.md → 1.app/1.middleware.md} +0 -0
  42. /package/2.guide/2.directory-structure/{1.plugins.md → 1.app/1.plugins.md} +0 -0
  43. /package/2.guide/2.directory-structure/{1.utils.md → 1.app/1.utils.md} +0 -0
  44. /package/2.guide/2.directory-structure/{3.app-config.md → 1.app/3.app-config.md} +0 -0
  45. /package/2.guide/2.directory-structure/{3.app.md → 1.app/3.app.md} +0 -0
  46. /package/2.guide/2.directory-structure/{3.error.md → 1.app/3.error.md} +0 -0
@@ -41,7 +41,7 @@ async function handleFormSubmit() {
41
41
  </script>
42
42
 
43
43
  <template>
44
- <div v-if="data == null">
44
+ <div v-if="data == undefined">
45
45
  No data
46
46
  </div>
47
47
  <div v-else>
@@ -230,7 +230,7 @@ Read more about `useAsyncData`.
230
230
 
231
231
  - `data`: the result of the asynchronous function that is passed in.
232
232
  - `refresh`/`execute`: a function that can be used to refresh the data returned by the `handler` function.
233
- - `clear`: a function that can be used to set `data` to `undefined`, set `error` to `null`, set `status` to `idle`, and mark any currently pending requests as cancelled.
233
+ - `clear`: a function that can be used to set `data` to `undefined` (or the value of `options.default()` if provided), set `error` to `undefined`, set `status` to `idle`, and mark any currently pending requests as cancelled.
234
234
  - `error`: an error object if the data fetching failed.
235
235
  - `status`: a string indicating the status of the data request (`"idle"`, `"pending"`, `"success"`, `"error"`).
236
236
 
@@ -18,7 +18,7 @@ Using Nitro gives Nuxt superpowers:
18
18
  - Universal deployment on any provider (many zero-config)
19
19
  - Hybrid rendering
20
20
 
21
- Nitro is internally using [h3](https://github.com/unjs/h3), a minimal H(TTP) framework built for high performance and portability.
21
+ Nitro is internally using [h3](https://github.com/h3js/h3), a minimal H(TTP) framework built for high performance and portability.
22
22
 
23
23
  :video-accordion{title="Watch a video from Alexander Lichter to understand the responsibilities of Nuxt and Nitro in your application" videoId="DkvgJa-X31k"}
24
24
 
@@ -135,7 +135,7 @@ export default defineNuxtConfig({
135
135
  });
136
136
  ```
137
137
 
138
- ## Runtime prerender configuration
138
+ ## Runtime Prerender Configuration
139
139
 
140
140
  ### `prerenderRoutes`
141
141
 
@@ -444,7 +444,7 @@ If you prefer to use `@vue/test-utils` on its own for unit testing in Nuxt, and
444
444
 
445
445
  2. Create a `vitest.config.ts` with the following content:
446
446
 
447
- ```ts twoslash
447
+ ```ts
448
448
  import { defineConfig } from 'vitest/config'
449
449
  import vue from '@vitejs/plugin-vue'
450
450
 
@@ -40,7 +40,7 @@ The nightly release channel `latest` tag is currently tracking the Nuxt v4 branc
40
40
 
41
41
  ## Testing Nuxt 4
42
42
 
43
- The release date of Nuxt 4 is **to be announced**. It is dependent on having enough time after Nitro's major release to be properly tested in the community. You can follow progress towards Nitro's release in [this PR](https://github.com/nitrojs/nitro/pull/2521).
43
+ Nuxt 4 is **scheduled for release in Q2 2025**. It will include all the features currently available through `compatibilityVersion: 4`.
44
44
 
45
45
  Until the release, it is possible to test many of Nuxt 4's breaking changes from Nuxt version 3.12+.
46
46
 
@@ -188,6 +188,10 @@ server/
188
188
  nuxt.config.ts
189
189
  ```
190
190
 
191
+ ::note
192
+ With this new structure, the `~` alias now points to the `app/` directory by default (your `srcDir`). This means `~/components` resolves to `app/components/`, `~/pages` to `app/pages/`, etc.
193
+ ::
194
+
191
195
  </details>
192
196
 
193
197
  👉 For more details, see the [PR implementing this change](https://github.com/nuxt/nuxt/pull/27029).
@@ -218,7 +222,7 @@ You can also force a v3 folder structure with the following configuration:
218
222
  export default defineNuxtConfig({
219
223
  // This reverts the new srcDir default from `app` back to your root directory
220
224
  srcDir: '.',
221
- // This specifies the directory prefix for `app/router.options.ts` and `app/spa-loading-template.html`
225
+ // This specifies the directory prefix for `router.options.ts` and `spa-loading-template.html`
222
226
  dir: {
223
227
  app: 'app'
224
228
  }
@@ -430,7 +434,7 @@ export default defineNuxtConfig({
430
434
 
431
435
  #### What Changed
432
436
 
433
- When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `app/spa-loading-template.html`), within the Nuxt app root:
437
+ When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `~/app/spa-loading-template.html` - note that this has also changed to `~/spa-loading-template.html` in Nuxt 4), within the Nuxt app root:
434
438
 
435
439
  ```html
436
440
  <div id="__nuxt">
@@ -976,6 +980,93 @@ const importName = genSafeVariableName
976
980
  You can automate this step by running `npx codemod@latest nuxt/4/template-compilation-changes`
977
981
  ::
978
982
 
983
+ ### TypeScript Configuration Changes
984
+
985
+ 🚦 **Impact Level**: Minimal
986
+
987
+ #### What Changed
988
+
989
+ Nuxt now generates separate TypeScript configurations for different contexts to provide better type-checking experiences:
990
+
991
+ 1. **New TypeScript configuration files**: Nuxt now generates additional TypeScript configurations:
992
+ * `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
993
+ * `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
994
+ * `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
995
+ * `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
996
+
997
+ 2. **Backward compatibility**: Existing projects that extend `.nuxt/tsconfig.json` will continue to work as before.
998
+
999
+ 3. **Opt-in project references**: New projects or those wanting better type checking can adopt TypeScript's project references feature.
1000
+
1001
+ 4. **Context-specific type checking**: Each context now has appropriate compiler options and includes/excludes for its specific environment.
1002
+
1003
+ 5. **New `typescript.nodeTsConfig` option**: You can now customize the TypeScript configuration for Node.js build-time code.
1004
+
1005
+ #### Reasons for Change
1006
+
1007
+ This change provides several benefits:
1008
+
1009
+ 1. **Better type safety**: Each context (app, server, build-time) gets appropriate type checking with context-specific globals and APIs.
1010
+ 2. **Improved IDE experience**: Better IntelliSense and error reporting for different parts of your codebase.
1011
+ 3. **Cleaner separation**: Server code won't incorrectly suggest client-side APIs and vice versa.
1012
+ 4. **Performance**: TypeScript can more efficiently check code with properly scoped configurations.
1013
+
1014
+ For example, auto-imports are not available in your `nuxt.config.ts` (but previously this was not flagged by TypeScript). And while IDEs recognized the separate context hinted by `tsconfig.json` in your `server/` directory, this was not reflected in type-checking (requiring a separate step).
1015
+
1016
+ #### Migration Steps
1017
+
1018
+ **No migration is required** - existing projects will continue to work as before.
1019
+
1020
+ However, to take advantage of improved type checking, you can opt in to the new project references approach:
1021
+
1022
+ 1. **Update your root `tsconfig.json`** to use project references:
1023
+
1024
+ ```json
1025
+ {
1026
+ "files": [],
1027
+ "references": [
1028
+ { "path": "./.nuxt/tsconfig.app.json" },
1029
+ { "path": "./.nuxt/tsconfig.server.json" },
1030
+ { "path": "./.nuxt/tsconfig.node.json" }
1031
+ ]
1032
+ }
1033
+ ```
1034
+
1035
+ 2. **Remove any manual server `tsconfig.json`** files (like `server/tsconfig.json`) that extended `.nuxt/tsconfig.server.json`.
1036
+
1037
+ 3. **Update your type checking scripts** to use the build flag for project references:
1038
+
1039
+ ```diff
1040
+ - "typecheck": "nuxt prepare && vue-tsc --noEmit"
1041
+ + "typecheck": "nuxt prepare && vue-tsc -b --noEmit"
1042
+ ```
1043
+
1044
+ 4. **Configure Node.js TypeScript options** if needed:
1045
+ <!-- @case-police-ignore tsConfig -->
1046
+
1047
+ ```ts
1048
+ export default defineNuxtConfig({
1049
+ typescript: {
1050
+ // Customize app/server TypeScript config
1051
+ tsConfig: {
1052
+ compilerOptions: {
1053
+ strict: true
1054
+ }
1055
+ },
1056
+ // Customize build-time TypeScript config
1057
+ nodeTsConfig: {
1058
+ compilerOptions: {
1059
+ strict: true
1060
+ }
1061
+ }
1062
+ }
1063
+ })
1064
+ ```
1065
+
1066
+ 5. **Update any CI/build scripts** that run TypeScript checking to ensure they use the new project references approach.
1067
+
1068
+ The new configuration provides better type safety and IntelliSense for projects that opt in, while maintaining full backward compatibility for existing setups.
1069
+
979
1070
  ### Removal of Experimental Features
980
1071
 
981
1072
  🚦 **Impact Level**: Minimal
@@ -1000,6 +1091,44 @@ These options have been set to their current values for some time and we do not
1000
1091
 
1001
1092
  * `respectNoSSRHeader`is implementable in user-land with [server middleware](https://github.com/nuxt/nuxt/blob/c660b39447f0d5b8790c0826092638d321cd6821/packages/nuxt/src/core/runtime/nitro/no-ssr.ts#L8-L9)
1002
1093
 
1094
+ ### Removal of Top-Level `generate` Configuration
1095
+
1096
+ 🚦 **Impact Level**: Minimal
1097
+
1098
+ #### What Changed
1099
+
1100
+ The top-level `generate` configuration option is no longer available in Nuxt 4. This includes all of its properties:
1101
+
1102
+ * `generate.exclude` - for excluding routes from prerendering
1103
+ * `generate.routes` - for specifying routes to prerender
1104
+
1105
+ #### Reasons for Change
1106
+
1107
+ The top level `generate` configuration was a holdover from Nuxt 2. We've supported `nitro.prerender` for a while now, and it is the preferred way to configure prerendering in Nuxt 3+.
1108
+
1109
+ #### Migration Steps
1110
+
1111
+ Replace `generate` configuration with the corresponding `nitro.prerender` options:
1112
+
1113
+ ```diff
1114
+ export default defineNuxtConfig({
1115
+ - generate: {
1116
+ - exclude: ['/admin', '/private'],
1117
+ - routes: ['/sitemap.xml', '/robots.txt']
1118
+ - }
1119
+ + nitro: {
1120
+ + prerender: {
1121
+ + ignore: ['/admin', '/private'],
1122
+ + routes: ['/sitemap.xml', '/robots.txt']
1123
+ + }
1124
+ + }
1125
+ })
1126
+ ```
1127
+
1128
+ ::read-more{to="https://nitro.build/config/#prerender"}
1129
+ Read more about Nitro's prerender configuration options.
1130
+ ::
1131
+
1003
1132
  ## Nuxt 2 vs. Nuxt 3+
1004
1133
 
1005
1134
  In the table below, there is a quick comparison between 3 versions of Nuxt:
@@ -88,7 +88,7 @@ export default defineNuxtConfig({
88
88
  ```
89
89
 
90
90
  ::note
91
- If you do use `ssr: false`, you should also place an HTML file in `~/app/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
91
+ If you do use `ssr: false`, you should also place an HTML file in `~/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
92
92
  :read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
93
93
  ::
94
94
 
@@ -16,7 +16,7 @@ It is shipped with many features:
16
16
 
17
17
  ## API Layer
18
18
 
19
- Server [API endpoints](/docs/guide/directory-structure/server#api-routes) and [Middleware](/docs/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/unjs/h3).
19
+ Server [API endpoints](/docs/guide/directory-structure/server#api-routes) and [Middleware](/docs/guide/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
20
20
 
21
21
  Key features include:
22
22
 
@@ -24,7 +24,7 @@ Key features include:
24
24
  - Handlers can return promises, which will be awaited (`res.end()` and `next()` are also supported)
25
25
  - Helper functions for body parsing, cookie handling, redirects, headers and more
26
26
 
27
- Check out [the h3 docs](https://github.com/unjs/h3) for more information.
27
+ Check out [the h3 docs](https://github.com/h3js/h3) for more information.
28
28
 
29
29
  ::read-more{to="/docs/guide/directory-structure/server#server-routes"}
30
30
  Learn more about the API layer in the `server/` directory.
@@ -55,7 +55,7 @@ This file contains the types of any modules you are using, as well as the key ty
55
55
 
56
56
  Some of the references in the file are to files that are only generated within your `buildDir` (`.nuxt`) and therefore for full typings, you will need to run `nuxt dev` or `nuxt build`.
57
57
 
58
- ### `.nuxt/tsconfig.json`
58
+ ### `.nuxt/tsconfig.app.json`
59
59
 
60
60
  This file contains the recommended basic TypeScript configuration for your project, including resolved aliases injected by Nuxt or modules you are using, so you can get full type support and path auto-complete for aliases like `~/file` or `#build/file`.
61
61
 
@@ -74,10 +74,37 @@ Nitro also [auto-generates types](/docs/guide/concepts/server-engine#typed-api-r
74
74
  ::
75
75
 
76
76
  ::note
77
- Keep in mind that all options extended from `./.nuxt/tsconfig.json` will be overwritten by the options defined in your `tsconfig.json`.
78
- Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead TypeScript to not factor in the module resolutions from `./.nuxt/tsconfig.json`. This can lead to module resolutions such as `#imports` not being recognized.
79
- :br :br
80
- In case you need to extend options provided by `./.nuxt/tsconfig.json` further, you can use the [`alias` property](/docs/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend `./.nuxt/tsconfig.json` accordingly.
77
+ For backward compatibility, Nuxt still generates `./.nuxt/tsconfig.json`. However, we recommend using [TypeScript project references](/docs/guide/directory-structure/tsconfig) with the new configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, etc.) for better type safety and performance.
78
+
79
+ If you do extend from `./.nuxt/tsconfig.json`, keep in mind that all options will be overwritten by those defined in your `tsconfig.json`. Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead TypeScript to not factor in the module resolutions, which can cause module resolutions such as `#imports` to not be recognized.
80
+
81
+ In case you need to extend options further, you can use the [`alias` property](/docs/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend the generated TypeScript configurations accordingly.
82
+ ::
83
+
84
+ ## Project References
85
+
86
+ Nuxt uses [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) to improve type-checking performance and provide better IDE support. This feature allows TypeScript to break up your codebase into smaller, more manageable pieces.
87
+
88
+ ### How Nuxt Uses Project References
89
+
90
+ When you run `nuxt dev` or `nuxt build`, Nuxt will generate multiple `tsconfig.json` files for different parts of your application.
91
+
92
+ - **`.nuxt/tsconfig.app.json`** - Configuration for your application code
93
+ - **`.nuxt/tsconfig.node.json`** - Configuration for your `nuxt.config` and modules
94
+ - **`.nuxt/tsconfig.server.json`** - Configuration for server-side code (when applicable)
95
+ - **`.nuxt/tsconfig.json`** - Legacy configuration for backward compatibility
96
+
97
+ Each of these files is configured to reference the appropriate dependencies and provide optimal type-checking for their specific context.
98
+
99
+ ### Benefits of Project References
100
+
101
+ - **Faster builds**: TypeScript can skip rebuilding unchanged projects
102
+ - **Better IDE performance**: Your IDE can provide faster IntelliSense and error checking
103
+ - **Isolated compilation**: Errors in one part of your application don't prevent compilation of other parts
104
+ - **Clearer dependency management**: Each project explicitly declares its dependencies
105
+
106
+ ::note
107
+ The project reference setup is handled automatically by Nuxt. You typically don't need to modify these configurations manually, but understanding how they work can help you troubleshoot type-checking issues.
81
108
  ::
82
109
 
83
110
  ## Strict Checks
@@ -0,0 +1,5 @@
1
+ title: app
2
+ titleTemplate: '%s · Nuxt Directory Structure'
3
+ head.title: "app/"
4
+ defaultOpen: true
5
+ icon: i-lucide-folders
@@ -6,7 +6,7 @@ navigation.icon: i-lucide-folder
6
6
  ---
7
7
 
8
8
  ::note
9
- To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`app/router.options.ts`](/docs/guide/recipes/custom-routing#using-approuteroptions).
9
+ To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/guide/recipes/custom-routing#using-approuteroptions).
10
10
  ::
11
11
 
12
12
  ## Usage
@@ -101,7 +101,7 @@ export default defineNitroPlugin((nitroApp) => {
101
101
 
102
102
  ## Server Utilities
103
103
 
104
- Server routes are powered by [unjs/h3](https://github.com/unjs/h3) which comes with a handy set of helpers.
104
+ Server routes are powered by [h3js/h3](https://github.com/h3js/h3) which comes with a handy set of helpers.
105
105
 
106
106
  :read-more{to="https://www.jsdocs.io/package/h3#package-index-functions" title="Available H3 Request Helpers" target="_blank"}
107
107
 
@@ -136,16 +136,6 @@ export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
136
136
  This feature is available from Nuxt >= 3.5
137
137
  ::
138
138
 
139
- To improve clarity within your IDE between the auto-imports from 'nitro' and 'vue', you can add a `~/server/tsconfig.json` with the following content:
140
-
141
- ```json [server/tsconfig.json]
142
- {
143
- "extends": "../.nuxt/tsconfig.server.json"
144
- }
145
- ```
146
-
147
- Currently, these values won't be respected when type checking ([`nuxt typecheck`](/docs/api/commands/typecheck)), but you should get better type hints in your IDE.
148
-
149
139
  ## Recipes
150
140
 
151
141
  ### Route Parameters
@@ -448,7 +438,7 @@ export default fromNodeMiddleware((req, res) => {
448
438
  ```
449
439
 
450
440
  ::important
451
- Legacy support is possible using [unjs/h3](https://github.com/unjs/h3), but it is advised to avoid legacy handlers as much as you can.
441
+ Legacy support is possible using [h3js/h3](https://github.com/h3js/h3), but it is advised to avoid legacy handlers as much as you can.
452
442
  ::
453
443
 
454
444
  ```ts [server/middleware/legacy.ts]
@@ -1,17 +1,28 @@
1
1
  ---
2
2
  title: "tsconfig.json"
3
- description: "Nuxt generates a .nuxt/tsconfig.json file with sensible defaults and your aliases."
3
+ description: "Nuxt generates multiple TypeScript configuration files with sensible defaults and your aliases."
4
4
  head.title: "tsconfig.json"
5
5
  navigation.icon: i-lucide-file
6
6
  ---
7
7
 
8
- Nuxt [automatically generates](/docs/guide/concepts/typescript) a `.nuxt/tsconfig.json` file with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
8
+ Nuxt [automatically generates](/docs/guide/concepts/typescript) multiple TypeScript configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, `.nuxt/tsconfig.node.json`) with the resolved aliases you are using in your Nuxt project, as well as with other sensible defaults.
9
9
 
10
10
  You can benefit from this by creating a `tsconfig.json` in the root of your project with the following content:
11
11
 
12
12
  ```json [tsconfig.json]
13
13
  {
14
- "extends": "./.nuxt/tsconfig.json"
14
+ "files": [],
15
+ "references": [
16
+ {
17
+ "path": "./.nuxt/tsconfig.app.json"
18
+ },
19
+ {
20
+ "path": "./.nuxt/tsconfig.server.json"
21
+ },
22
+ {
23
+ "path": "./.nuxt/tsconfig.node.json"
24
+ }
25
+ ]
15
26
  }
16
27
  ```
17
28
 
@@ -386,6 +386,7 @@ package-lock.json
386
386
  yarn.lock
387
387
  pnpm-lock.yaml
388
388
  tsconfig.json
389
+ bun.lock
389
390
  bun.lockb
390
391
  ```
391
392
 
@@ -454,7 +455,7 @@ By setting `experimental.normalizeComponentNames`, these two values match, and V
454
455
 
455
456
  ## spaLoadingTemplateLocation
456
457
 
457
- When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `app/spa-loading-template.html`).
458
+ When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from `~/spa-loading-template.html`).
458
459
 
459
460
  It can be set to `within`, which will render it like this:
460
461
 
@@ -32,7 +32,7 @@ Update `nuxt` dependency inside `package.json`:
32
32
  }
33
33
  ```
34
34
 
35
- Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`) and reinstall dependencies.
35
+ Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock` or `bun.lockb`) and reinstall dependencies.
36
36
 
37
37
  ## Opting Out
38
38
 
@@ -47,7 +47,7 @@ Update `nuxt` dependency inside `package.json`:
47
47
  }
48
48
  ```
49
49
 
50
- Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`) and reinstall dependencies.
50
+ Remove lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock` or `bun.lockb`) and reinstall dependencies.
51
51
 
52
52
  ## Using Nightly `@nuxt/cli`
53
53
 
@@ -230,8 +230,6 @@ Learn more about asset injection in [the recipes section](#recipes).
230
230
  Published modules cannot leverage auto-imports for assets within their runtime directory. Instead, they have to import them explicitly from `#imports` or alike.
231
231
  :br :br
232
232
  Indeed, auto-imports are not enabled for files within `node_modules` (the location where a published module will eventually live) for performance reasons.
233
- :br :br
234
- If you are using the module starter, auto-imports will not be enabled in your playground either.
235
233
  ::
236
234
 
237
235
  ### Tooling
@@ -13,7 +13,7 @@ Using [router options](/docs/guide/recipes/custom-routing#router-options), you c
13
13
 
14
14
  If it returns `null` or `undefined`, Nuxt will fall back to the default routes (useful to modify input array).
15
15
 
16
- ```ts [app/router.options.ts]
16
+ ```ts [router.options.ts]
17
17
  import type { RouterConfig } from '@nuxt/schema'
18
18
 
19
19
  export default {
@@ -83,11 +83,11 @@ The [Nuxt kit](/docs/guide/going-further/kit) provides a few ways [to add routes
83
83
 
84
84
  On top of customizing options for [`vue-router`](https://router.vuejs.org/api/interfaces/routeroptions.html), Nuxt offers [additional options](/docs/api/nuxt-config#router) to customize the router.
85
85
 
86
- ### Using `app/router.options`
86
+ ### Using `router.options`
87
87
 
88
88
  This is the recommended way to specify [router options](/docs/api/nuxt-config#router).
89
89
 
90
- ```ts [app/router.options.ts]
90
+ ```ts [router.options.ts]
91
91
  import type { RouterConfig } from '@nuxt/schema'
92
92
 
93
93
  export default {
@@ -109,7 +109,7 @@ export default defineNuxtConfig({
109
109
  const resolver = createResolver(import.meta.url)
110
110
  // add a route
111
111
  files.push({
112
- path: resolver.resolve('./runtime/app/router-options'),
112
+ path: resolver.resolve('./runtime/router-options'),
113
113
  optional: true
114
114
  })
115
115
  }
@@ -170,7 +170,7 @@ export default defineNuxtConfig({
170
170
 
171
171
  You can optionally override history mode using a function that accepts the base URL and returns the history mode. If it returns `null` or `undefined`, Nuxt will fallback to the default history.
172
172
 
173
- ```ts [app/router.options.ts]
173
+ ```ts [router.options.ts]
174
174
  import type { RouterConfig } from '@nuxt/schema'
175
175
  import { createMemoryHistory } from 'vue-router'
176
176
 
@@ -51,6 +51,10 @@ In this example, we pass the `id` param to link to the route `~/pages/posts/[id]
51
51
  Check out the Pages panel in Nuxt DevTools to see the route name and the params it might take.
52
52
  ::
53
53
 
54
+ ::tip
55
+ When you pass an object into the `to` prop, `<NuxtLink>` will inherit Vue Router’s handling of query parameters. Keys and values will be automatically encoded, so you don’t need to call `encodeURI` or `encodeURIComponent` manually.
56
+ ::
57
+
54
58
  ### Handling Static File and Cross-App Links
55
59
 
56
60
  By default, `<NuxtLink>` uses Vue Router's client side navigation for relative route. When linking to static files in the `/public` directory or to another application hosted on the same domain, it might result in unexpected 404 errors because they are not part of the client routes. In such cases, you can use the `external` prop with `<NuxtLink>` to bypass Vue Router's internal routing mechanism.
@@ -12,23 +12,33 @@ links:
12
12
  This composable is available in Nuxt v3.12+.
13
13
  ::
14
14
 
15
- `onPrehydrate` is a composable lifecycle hook that allows you to run a callback on the client immediately before
16
- Nuxt hydrates the page.
17
-
15
+ `onPrehydrate` is a composable lifecycle hook that allows you to run a callback on the client immediately before Nuxt hydrates the page.
18
16
  ::note
19
17
  This is an advanced utility and should be used with care. For example, [`nuxt-time`](https://github.com/danielroe/nuxt-time/pull/251) and [`@nuxtjs/color-mode`](https://github.com/nuxt-modules/color-mode/blob/main/src/script.js) manipulate the DOM to avoid hydration mismatches.
20
18
  ::
21
19
 
22
20
  ## Usage
23
21
 
24
- `onPrehydrate` can be called directly in the setup function of a Vue component (for example, in `<script setup>`), or in a plugin.
25
- It will only have an effect when it is called on the server, and it will not be included in your client build.
22
+ Call `onPrehydrate` in the setup function of a Vue component (e.g., in `<script setup>`) or in a plugin. It only has an effect when called on the server and will not be included in your client build.
23
+
24
+ ## Type
25
+
26
+ ```ts [Signature]
27
+ export function onPrehydrate(callback: (el: HTMLElement) => void): void
28
+ export function onPrehydrate(callback: string | ((el: HTMLElement) => void), key?: string): undefined | string
29
+ ```
26
30
 
27
31
  ## Parameters
28
32
 
29
- - `callback`: A function that will be stringified and inlined in the HTML. It should not have any external
30
- dependencies (such as auto-imports) or refer to variables defined outside the callback. The callback will run
31
- before Nuxt runtime initializes so it should not rely on the Nuxt or Vue context.
33
+ | Parameter | Type | Required | Description |
34
+ | ---- | --- | --- | --- |
35
+ | `callback` | `((el: HTMLElement) => void) \| string` | Yes | A function (or stringified function) to run before Nuxt hydrates. It will be stringified and inlined in the HTML. Should not have external dependencies or reference variables outside the callback. Runs before Nuxt runtime initializes, so it should not rely on Nuxt or Vue context. |
36
+ | `key` | `string` | No | (Advanced) A unique key to identify the prehydrate script, useful for advanced scenarios like multiple root nodes. |
37
+
38
+ ## Return Values
39
+
40
+ - Returns `undefined` when called with only a callback function.
41
+ - Returns a string (the prehydrate id) when called with a callback and a key, which can be used to set or access the `data-prehydrate-id` attribute for advanced use cases.
32
42
 
33
43
  ## Example
34
44
 
@@ -36,19 +46,18 @@ before Nuxt runtime initializes so it should not rely on the Nuxt or Vue context
36
46
  <script setup lang="ts">
37
47
  declare const window: Window
38
48
  // ---cut---
39
- // onPrehydrate is guaranteed to run before Nuxt hydrates
49
+ // Run code before Nuxt hydrates
40
50
  onPrehydrate(() => {
41
51
  console.log(window)
42
52
  })
43
53
 
44
- // As long as it only has one root node, you can access the element
54
+ // Access the root element
45
55
  onPrehydrate((el) => {
46
56
  console.log(el.outerHTML)
47
57
  // <div data-v-inspector="app.vue:15:3" data-prehydrate-id=":b3qlvSiBeH:"> Hi there </div>
48
58
  })
49
59
 
50
- // For _very_ advanced use cases (such as not having a single root node) you
51
- // can access/set `data-prehydrate-id` yourself
60
+ // Advanced: access/set `data-prehydrate-id` yourself
52
61
  const prehydrateId = onPrehydrate((el) => {})
53
62
  </script>
54
63
 
@@ -154,7 +154,7 @@ const { data: users2 } = useAsyncData('users', () => $fetch('/api/users'), { imm
154
154
  - `pending`: the request is in progress
155
155
  - `success`: the request has completed successfully
156
156
  - `error`: the request has failed
157
- - `clear`: a function which will set `data` to `undefined`, set `error` to `null`, set `status` to `'idle'`, and mark any currently pending requests as cancelled.
157
+ - `clear`: a function that can be used to set `data` to `undefined` (or the value of `options.default()` if provided), set `error` to `undefined`, set `status` to `idle`, and mark any currently pending requests as cancelled.
158
158
 
159
159
  By default, Nuxt waits until a `refresh` is finished before it can be executed again.
160
160