@nuxt/docs 3.20.2 → 3.21.1
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.
- package/1.getting-started/01.introduction.md +4 -4
- package/1.getting-started/02.installation.md +4 -7
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +6 -4
- package/1.getting-started/05.assets.md +2 -2
- package/1.getting-started/06.styling.md +22 -16
- package/1.getting-started/07.routing.md +6 -6
- package/1.getting-started/08.seo-meta.md +8 -4
- package/1.getting-started/09.transitions.md +6 -6
- package/1.getting-started/10.data-fetching.md +18 -18
- package/1.getting-started/11.state-management.md +5 -5
- package/1.getting-started/12.error-handling.md +25 -19
- package/1.getting-started/13.server.md +9 -9
- package/1.getting-started/14.layers.md +49 -15
- package/1.getting-started/15.prerendering.md +18 -4
- package/1.getting-started/16.deployment.md +2 -1
- package/1.getting-started/17.testing.md +17 -7
- package/1.getting-started/18.upgrade.md +111 -60
- package/2.directory-structure/0.output.md +1 -1
- package/2.directory-structure/1.assets.md +1 -1
- package/2.directory-structure/1.components.md +12 -8
- package/2.directory-structure/1.composables.md +2 -2
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +87 -0
- package/2.directory-structure/1.layouts.md +35 -3
- package/2.directory-structure/1.middleware.md +7 -7
- package/2.directory-structure/1.modules.md +8 -2
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.pages.md +39 -18
- package/2.directory-structure/1.plugins.md +4 -1
- package/2.directory-structure/1.public.md +1 -1
- package/2.directory-structure/1.server.md +28 -8
- package/2.directory-structure/1.shared.md +3 -3
- package/2.directory-structure/1.utils.md +2 -2
- package/2.directory-structure/2.env.md +3 -3
- package/2.directory-structure/2.nuxtignore.md +1 -0
- package/2.directory-structure/2.nuxtrc.md +5 -2
- package/2.directory-structure/3.app-config.md +2 -2
- package/2.directory-structure/3.app.md +3 -3
- package/2.directory-structure/3.error.md +9 -5
- package/2.directory-structure/3.nuxt-config.md +1 -1
- package/2.directory-structure/3.package.md +1 -1
- package/2.directory-structure/3.tsconfig.md +3 -2
- package/2.directory-structure/index.md +12 -8
- package/3.guide/0.index.md +5 -2
- package/3.guide/1.concepts/{3.rendering.md → 1.rendering.md} +11 -32
- package/3.guide/1.concepts/{2.vuejs-development.md → 10.vuejs-development.md} +9 -8
- package/3.guide/1.concepts/{10.nuxt-lifecycle.md → 2.nuxt-lifecycle.md} +31 -24
- package/3.guide/1.concepts/{1.auto-imports.md → 3.auto-imports.md} +6 -6
- package/3.guide/1.concepts/4.server-engine.md +2 -2
- package/3.guide/1.concepts/5.modules.md +14 -1
- package/3.guide/1.concepts/7.esm.md +5 -4
- package/3.guide/1.concepts/8.typescript.md +9 -15
- package/3.guide/1.concepts/9.code-style.md +1 -1
- package/3.guide/2.best-practices/hydration.md +1 -1
- package/3.guide/2.best-practices/performance.md +5 -5
- package/3.guide/3.ai/.navigation.yml +3 -0
- package/3.guide/3.ai/1.mcp.md +277 -0
- package/3.guide/3.ai/2.llms-txt.md +65 -0
- package/3.guide/4.modules/.navigation.yml +3 -0
- package/3.guide/4.modules/1.getting-started.md +103 -0
- package/3.guide/4.modules/2.module-anatomy.md +138 -0
- package/3.guide/4.modules/3.recipes-basics.md +420 -0
- package/3.guide/4.modules/4.recipes-advanced.md +243 -0
- package/3.guide/4.modules/5.testing.md +76 -0
- package/3.guide/4.modules/6.best-practices.md +104 -0
- package/3.guide/4.modules/7.ecosystem.md +32 -0
- package/3.guide/4.modules/index.md +36 -0
- package/3.guide/{3.recipes → 5.recipes}/1.custom-routing.md +3 -3
- package/3.guide/{3.recipes → 5.recipes}/2.vite-plugin.md +4 -0
- package/3.guide/{3.recipes → 5.recipes}/3.custom-usefetch.md +2 -2
- package/3.guide/{3.recipes → 5.recipes}/4.sessions-and-authentication.md +3 -3
- package/3.guide/{4.going-further → 6.going-further}/1.events.md +3 -4
- package/3.guide/{4.going-further → 6.going-further}/1.experimental-features.md +211 -86
- package/3.guide/6.going-further/1.features.md +108 -0
- package/3.guide/{4.going-further → 6.going-further}/1.internals.md +4 -3
- package/3.guide/{4.going-further → 6.going-further}/10.runtime-config.md +2 -2
- package/3.guide/{4.going-further → 6.going-further}/11.nightly-release-channel.md +1 -1
- package/3.guide/{4.going-further → 6.going-further}/2.hooks.md +5 -5
- package/3.guide/{4.going-further → 6.going-further}/4.kit.md +3 -3
- package/3.guide/{4.going-further → 6.going-further}/6.nuxt-app.md +6 -6
- package/3.guide/{4.going-further → 6.going-further}/7.layers.md +31 -5
- package/3.guide/{4.going-further → 6.going-further}/9.debugging.md +3 -2
- package/4.api/1.components/1.nuxt-client-fallback.md +5 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +2 -2
- package/4.api/1.components/12.nuxt-route-announcer.md +0 -2
- package/4.api/1.components/13.nuxt-time.md +0 -2
- package/4.api/1.components/2.nuxt-page.md +3 -3
- package/4.api/1.components/3.nuxt-layout.md +6 -6
- package/4.api/1.components/4.nuxt-link.md +13 -13
- package/4.api/1.components/5.nuxt-loading-indicator.md +1 -1
- package/4.api/1.components/6.nuxt-error-boundary.md +2 -2
- package/4.api/1.components/7.nuxt-welcome.md +2 -2
- package/4.api/1.components/8.nuxt-island.md +9 -2
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +5 -5
- package/4.api/2.composables/use-cookie.md +16 -16
- package/4.api/2.composables/use-error.md +3 -3
- package/4.api/2.composables/use-fetch.md +37 -37
- package/4.api/2.composables/use-head-safe.md +1 -1
- package/4.api/2.composables/use-head.md +22 -7
- package/4.api/2.composables/use-lazy-async-data.md +1 -1
- package/4.api/2.composables/use-lazy-fetch.md +9 -9
- package/4.api/2.composables/use-nuxt-app.md +9 -7
- package/4.api/2.composables/use-route-announcer.md +1 -3
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +15 -15
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-seo-meta.md +2 -2
- package/4.api/2.composables/use-server-seo-meta.md +2 -2
- package/4.api/2.composables/use-state.md +12 -2
- package/4.api/3.utils/$fetch.md +1 -1
- package/4.api/3.utils/abort-navigation.md +2 -2
- package/4.api/3.utils/call-once.md +2 -4
- package/4.api/3.utils/clear-error.md +1 -1
- package/4.api/3.utils/create-error.md +7 -7
- package/4.api/3.utils/define-lazy-hydration-component.md +5 -5
- package/4.api/3.utils/define-nuxt-component.md +1 -1
- package/4.api/3.utils/define-nuxt-plugin.md +12 -12
- package/4.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/4.api/3.utils/define-page-meta.md +18 -11
- package/4.api/3.utils/define-route-rules.md +2 -2
- package/4.api/3.utils/navigate-to.md +14 -14
- package/4.api/3.utils/on-before-route-leave.md +1 -1
- package/4.api/3.utils/on-before-route-update.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/refresh-cookie.md +0 -2
- package/4.api/3.utils/refresh-nuxt-data.md +1 -1
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +36 -0
- package/4.api/3.utils/set-response-status.md +3 -3
- package/4.api/3.utils/show-error.md +4 -4
- package/4.api/3.utils/update-app-config.md +1 -1
- package/4.api/4.commands/add.md +12 -12
- package/4.api/4.commands/analyze.md +11 -11
- package/4.api/4.commands/build-module.md +11 -11
- package/4.api/4.commands/build.md +12 -12
- package/4.api/4.commands/cleanup.md +6 -6
- package/4.api/4.commands/dev.md +23 -23
- package/4.api/4.commands/devtools.md +7 -7
- package/4.api/4.commands/generate.md +12 -12
- package/4.api/4.commands/info.md +6 -6
- package/4.api/4.commands/init.md +18 -18
- package/4.api/4.commands/module.md +18 -18
- package/4.api/4.commands/prepare.md +10 -10
- package/4.api/4.commands/preview.md +11 -11
- package/4.api/4.commands/test.md +9 -9
- package/4.api/4.commands/typecheck.md +10 -10
- package/4.api/4.commands/upgrade.md +10 -10
- package/4.api/5.kit/1.modules.md +31 -18
- package/4.api/5.kit/10.templates.md +23 -23
- package/4.api/5.kit/11.nitro.md +40 -36
- package/4.api/5.kit/12.resolving.md +2 -2
- package/4.api/5.kit/14.builder.md +35 -23
- package/4.api/5.kit/16.layers.md +16 -16
- package/4.api/5.kit/2.programmatic.md +2 -2
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +23 -19
- package/4.api/5.kit/5.components.md +35 -35
- package/4.api/5.kit/6.context.md +1 -1
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +85 -85
- package/4.api/index.md +7 -7
- package/5.community/4.contribution.md +10 -10
- package/5.community/5.framework-contribution.md +9 -9
- package/5.community/6.roadmap.md +26 -26
- package/5.community/7.changelog.md +10 -0
- package/6.bridge/1.overview.md +8 -0
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +2 -2
- package/6.bridge/5.nuxt3-compatible-api.md +1 -1
- package/6.bridge/8.nitro.md +4 -0
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +5 -5
- package/7.migration/20.module-authors.md +3 -3
- package/7.migration/4.meta.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +5 -5
- package/7.migration/7.component-options.md +6 -6
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
- package/3.guide/4.going-further/1.features.md +0 -103
- package/3.guide/4.going-further/3.modules.md +0 -901
- /package/3.guide/{3.recipes → 5.recipes}/.navigation.yml +0 -0
- /package/3.guide/{4.going-further → 6.going-further}/.navigation.yml +0 -0
- /package/3.guide/{4.going-further → 6.going-further}/index.md +0 -0
|
@@ -6,6 +6,35 @@ navigation.icon: i-lucide-circle-arrow-up
|
|
|
6
6
|
|
|
7
7
|
## Upgrading Nuxt
|
|
8
8
|
|
|
9
|
+
### Latest Nuxt 3 release
|
|
10
|
+
|
|
11
|
+
To upgrade Nuxt to the [latest v3 release](https://github.com/nuxt/nuxt/releases), use the `nuxt upgrade` command with `--channel=v3` flag.
|
|
12
|
+
|
|
13
|
+
::code-group{sync="pm"}
|
|
14
|
+
|
|
15
|
+
```bash [npm]
|
|
16
|
+
npx nuxt upgrade --dedupe --channel=v3
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash [yarn]
|
|
20
|
+
yarn nuxt upgrade --dedupe --channel=v3
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```bash [pnpm]
|
|
24
|
+
pnpm nuxt upgrade --dedupe --channel=v3
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```bash [bun]
|
|
28
|
+
bun x nuxt upgrade --dedupe --channel=v3
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
::
|
|
32
|
+
|
|
33
|
+
::note
|
|
34
|
+
This will only work if you _already have_ a version of `@nuxt/cli` which has the `--channel` flag implemented. If this does not work, you can instead use `nuxi@latest` for the initial upgrade.
|
|
35
|
+
E.g. `npx nuxi@latest upgrade --dedupe --channel=v3`
|
|
36
|
+
::
|
|
37
|
+
|
|
9
38
|
### Latest release
|
|
10
39
|
|
|
11
40
|
To upgrade Nuxt to the [latest release](https://github.com/nuxt/nuxt/releases), use the `nuxt upgrade` command.
|
|
@@ -28,6 +57,10 @@ pnpm nuxt upgrade
|
|
|
28
57
|
bun x nuxt upgrade
|
|
29
58
|
```
|
|
30
59
|
|
|
60
|
+
```bash [deno]
|
|
61
|
+
deno x nuxt upgrade
|
|
62
|
+
```
|
|
63
|
+
|
|
31
64
|
::
|
|
32
65
|
|
|
33
66
|
### Nightly Release Channel
|
|
@@ -99,46 +132,47 @@ For now, you need to define the compatibility version in each layer that opts in
|
|
|
99
132
|
|
|
100
133
|
When you set your `compatibilityVersion` to `4`, defaults throughout your Nuxt configuration will change to opt in to Nuxt v4 behavior, but you can granularly re-enable Nuxt v3 behavior when testing, following the commented out lines above. Please file issues if so, so that we can address them in Nuxt or in the ecosystem.
|
|
101
134
|
|
|
102
|
-
Breaking or significant changes
|
|
103
|
-
|
|
104
|
-
::note
|
|
105
|
-
This section is subject to change until the final release, so please check back here regularly if you are testing Nuxt 4 using `compatibilityVersion: 4`.
|
|
106
|
-
::
|
|
135
|
+
Breaking or significant changes are documented below along with migration steps and available configuration options.
|
|
107
136
|
|
|
108
137
|
### Migrating Using Codemods
|
|
109
138
|
|
|
110
|
-
To facilitate the upgrade process, we have collaborated with the [Codemod](https://github.com/codemod
|
|
139
|
+
To facilitate the upgrade process, we have collaborated with the [Codemod](https://github.com/codemod/codemod) team to automate many migration steps with some open-source codemods.
|
|
111
140
|
|
|
112
141
|
::note
|
|
113
142
|
If you encounter any issues, please report them to the Codemod team with `npx codemod feedback` 🙏
|
|
114
143
|
::
|
|
115
144
|
|
|
116
|
-
For a complete list of Nuxt 4 codemods, detailed information on each, their source, and various ways to run them, visit the [Codemod Registry](https://
|
|
145
|
+
For a complete list of Nuxt 4 codemods, detailed information on each, their source, and various ways to run them, visit the [Codemod Registry](https://app.codemod.com/registry).
|
|
117
146
|
|
|
118
147
|
You can run all the codemods mentioned in this guide using the following `codemod` recipe:
|
|
119
148
|
|
|
120
149
|
::code-group
|
|
121
150
|
|
|
122
151
|
```bash [npm]
|
|
123
|
-
# Using pinned version due to https://github.com/codemod
|
|
152
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
124
153
|
npx codemod@0.18.7 nuxt/4/migration-recipe
|
|
125
154
|
```
|
|
126
155
|
|
|
127
156
|
```bash [yarn]
|
|
128
|
-
# Using pinned version due to https://github.com/codemod
|
|
157
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
129
158
|
yarn dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
130
159
|
```
|
|
131
160
|
|
|
132
161
|
```bash [pnpm]
|
|
133
|
-
# Using pinned version due to https://github.com/codemod
|
|
162
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
134
163
|
pnpm dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
135
164
|
```
|
|
136
165
|
|
|
137
166
|
```bash [bun]
|
|
138
|
-
# Using pinned version due to https://github.com/codemod
|
|
167
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
139
168
|
bun x codemod@0.18.7 nuxt/4/migration-recipe
|
|
140
169
|
```
|
|
141
170
|
|
|
171
|
+
```bash [deno]
|
|
172
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
173
|
+
deno x codemod@0.18.7 nuxt/4/migration-recipe
|
|
174
|
+
```
|
|
175
|
+
|
|
142
176
|
::
|
|
143
177
|
|
|
144
178
|
This command will execute all codemods in sequence, with the option to deselect any that you do not wish to run. Each codemod is also listed below alongside its respective change and can be executed independently.
|
|
@@ -153,11 +187,11 @@ Nuxt now defaults to a new directory structure, with backwards compatibility (so
|
|
|
153
187
|
|
|
154
188
|
#### What Changed
|
|
155
189
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
190
|
+
- the new Nuxt default `srcDir` is `app/` by default, and most things are resolved from there.
|
|
191
|
+
- `serverDir` now defaults to `<rootDir>/server` rather than `<srcDir>/server`
|
|
192
|
+
- `layers/`, `modules/` and `public/` are resolved relative to `<rootDir>` by default
|
|
193
|
+
- if using [Nuxt Content v2.13+](https://github.com/nuxt/content/pull/2649), `content/` is resolved relative to `<rootDir>`
|
|
194
|
+
- a new `dir.app` is added, which is the directory we look for `router.options.ts` and `spa-loading-template.html` - this defaults to `<srcDir>/`
|
|
161
195
|
|
|
162
196
|
<details>
|
|
163
197
|
|
|
@@ -193,6 +227,10 @@ server/
|
|
|
193
227
|
nuxt.config.ts
|
|
194
228
|
```
|
|
195
229
|
|
|
230
|
+
::note
|
|
231
|
+
With this new structure, the `~` alias now points to the `app/` directory by default (your `srcDir`). This means `~/components` resolves to `components/`, `~/pages` to `pages/`, etc.
|
|
232
|
+
::
|
|
233
|
+
|
|
196
234
|
</details>
|
|
197
235
|
|
|
198
236
|
👉 For more details, see the [PR implementing this change](https://github.com/nuxt/nuxt/pull/27029).
|
|
@@ -318,15 +356,15 @@ Now modules are loaded in the correct order:
|
|
|
318
356
|
2. **Project modules last** (highest priority)
|
|
319
357
|
|
|
320
358
|
This affects both:
|
|
321
|
-
|
|
322
|
-
|
|
359
|
+
- Modules defined in the `modules` array in `nuxt.config.ts`
|
|
360
|
+
- Auto-discovered modules from the `modules/` directory
|
|
323
361
|
|
|
324
362
|
#### Reasons for Change
|
|
325
363
|
|
|
326
364
|
This change ensures that:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
365
|
+
- Extended layers have lower priority than the consuming project
|
|
366
|
+
- Module execution order matches the intuitive layer inheritance pattern
|
|
367
|
+
- Module configuration and hooks work as expected in multi-layer setups
|
|
330
368
|
|
|
331
369
|
#### Migration Steps
|
|
332
370
|
|
|
@@ -358,7 +396,7 @@ export default defineNuxtConfig({
|
|
|
358
396
|
// 4. project-module-2 (can override layer modules)
|
|
359
397
|
```
|
|
360
398
|
|
|
361
|
-
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/3.x/guide/
|
|
399
|
+
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/3.x/guide/modules#custom-hooks) for modules that need to call a hook. This is run after all other modules have been loaded, which means it is safe to use.
|
|
362
400
|
|
|
363
401
|
👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
|
|
364
402
|
|
|
@@ -433,9 +471,9 @@ export default defineNuxtConfig({
|
|
|
433
471
|
[Unhead](https://unhead.unjs.io/), used to generate `<head>` tags, has been updated to version 2. While mostly compatible it includes several breaking changes
|
|
434
472
|
for lower-level APIs.
|
|
435
473
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
474
|
+
- Removed props: `vmid`, `hid`, `children`, `body`.
|
|
475
|
+
- Promise input no longer supported.
|
|
476
|
+
- Tags are now sorted using Capo.js by default.
|
|
439
477
|
|
|
440
478
|
#### Migration Steps
|
|
441
479
|
|
|
@@ -443,7 +481,7 @@ The above changes should have minimal impact on your app.
|
|
|
443
481
|
|
|
444
482
|
If you have issues you should verify:
|
|
445
483
|
|
|
446
|
-
|
|
484
|
+
- You're not using any of the removed props.
|
|
447
485
|
|
|
448
486
|
```diff
|
|
449
487
|
useHead({
|
|
@@ -456,7 +494,7 @@ useHead({
|
|
|
456
494
|
})
|
|
457
495
|
```
|
|
458
496
|
|
|
459
|
-
|
|
497
|
+
- If you're using [Template Params](https://unhead.unjs.io/docs/head/guides/plugins/template-params) or [Alias Tag Sorting](https://unhead.unjs.io/docs/head/guides/plugins/alias-sorting), you will need to explicitly opt in to these features now.
|
|
460
498
|
|
|
461
499
|
```ts
|
|
462
500
|
import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
|
|
@@ -493,7 +531,7 @@ export default defineNuxtConfig({
|
|
|
493
531
|
|
|
494
532
|
#### What Changed
|
|
495
533
|
|
|
496
|
-
When rendering a client-only page (with `ssr: false`), we optionally render a loading screen (from
|
|
534
|
+
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:
|
|
497
535
|
|
|
498
536
|
```html
|
|
499
537
|
<div id="__nuxt">
|
|
@@ -638,7 +676,7 @@ For example, if your site requires a `useFetch` call for every page (for example
|
|
|
638
676
|
|
|
639
677
|
Make sure that any unique key of your data is always resolvable to the same data. For example, if you are using `useAsyncData` to fetch data related to a particular page, you should provide a key that uniquely matches that data. (`useFetch` should do this automatically for you.)
|
|
640
678
|
|
|
641
|
-
```ts [
|
|
679
|
+
```ts [pages/test/[slug\\].vue]
|
|
642
680
|
// This would be unsafe in a dynamic page (e.g. `[slug].vue`) because the route slug makes a difference
|
|
643
681
|
// to the data fetched, but Nuxt can't know that because it's not reflected in the key.
|
|
644
682
|
const route = useRoute()
|
|
@@ -989,15 +1027,15 @@ In Nuxt v3 we moved to a 'virtual' syntax with a `getContents()` function which
|
|
|
989
1027
|
|
|
990
1028
|
In addition, `lodash/template` has had a succession of security issues. These do not really apply to Nuxt projects because it is being used at build-time, not runtime, and by trusted code. However, they still appear in security audits. Moreover, `lodash` is a hefty dependency and is unused by most projects.
|
|
991
1029
|
|
|
992
|
-
Finally, providing code serialization functions directly within Nuxt is not ideal. Instead, we maintain projects like [unjs/knitwork](
|
|
1030
|
+
Finally, providing code serialization functions directly within Nuxt is not ideal. Instead, we maintain projects like [unjs/knitwork](https://github.com/unjs/knitwork) which can be dependencies of your project, and where security issues can be reported/resolved directly without requiring an upgrade of Nuxt itself.
|
|
993
1031
|
|
|
994
1032
|
#### Migration Steps
|
|
995
1033
|
|
|
996
1034
|
We have raised PRs to update modules using EJS syntax, but if you need to do this yourself, you have three backwards/forwards-compatible alternatives:
|
|
997
1035
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1036
|
+
- Moving your string interpolation logic directly into `getContents()`.
|
|
1037
|
+
- Using a custom function to handle the replacement, such as in https://github.com/nuxt-modules/color-mode/pull/240.
|
|
1038
|
+
- Use `es-toolkit/compat` (a drop-in replacement for lodash template), as a dependency of _your_ project rather than Nuxt:
|
|
1001
1039
|
|
|
1002
1040
|
```diff
|
|
1003
1041
|
+ import { readFileSync } from 'node:fs'
|
|
@@ -1080,11 +1118,11 @@ There are two approaches:
|
|
|
1080
1118
|
Nuxt now generates separate TypeScript configurations for different contexts to provide better type-checking experiences:
|
|
1081
1119
|
|
|
1082
1120
|
1. **New TypeScript configuration files**: Nuxt now generates additional TypeScript configurations:
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1121
|
+
- `.nuxt/tsconfig.app.json` - For your app code (Vue components, composables, etc.)
|
|
1122
|
+
- `.nuxt/tsconfig.server.json` - For your server-side code (Nitro/server directory)
|
|
1123
|
+
- `.nuxt/tsconfig.node.json` - For your build-time code (modules, `nuxt.config.ts`, etc.)
|
|
1124
|
+
- `.nuxt/tsconfig.shared.json` - For code shared between app and server contexts (like types and non-environment specific utilities)
|
|
1125
|
+
- `.nuxt/tsconfig.json` - Legacy configuration for backward compatibility
|
|
1088
1126
|
|
|
1089
1127
|
2. **Backward compatibility**: Existing projects that extend `.nuxt/tsconfig.json` will continue to work as before.
|
|
1090
1128
|
|
|
@@ -1113,8 +1151,13 @@ However, to take advantage of improved type checking, you can opt in to the new
|
|
|
1113
1151
|
|
|
1114
1152
|
1. **Update your root `tsconfig.json`** to use project references:
|
|
1115
1153
|
|
|
1154
|
+
::note
|
|
1155
|
+
If your `tsconfig.json` currently has an `"extends": "./.nuxt/tsconfig.json"` line, **remove it** before adding the references. Project references and extends are mutually exclusive.
|
|
1156
|
+
::
|
|
1157
|
+
|
|
1116
1158
|
```json
|
|
1117
1159
|
{
|
|
1160
|
+
// Remove "extends": "./.nuxt/tsconfig.json" if present
|
|
1118
1161
|
"files": [],
|
|
1119
1162
|
"references": [
|
|
1120
1163
|
{ "path": "./.nuxt/tsconfig.app.json" },
|
|
@@ -1135,30 +1178,38 @@ However, to take advantage of improved type checking, you can opt in to the new
|
|
|
1135
1178
|
```
|
|
1136
1179
|
|
|
1137
1180
|
4. **Move all type augmentations into their appropriate context**:
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1181
|
+
- If you are augmenting types for the app context, move the files to the `app/` directory.
|
|
1182
|
+
- If you are augmenting types for the server context, move the files to the `server/` directory.
|
|
1183
|
+
- If you are augmenting types that are **shared between the app and server**, move the files to the `shared/` directory.
|
|
1141
1184
|
|
|
1142
1185
|
::warning
|
|
1143
1186
|
Augmenting types from outside the `app/`, `server/`, or `shared/` directories will not work with the new project references setup.
|
|
1144
1187
|
::
|
|
1145
1188
|
|
|
1146
|
-
5. **Configure
|
|
1189
|
+
5. **Configure TypeScript options** if needed:
|
|
1147
1190
|
<!-- @case-police-ignore tsConfig -->
|
|
1148
1191
|
|
|
1149
1192
|
```ts
|
|
1150
1193
|
export default defineNuxtConfig({
|
|
1151
1194
|
typescript: {
|
|
1152
|
-
//
|
|
1195
|
+
// customize tsconfig.app.json
|
|
1153
1196
|
tsConfig: {
|
|
1154
|
-
|
|
1155
|
-
strict: true,
|
|
1156
|
-
},
|
|
1197
|
+
// ...
|
|
1157
1198
|
},
|
|
1158
|
-
//
|
|
1199
|
+
// customize tsconfig.shared.json
|
|
1200
|
+
sharedTsConfig: {
|
|
1201
|
+
// ...
|
|
1202
|
+
},
|
|
1203
|
+
// customize tsconfig.node.json
|
|
1159
1204
|
nodeTsConfig: {
|
|
1160
|
-
|
|
1161
|
-
|
|
1205
|
+
// ...
|
|
1206
|
+
},
|
|
1207
|
+
},
|
|
1208
|
+
nitro: {
|
|
1209
|
+
typescript: {
|
|
1210
|
+
// customize tsconfig.server.json
|
|
1211
|
+
tsConfig: {
|
|
1212
|
+
// ...
|
|
1162
1213
|
},
|
|
1163
1214
|
},
|
|
1164
1215
|
},
|
|
@@ -1177,11 +1228,11 @@ The new configuration provides better type safety and IntelliSense for projects
|
|
|
1177
1228
|
|
|
1178
1229
|
Four experimental features are no longer configurable in Nuxt 4:
|
|
1179
1230
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1231
|
+
- `experimental.treeshakeClientOnly` will be `true` (default since v3.0)
|
|
1232
|
+
- `experimental.configSchema` will be `true` (default since v3.3)
|
|
1233
|
+
- `experimental.polyfillVueUseHead` will be `false` (default since v3.4)
|
|
1234
|
+
- `experimental.respectNoSSRHeader` will be `false` (default since v3.4)
|
|
1235
|
+
- `vite.devBundler` is no longer configurable - it will use `vite-node` by default
|
|
1185
1236
|
|
|
1186
1237
|
#### Reasons for Change
|
|
1187
1238
|
|
|
@@ -1189,9 +1240,9 @@ These options have been set to their current values for some time and we do not
|
|
|
1189
1240
|
|
|
1190
1241
|
#### Migration Steps
|
|
1191
1242
|
|
|
1192
|
-
|
|
1243
|
+
- `polyfillVueUseHead` is implementable in user-land with [this plugin](https://github.com/nuxt/nuxt/blob/f209158352b09d1986aa320e29ff36353b91c358/packages/nuxt/src/head/runtime/plugins/vueuse-head-polyfill.ts#L10-L11)
|
|
1193
1244
|
|
|
1194
|
-
|
|
1245
|
+
- `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)
|
|
1195
1246
|
|
|
1196
1247
|
### Removal of Top-Level `generate` Configuration
|
|
1197
1248
|
|
|
@@ -1201,8 +1252,8 @@ These options have been set to their current values for some time and we do not
|
|
|
1201
1252
|
|
|
1202
1253
|
The top-level `generate` configuration option is no longer available in Nuxt 4. This includes all of its properties:
|
|
1203
1254
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1255
|
+
- `generate.exclude` - for excluding routes from prerendering
|
|
1256
|
+
- `generate.routes` - for specifying routes to prerender
|
|
1206
1257
|
|
|
1207
1258
|
#### Reasons for Change
|
|
1208
1259
|
|
|
@@ -1257,7 +1308,7 @@ Static sites | ✅ | ✅ | ✅
|
|
|
1257
1308
|
|
|
1258
1309
|
The migration guide provides a step-by-step comparison of Nuxt 2 features to Nuxt 3+ features and guidance to adapt your current application.
|
|
1259
1310
|
|
|
1260
|
-
::read-more{to="/docs/migration/overview"}
|
|
1311
|
+
::read-more{to="/docs/3.x/migration/overview"}
|
|
1261
1312
|
Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
1262
1313
|
::
|
|
1263
1314
|
|
|
@@ -1265,6 +1316,6 @@ Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
|
1265
1316
|
|
|
1266
1317
|
If you prefer to progressively migrate your Nuxt 2 application to Nuxt 3, you can use Nuxt Bridge. Nuxt Bridge is a compatibility layer that allows you to use Nuxt 3+ features in Nuxt 2 with an opt-in mechanism.
|
|
1267
1318
|
|
|
1268
|
-
::read-more{to="/docs/bridge/overview"}
|
|
1319
|
+
::read-more{to="/docs/3.x/bridge/overview"}
|
|
1269
1320
|
**Migrate from Nuxt 2 to Nuxt Bridge**
|
|
1270
1321
|
::
|
|
@@ -11,7 +11,7 @@ This directory should be added to your [`.gitignore`](/docs/3.x/directory-struct
|
|
|
11
11
|
|
|
12
12
|
Use this directory to deploy your Nuxt application to production.
|
|
13
13
|
|
|
14
|
-
:read-more{to="/docs/getting-started/deployment"}
|
|
14
|
+
:read-more{to="/docs/3.x/getting-started/deployment"}
|
|
15
15
|
|
|
16
16
|
::warning
|
|
17
17
|
You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/3.x/api/commands/build).
|
|
@@ -13,4 +13,4 @@ The directory usually contains the following types of files:
|
|
|
13
13
|
|
|
14
14
|
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/3.x/directory-structure/public) directory.
|
|
15
15
|
|
|
16
|
-
:read-more{to="/docs/getting-started/assets"}
|
|
16
|
+
:read-more{to="/docs/3.x/getting-started/assets"}
|
|
@@ -163,7 +163,7 @@ Read more about the options for `hydrate-on-visible`.
|
|
|
163
163
|
::
|
|
164
164
|
|
|
165
165
|
::note
|
|
166
|
-
Under the hood, this uses Vue's built-in [`hydrateOnVisible` strategy](https://vuejs.org/guide/components/async
|
|
166
|
+
Under the hood, this uses Vue's built-in [`hydrateOnVisible` strategy](https://vuejs.org/guide/components/async#hydrate-on-visible).
|
|
167
167
|
::
|
|
168
168
|
|
|
169
169
|
#### `hydrate-on-idle`
|
|
@@ -181,7 +181,7 @@ You can also pass a number which serves as a max timeout.
|
|
|
181
181
|
```
|
|
182
182
|
|
|
183
183
|
::note
|
|
184
|
-
Under the hood, this uses Vue's built-in [`hydrateOnIdle` strategy](https://vuejs.org/guide/components/async
|
|
184
|
+
Under the hood, this uses Vue's built-in [`hydrateOnIdle` strategy](https://vuejs.org/guide/components/async#hydrate-on-idle).
|
|
185
185
|
::
|
|
186
186
|
|
|
187
187
|
#### `hydrate-on-interaction`
|
|
@@ -199,7 +199,7 @@ Hydrates the component after a specified interaction (e.g., click, mouseover).
|
|
|
199
199
|
If you do not pass an event or list of events, it defaults to hydrating on `pointerenter`, `click` and `focus`.
|
|
200
200
|
|
|
201
201
|
::note
|
|
202
|
-
Under the hood, this uses Vue's built-in [`hydrateOnInteraction` strategy](https://vuejs.org/guide/components/async
|
|
202
|
+
Under the hood, this uses Vue's built-in [`hydrateOnInteraction` strategy](https://vuejs.org/guide/components/async#hydrate-on-interaction).
|
|
203
203
|
::
|
|
204
204
|
|
|
205
205
|
#### `hydrate-on-media-query`
|
|
@@ -215,7 +215,7 @@ Hydrates the component when the window matches a media query.
|
|
|
215
215
|
```
|
|
216
216
|
|
|
217
217
|
::note
|
|
218
|
-
Under the hood, this uses Vue's built-in [`hydrateOnMediaQuery` strategy](https://vuejs.org/guide/components/async
|
|
218
|
+
Under the hood, this uses Vue's built-in [`hydrateOnMediaQuery` strategy](https://vuejs.org/guide/components/async#hydrate-on-media-query).
|
|
219
219
|
::
|
|
220
220
|
|
|
221
221
|
#### `hydrate-after`
|
|
@@ -430,7 +430,7 @@ This feature only works with Nuxt auto-imports and `#components` imports. Explic
|
|
|
430
430
|
`.client` components are rendered only after being mounted. To access the rendered template using `onMounted()`, add `await nextTick()` in the callback of the `onMounted()` hook.
|
|
431
431
|
::
|
|
432
432
|
|
|
433
|
-
::read-more{to="/docs/api/components/client-only"}
|
|
433
|
+
::read-more{to="/docs/3.x/api/components/client-only"}
|
|
434
434
|
You can also achieve a similar result with the `<ClientOnly>` component.
|
|
435
435
|
::
|
|
436
436
|
|
|
@@ -438,7 +438,7 @@ You can also achieve a similar result with the `<ClientOnly>` component.
|
|
|
438
438
|
|
|
439
439
|
Server components allow server-rendering individual components within your client-side apps. It's possible to use server components within Nuxt, even if you are generating a static site. That makes it possible to build complex sites that mix dynamic components, server-rendered HTML and even static chunks of markup.
|
|
440
440
|
|
|
441
|
-
Server components can either be used on their own or paired with a [client component](#paired-with-a-client-component).
|
|
441
|
+
Server components can either be used on their own or paired with a [client component](/docs/3.x/directory-structure/components#paired-with-a-client-component).
|
|
442
442
|
|
|
443
443
|
:video-accordion{title="Watch Learn Vue video about Nuxt Server Components" videoId="u1yyXe86xJM"}
|
|
444
444
|
|
|
@@ -535,6 +535,10 @@ This means:
|
|
|
535
535
|
* You can't access the 'island context' from the rest of your app and you can't access the context of the rest of your app from the island component. In other words, the server component or island is _isolated_ from the rest of your app.
|
|
536
536
|
* Your plugins will run again when rendering the island, unless they have `env: { islands: false }` set (which you can do in an object-syntax plugin).
|
|
537
537
|
|
|
538
|
+
::important
|
|
539
|
+
Route middleware does not run when rendering island components. Middleware is a routing concept that applies to pages, not components, and is not designed to control component rendering.
|
|
540
|
+
::
|
|
541
|
+
|
|
538
542
|
Within an island component, you can access its island context through `nuxtApp.ssrContext.islandContext`. Note that while island components are still marked as experimental, the format of this context may change.
|
|
539
543
|
|
|
540
544
|
::note
|
|
@@ -564,7 +568,7 @@ In this case, the `.server` + `.client` components are two 'halves' of a compone
|
|
|
564
568
|
|
|
565
569
|
There are a number of components that Nuxt provides, including `<ClientOnly>` and `<DevOnly>`. You can read more about them in the API documentation.
|
|
566
570
|
|
|
567
|
-
::read-more{to="/docs/api"}
|
|
571
|
+
::read-more{to="/docs/3.x/api"}
|
|
568
572
|
::
|
|
569
573
|
|
|
570
574
|
## Library Authors
|
|
@@ -626,4 +630,4 @@ export default defineNuxtConfig({
|
|
|
626
630
|
|
|
627
631
|
It will automatically import the components only if used and also support HMR when updating your components in `node_modules/awesome-ui/components/`.
|
|
628
632
|
|
|
629
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
633
|
+
:link-example{to="/docs/3.x/examples/features/auto-imports"}
|
|
@@ -42,9 +42,9 @@ const foo = useFoo()
|
|
|
42
42
|
The `composables/` directory in Nuxt does not provide any additional reactivity capabilities to your code. Instead, any reactivity within composables is achieved using Vue's Composition API mechanisms, such as ref and reactive. Note that reactive code is also not limited to the boundaries of the `composables/` directory. You are free to employ reactivity features wherever they're needed in your application.
|
|
43
43
|
::
|
|
44
44
|
|
|
45
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
45
|
+
:read-more{to="/docs/3.x/guide/concepts/auto-imports"}
|
|
46
46
|
|
|
47
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
47
|
+
:link-example{to="/docs/3.x/examples/features/auto-imports"}
|
|
48
48
|
|
|
49
49
|
## Types
|
|
50
50
|
|
|
@@ -5,7 +5,7 @@ description: Use the content/ directory to create a file-based CMS for your appl
|
|
|
5
5
|
navigation.icon: i-vscode-icons-folder-type-log
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
[Nuxt Content](https://content.nuxt.com) reads the
|
|
8
|
+
[Nuxt Content](https://content.nuxt.com) reads the `content/` directory in your project and parses `.md`, `.yml`, `.csv` and `.json` files to create a file-based CMS for your application.
|
|
9
9
|
|
|
10
10
|
- Render your content with built-in components.
|
|
11
11
|
- Query your content with a MongoDB-like API.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'layers'
|
|
3
|
+
head.title: 'layers/'
|
|
4
|
+
description: Use the layers/ directory to organize and auto-register local layers within your application.
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-nuxt
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The `layers/` directory allows you to organize and share reusable code, components, composables, and configurations across your Nuxt application. Any layers within your project in the `layers/` directory will be automatically registered.
|
|
9
|
+
|
|
10
|
+
::note
|
|
11
|
+
The `layers/` directory auto-registration is available in Nuxt v3.12.0+.
|
|
12
|
+
::
|
|
13
|
+
|
|
14
|
+
::tip{icon="i-lucide-lightbulb"}
|
|
15
|
+
Layers are ideal for organizing large codebases with **Domain-Driven Design (DDD)**, creating reusable **UI libraries** or **themes**, sharing **configuration presets** across projects, and separating concerns like **admin panels** or **feature modules**.
|
|
16
|
+
::
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
Each subdirectory within `layers/` is treated as a separate layer. A layer can contain the same structure as a standard Nuxt application.
|
|
21
|
+
|
|
22
|
+
::important
|
|
23
|
+
Every layer **must have** a `nuxt.config.ts` file to be recognized as a valid layer, even if it's empty.
|
|
24
|
+
::
|
|
25
|
+
|
|
26
|
+
```bash [Directory structure]
|
|
27
|
+
-| layers/
|
|
28
|
+
---| base/
|
|
29
|
+
-----| nuxt.config.ts
|
|
30
|
+
-----| app/
|
|
31
|
+
-------| components/
|
|
32
|
+
---------| BaseButton.vue
|
|
33
|
+
-------| composables/
|
|
34
|
+
---------| useBase.ts
|
|
35
|
+
-----| server/
|
|
36
|
+
-------| api/
|
|
37
|
+
---------| hello.ts
|
|
38
|
+
---| admin/
|
|
39
|
+
-----| nuxt.config.ts
|
|
40
|
+
-----| app/
|
|
41
|
+
-------| pages/
|
|
42
|
+
---------| admin.vue
|
|
43
|
+
-------| layouts/
|
|
44
|
+
---------| admin.vue
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Automatic Aliases
|
|
48
|
+
|
|
49
|
+
Named layer aliases to the `srcDir` of each layer are automatically created. You can access a layer using the `#layers/[name]` alias:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// Access the base layer
|
|
53
|
+
import something from '#layers/base/path/to/file'
|
|
54
|
+
|
|
55
|
+
// Access the admin layer
|
|
56
|
+
import { useAdmin } from '#layers/admin/composables/useAdmin'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
::note
|
|
60
|
+
Named layer aliases were introduced in Nuxt v3.16.0.
|
|
61
|
+
::
|
|
62
|
+
|
|
63
|
+
## Layer Content
|
|
64
|
+
|
|
65
|
+
Each layer can include:
|
|
66
|
+
|
|
67
|
+
- [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) - Layer-specific configuration that will be merged with the main config
|
|
68
|
+
- [`app.config.ts`](/docs/3.x/directory-structure/app-config) - Reactive application configuration
|
|
69
|
+
- [`components/`](/docs/3.x/directory-structure/components) - Vue components (auto-imported)
|
|
70
|
+
- [`composables/`](/docs/3.x/directory-structure/composables) - Vue composables (auto-imported)
|
|
71
|
+
- [`utils/`](/docs/3.x/directory-structure/utils) - Utility functions (auto-imported)
|
|
72
|
+
- [`pages/`](/docs/3.x/directory-structure/pages) - Application pages
|
|
73
|
+
- [`layouts/`](/docs/3.x/directory-structure/layouts) - Application layouts
|
|
74
|
+
- [`middleware/`](/docs/3.x/directory-structure/middleware) - Route middleware
|
|
75
|
+
- [`plugins/`](/docs/3.x/directory-structure/plugins) - Nuxt plugins
|
|
76
|
+
- [`server/`](/docs/3.x/directory-structure/server) - Server routes, middleware, and utilities
|
|
77
|
+
- [`shared/`](/docs/3.x/directory-structure/shared) - Shared code between app and server
|
|
78
|
+
|
|
79
|
+
## Priority Order
|
|
80
|
+
|
|
81
|
+
When multiple layers define the same resource (component, composable, page, etc.), the layer with **higher priority wins**. Layers are sorted alphabetically, with later letters having higher priority (Z > A).
|
|
82
|
+
|
|
83
|
+
To control the order, prefix directories with numbers: `1.base/`, `2.features/`, `3.admin/`.
|
|
84
|
+
|
|
85
|
+
:read-more{to="/docs/3.x/getting-started/layers#layer-priority"}
|
|
86
|
+
|
|
87
|
+
:video-accordion{title="Watch a video from Learn Vue about Nuxt Layers" videoId="lnFCM7c9f7I"}
|
|
@@ -24,6 +24,7 @@ Layouts are enabled by adding [`<NuxtLayout>`](/docs/3.x/api/components/nuxt-lay
|
|
|
24
24
|
To use a layout:
|
|
25
25
|
- Set a `layout` property in your page with [definePageMeta](/docs/3.x/api/utils/define-page-meta).
|
|
26
26
|
- Set the `name` prop of `<NuxtLayout>`.
|
|
27
|
+
- Set the `appLayout` property in route rules.
|
|
27
28
|
|
|
28
29
|
::note
|
|
29
30
|
The layout name is normalized to kebab-case, so `someLayout` becomes `some-layout`.
|
|
@@ -68,13 +69,19 @@ Then you can use the `custom` layout in your page:
|
|
|
68
69
|
|
|
69
70
|
```vue twoslash [pages/about.vue]
|
|
70
71
|
<script setup lang="ts">
|
|
72
|
+
declare module 'nuxt/app' {
|
|
73
|
+
interface NuxtLayouts {
|
|
74
|
+
'custom': unknown
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ---cut---
|
|
71
78
|
definePageMeta({
|
|
72
79
|
layout: 'custom',
|
|
73
80
|
})
|
|
74
81
|
</script>
|
|
75
82
|
```
|
|
76
83
|
|
|
77
|
-
::read-more{to="/docs/
|
|
84
|
+
::read-more{to="/docs/3.x/directory-structure/pages#page-metadata"}
|
|
78
85
|
Learn more about `definePageMeta`.
|
|
79
86
|
::
|
|
80
87
|
|
|
@@ -109,7 +116,7 @@ File | Layout Name
|
|
|
109
116
|
`~/layouts/desktop-base/DesktopBase.vue` | `desktop-base`
|
|
110
117
|
`~/layouts/desktop/Desktop.vue` | `desktop`
|
|
111
118
|
|
|
112
|
-
:link-example{to="/docs/examples/features/layouts"}
|
|
119
|
+
:link-example{to="/docs/3.x/examples/features/layouts"}
|
|
113
120
|
|
|
114
121
|
## Changing the Layout Dynamically
|
|
115
122
|
|
|
@@ -117,6 +124,12 @@ You can also use the [`setPageLayout`](/docs/3.x/api/utils/set-page-layout) help
|
|
|
117
124
|
|
|
118
125
|
```vue twoslash
|
|
119
126
|
<script setup lang="ts">
|
|
127
|
+
declare module 'nuxt/app' {
|
|
128
|
+
interface NuxtLayouts {
|
|
129
|
+
'custom': unknown
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// ---cut---
|
|
120
133
|
function enableCustomLayout () {
|
|
121
134
|
setPageLayout('custom')
|
|
122
135
|
}
|
|
@@ -134,7 +147,26 @@ definePageMeta({
|
|
|
134
147
|
</template>
|
|
135
148
|
```
|
|
136
149
|
|
|
137
|
-
:
|
|
150
|
+
You can also set layouts for specific routes using the `appLayout` property in route rules:
|
|
151
|
+
|
|
152
|
+
```ts [nuxt.config.ts]
|
|
153
|
+
export default defineNuxtConfig({
|
|
154
|
+
routeRules: {
|
|
155
|
+
// Set layout for specific route
|
|
156
|
+
'/admin': { appLayout: 'admin' },
|
|
157
|
+
// Set layout for multiple routes
|
|
158
|
+
'/dashboard/**': { appLayout: 'dashboard' },
|
|
159
|
+
// Disable layout for a route
|
|
160
|
+
'/landing': { appLayout: false },
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
::tip
|
|
166
|
+
This is useful when you want to manage layouts centrally in your configuration rather than in each page file, or when you need to apply layouts to routes that don't have corresponding page components (such as catchall pages which might match many paths).
|
|
167
|
+
::
|
|
168
|
+
|
|
169
|
+
:link-example{to="/docs/3.x/examples/features/layouts"}
|
|
138
170
|
|
|
139
171
|
## Overriding a Layout on a Per-page Basis
|
|
140
172
|
|