@nuxt/docs 4.2.1 → 4.3.0
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 +1 -1
- package/1.getting-started/02.installation.md +2 -5
- package/1.getting-started/03.configuration.md +27 -27
- package/1.getting-started/04.views.md +5 -5
- package/1.getting-started/05.assets.md +7 -7
- package/1.getting-started/06.styling.md +9 -5
- package/1.getting-started/07.routing.md +8 -8
- package/1.getting-started/08.seo-meta.md +7 -3
- package/1.getting-started/09.transitions.md +6 -6
- package/1.getting-started/10.data-fetching.md +2 -2
- package/1.getting-started/11.state-management.md +2 -2
- package/1.getting-started/12.error-handling.md +15 -9
- package/1.getting-started/13.server.md +2 -2
- package/1.getting-started/14.layers.md +50 -16
- package/1.getting-started/15.prerendering.md +6 -0
- package/1.getting-started/16.deployment.md +2 -1
- package/1.getting-started/17.testing.md +44 -3
- package/1.getting-started/18.upgrade.md +37 -24
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.nuxt.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.output.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.assets.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.components.md +6 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.composables.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.layouts.md +35 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.middleware.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.pages.md +28 -7
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.plugins.md +5 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.utils.md +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.error.md +10 -8
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
- package/2.directory-structure/1.layers.md +87 -0
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +13 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.node_modules.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +27 -7
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +4 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.package.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.tsconfig.md +1 -0
- package/2.directory-structure/index.md +65 -0
- package/{2.guide → 3.guide}/0.index.md +10 -7
- package/{2.guide/2.concepts/3.rendering.md → 3.guide/1.concepts/1.rendering.md} +2 -27
- package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +4 -3
- package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +33 -26
- package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +5 -5
- package/{2.guide/2.concepts → 3.guide/1.concepts}/4.server-engine.md +3 -3
- package/{2.guide/2.concepts → 3.guide/1.concepts}/5.modules.md +15 -2
- package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +1 -0
- package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +9 -5
- package/{2.guide/5.best-practices → 3.guide/2.best-practices}/performance.md +2 -2
- 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 +330 -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/{2.guide/4.recipes → 3.guide/5.recipes}/1.custom-routing.md +1 -1
- package/{2.guide/4.recipes → 3.guide/5.recipes}/2.vite-plugin.md +5 -1
- package/{2.guide/4.recipes → 3.guide/5.recipes}/3.custom-usefetch.md +2 -2
- package/{2.guide/4.recipes → 3.guide/5.recipes}/4.sessions-and-authentication.md +2 -2
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.events.md +2 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.experimental-features.md +19 -4
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.internals.md +5 -4
- package/{2.guide/3.going-further → 3.guide/6.going-further}/10.runtime-config.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/2.hooks.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/4.kit.md +1 -1
- package/{2.guide/3.going-further → 3.guide/6.going-further}/6.nuxt-app.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +38 -12
- package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +4 -0
- package/{3.api → 4.api}/1.components/12.nuxt-route-announcer.md +1 -3
- package/{3.api → 4.api}/1.components/13.nuxt-time.md +0 -2
- package/{3.api → 4.api}/1.components/2.nuxt-page.md +2 -2
- package/{3.api → 4.api}/1.components/3.nuxt-layout.md +6 -6
- package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +1 -1
- package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +2 -2
- package/{3.api → 4.api}/1.components/8.nuxt-island.md +9 -2
- package/{3.api → 4.api}/2.composables/use-app-config.md +1 -1
- package/{3.api → 4.api}/2.composables/use-async-data.md +3 -3
- package/4.api/2.composables/use-cookie.md +183 -0
- package/{3.api → 4.api}/2.composables/use-error.md +2 -2
- package/{3.api → 4.api}/2.composables/use-fetch.md +33 -33
- package/{3.api → 4.api}/2.composables/use-head.md +16 -1
- package/{3.api → 4.api}/2.composables/use-lazy-fetch.md +8 -8
- package/{3.api → 4.api}/2.composables/use-nuxt-app.md +6 -4
- package/{3.api → 4.api}/2.composables/use-response-header.md +1 -1
- package/{3.api → 4.api}/2.composables/use-route-announcer.md +0 -2
- package/{3.api → 4.api}/2.composables/use-route.md +1 -1
- package/{3.api → 4.api}/2.composables/use-router.md +2 -2
- package/{3.api → 4.api}/2.composables/use-runtime-config.md +1 -1
- package/{3.api → 4.api}/2.composables/use-state.md +10 -0
- package/{3.api → 4.api}/3.utils/$fetch.md +1 -1
- package/{3.api → 4.api}/3.utils/abort-navigation.md +1 -1
- package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
- package/{3.api → 4.api}/3.utils/call-once.md +0 -2
- package/{3.api → 4.api}/3.utils/create-error.md +6 -6
- package/{3.api → 4.api}/3.utils/define-nuxt-plugin.md +12 -12
- package/{3.api → 4.api}/3.utils/define-nuxt-route-middleware.md +2 -2
- package/{3.api → 4.api}/3.utils/define-page-meta.md +14 -7
- package/{3.api → 4.api}/3.utils/navigate-to.md +10 -10
- package/{3.api → 4.api}/3.utils/refresh-cookie.md +0 -2
- package/{3.api → 4.api}/3.utils/set-page-layout.md +36 -0
- package/{3.api → 4.api}/3.utils/set-response-status.md +2 -2
- package/{3.api → 4.api}/3.utils/show-error.md +3 -3
- package/{3.api → 4.api}/3.utils/update-app-config.md +2 -2
- package/{3.api → 4.api}/4.commands/add.md +11 -11
- package/4.api/4.commands/analyze.md +42 -0
- package/4.api/4.commands/build-module.md +42 -0
- package/4.api/4.commands/build.md +47 -0
- package/{3.api → 4.api}/4.commands/cleanup.md +6 -6
- package/4.api/4.commands/dev.md +60 -0
- package/{3.api → 4.api}/4.commands/devtools.md +7 -7
- package/4.api/4.commands/generate.md +42 -0
- package/4.api/4.commands/info.md +33 -0
- package/4.api/4.commands/init.md +50 -0
- package/4.api/4.commands/module.md +84 -0
- package/4.api/4.commands/prepare.md +41 -0
- package/4.api/4.commands/preview.md +44 -0
- package/4.api/4.commands/test.md +40 -0
- package/4.api/4.commands/typecheck.md +44 -0
- package/4.api/4.commands/upgrade.md +37 -0
- package/{3.api → 4.api}/5.kit/1.modules.md +30 -17
- package/{3.api → 4.api}/5.kit/10.templates.md +23 -23
- package/{3.api → 4.api}/5.kit/11.nitro.md +35 -35
- package/{3.api → 4.api}/5.kit/14.builder.md +29 -17
- package/{3.api → 4.api}/5.kit/16.layers.md +12 -12
- package/{3.api → 4.api}/5.kit/2.programmatic.md +2 -2
- package/{3.api → 4.api}/5.kit/4.autoimports.md +18 -18
- package/4.api/5.kit/5.components.md +146 -0
- package/4.api/6.advanced/1.hooks.md +105 -0
- package/{3.api → 4.api}/6.nuxt-config.md +7 -6
- package/5.community/4.contribution.md +5 -5
- package/5.community/5.framework-contribution.md +1 -1
- package/5.community/6.roadmap.md +25 -25
- package/5.community/7.changelog.md +20 -0
- package/6.bridge/1.overview.md +9 -1
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +1 -1
- package/6.bridge/4.plugins-and-middleware.md +3 -3
- package/6.bridge/8.nitro.md +4 -0
- package/7.migration/11.server.md +1 -1
- package/7.migration/2.configuration.md +4 -4
- package/7.migration/20.module-authors.md +3 -3
- package/7.migration/3.auto-imports.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +2 -2
- package/7.migration/6.pages-and-layouts.md +6 -6
- package/7.migration/7.component-options.md +1 -1
- package/package.json +1 -1
- package/2.guide/3.going-further/3.modules.md +0 -968
- package/3.api/2.composables/use-cookie.md +0 -183
- package/3.api/4.commands/analyze.md +0 -42
- package/3.api/4.commands/build-module.md +0 -42
- package/3.api/4.commands/build.md +0 -47
- package/3.api/4.commands/dev.md +0 -60
- package/3.api/4.commands/generate.md +0 -42
- package/3.api/4.commands/info.md +0 -33
- package/3.api/4.commands/init.md +0 -50
- package/3.api/4.commands/module.md +0 -84
- package/3.api/4.commands/prepare.md +0 -41
- package/3.api/4.commands/preview.md +0 -44
- package/3.api/4.commands/test.md +0 -40
- package/3.api/4.commands/typecheck.md +0 -44
- package/3.api/4.commands/upgrade.md +0 -37
- package/3.api/5.kit/5.components.md +0 -146
- package/3.api/6.advanced/1.hooks.md +0 -105
- /package/{2.guide/1.directory-structure → 2.directory-structure}/.navigation.yml +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/.navigation.yml +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app-config.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/2.gitignore.md +0 -0
- /package/{2.guide → 3.guide}/.navigation.yml +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/.navigation.yml +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/plugins.md +0 -0
- /package/{2.guide/4.recipes → 3.guide/5.recipes}/.navigation.yml +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/.navigation.yml +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/1.features.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/11.nightly-release-channel.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/6.going-further}/index.md +0 -0
- /package/{3.api → 4.api}/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/1.client-only.md +0 -0
- /package/{3.api → 4.api}/1.components/1.dev-only.md +0 -0
- /package/{3.api → 4.api}/1.components/10.nuxt-picture.md +0 -0
- /package/{3.api → 4.api}/1.components/11.teleports.md +0 -0
- /package/{3.api → 4.api}/1.components/4.nuxt-link.md +0 -0
- /package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +0 -0
- /package/{3.api → 4.api}/1.components/9.nuxt-img.md +0 -0
- /package/{3.api → 4.api}/2.composables/.navigation.yml +0 -0
- /package/{3.api → 4.api}/2.composables/on-prehydrate.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-head-safe.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-hydration.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-lazy-async-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-loading-indicator.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-preview-mode.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-event.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-fetch.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-header.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-headers.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-url.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-runtime-hook.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-seo-meta.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +0 -0
- /package/{3.api → 4.api}/3.utils/.navigation.yml +0 -0
- /package/{3.api → 4.api}/3.utils/clear-error.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-state.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-nuxt-component.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-route-rules.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-before-route-leave.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-before-route-update.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-nuxt-ready.md +0 -0
- /package/{3.api → 4.api}/3.utils/prefetch-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/preload-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/preload-route-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/prerender-routes.md +0 -0
- /package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +0 -0
- /package/{3.api → 4.api}/4.commands/.navigation.yml +0 -0
- /package/{3.api → 4.api}/5.kit/.navigation.yml +0 -0
- /package/{3.api → 4.api}/5.kit/10.runtime-config.md +0 -0
- /package/{3.api → 4.api}/5.kit/12.resolving.md +0 -0
- /package/{3.api → 4.api}/5.kit/13.logging.md +0 -0
- /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
- /package/{3.api → 4.api}/5.kit/3.compatibility.md +0 -0
- /package/{3.api → 4.api}/5.kit/6.context.md +0 -0
- /package/{3.api → 4.api}/5.kit/7.pages.md +0 -0
- /package/{3.api → 4.api}/5.kit/8.layout.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.head.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.plugins.md +0 -0
- /package/{3.api → 4.api}/6.advanced/.navigation.yml +0 -0
- /package/{3.api → 4.api}/6.advanced/2.import-meta.md +0 -0
- /package/{3.api → 4.api}/index.md +0 -0
|
@@ -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/4.x/
|
|
13
|
-
- Create utility and composable library using [`app/composables/`](/docs/4.x/
|
|
12
|
+
- Create a component library using [`app/components/`](/docs/4.x/directory-structure/app/components) directory
|
|
13
|
+
- Create utility and composable library using [`app/composables/`](/docs/4.x/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/directory-structure/app/utils) directories
|
|
14
14
|
- Create Nuxt module presets
|
|
15
15
|
- Share standard setup across projects
|
|
16
16
|
- Create Nuxt themes
|
|
@@ -30,7 +30,7 @@ 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/4.x/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/4.x/
|
|
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/directory-structure/nuxt-config) file.
|
|
34
34
|
|
|
35
35
|
```ts [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
@@ -56,6 +56,10 @@ export default defineNuxtConfig({
|
|
|
56
56
|
})
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
::note
|
|
60
|
+
If a branch is not specified, this will clone `main`.
|
|
61
|
+
::
|
|
62
|
+
|
|
59
63
|
::tip
|
|
60
64
|
You can override a layer's alias by specifying it in the options next to the layer source.
|
|
61
65
|
|
|
@@ -82,32 +86,60 @@ Nuxt uses [unjs/c12](https://github.com/unjs/c12) and [unjs/giget](https://githu
|
|
|
82
86
|
|
|
83
87
|
When using multiple layers, it's important to understand the override order. Layers with **higher priority** override layers with lower priority when they define the same files or components.
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
### Priority Order
|
|
90
|
+
|
|
91
|
+
From highest to lowest priority:
|
|
86
92
|
|
|
87
93
|
1. **Your project files** - always have the highest priority
|
|
88
94
|
2. **Auto-scanned layers** from `~~/layers` directory - sorted alphabetically (Z has higher priority than A)
|
|
89
95
|
3. **Layers in `extends`** config - first entry has higher priority than second
|
|
90
96
|
|
|
91
|
-
###
|
|
97
|
+
### Practical Example
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
Consider multiple layers defining the same component:
|
|
100
|
+
|
|
101
|
+
```bash [Directory structure]
|
|
102
|
+
layers/
|
|
103
|
+
1.base/
|
|
104
|
+
app/components/Button.vue # Base button style
|
|
105
|
+
2.theme/
|
|
106
|
+
app/components/Button.vue # Themed button (overrides base)
|
|
107
|
+
app/
|
|
108
|
+
components/Button.vue # Project button (overrides all layers)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
In this case:
|
|
112
|
+
- If only layers exist, `2.theme/Button.vue` is used (higher alphabetically)
|
|
113
|
+
- If `app/components/Button.vue` exists in your project, it overrides all layers
|
|
114
|
+
|
|
115
|
+
### Controlling Priority
|
|
116
|
+
|
|
117
|
+
You can prefix layer directories with numbers to control the order:
|
|
118
|
+
|
|
119
|
+
```bash [Directory structure]
|
|
120
|
+
layers/
|
|
121
|
+
1.base/ # Lowest priority
|
|
122
|
+
2.features/ # Medium priority
|
|
123
|
+
3.admin/ # Highest priority (among layers)
|
|
124
|
+
```
|
|
95
125
|
|
|
96
126
|
::tip
|
|
97
|
-
|
|
127
|
+
This pattern is useful for creating base layers with defaults that can be progressively overridden by more specific layers.
|
|
98
128
|
::
|
|
99
129
|
|
|
100
|
-
###
|
|
130
|
+
### When to Use Each
|
|
131
|
+
|
|
132
|
+
- **`~~/layers` directory** - Use for local layers that are part of your project
|
|
133
|
+
- **`extends`** - Use for external dependencies (npm packages, remote repositories) or layers outside your project directory
|
|
134
|
+
|
|
135
|
+
### Full Example with extends
|
|
101
136
|
|
|
102
137
|
```ts [nuxt.config.ts]
|
|
103
138
|
export default defineNuxtConfig({
|
|
104
139
|
extends: [
|
|
105
|
-
// Local layer outside
|
|
106
|
-
'
|
|
107
|
-
//
|
|
108
|
-
'@my-themes/awesome',
|
|
109
|
-
// Remote repository
|
|
110
|
-
'github:my-themes/awesome#v1',
|
|
140
|
+
'../base', // Local layer outside project
|
|
141
|
+
'@my-themes/awesome', // NPM package
|
|
142
|
+
'github:my-themes/awesome#v1', // Remote repository
|
|
111
143
|
],
|
|
112
144
|
})
|
|
113
145
|
```
|
|
@@ -119,7 +151,9 @@ If you also have `~~/layers/custom`, the priority order is:
|
|
|
119
151
|
- `@my-themes/awesome`
|
|
120
152
|
- `github:my-themes/awesome#v1` (lowest)
|
|
121
153
|
|
|
122
|
-
|
|
154
|
+
::read-more{to="/docs/4.x/directory-structure/layers"}
|
|
155
|
+
Learn about the **layers/ directory** to organize and share reusable code, components, composables, and configurations across your Nuxt application.
|
|
156
|
+
::
|
|
123
157
|
|
|
124
158
|
::read-more{to="/docs/4.x/guide/going-further/layers"}
|
|
125
159
|
Read more about layers in the **Layer Author Guide**.
|
|
@@ -32,6 +32,10 @@ pnpm nuxt generate
|
|
|
32
32
|
bun x nuxt generate
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
```bash [deno]
|
|
36
|
+
deno x nuxt generate
|
|
37
|
+
```
|
|
38
|
+
|
|
35
39
|
::
|
|
36
40
|
|
|
37
41
|
You can now deploy the `.output/public` directory to any static hosting service or preview it locally with `npx serve .output/public`.
|
|
@@ -54,6 +58,7 @@ Read more about the `nuxt generate` command.
|
|
|
54
58
|
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
59
|
|
|
56
60
|
```ts twoslash [nuxt.config.ts]
|
|
61
|
+
// @errors: 2353
|
|
57
62
|
export default defineNuxtConfig({
|
|
58
63
|
nitro: {
|
|
59
64
|
prerender: {
|
|
@@ -67,6 +72,7 @@ export default defineNuxtConfig({
|
|
|
67
72
|
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`:
|
|
68
73
|
|
|
69
74
|
```ts twoslash [nuxt.config.ts]
|
|
75
|
+
// @errors: 2353
|
|
70
76
|
export default defineNuxtConfig({
|
|
71
77
|
nitro: {
|
|
72
78
|
prerender: {
|
|
@@ -95,9 +95,10 @@ 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/4.x/
|
|
98
|
+
You can explicitly set the desired preset in the [`nuxt.config.ts`](/docs/4.x/directory-structure/nuxt-config) file:
|
|
99
99
|
|
|
100
100
|
```ts twoslash [nuxt.config.ts]
|
|
101
|
+
// @errors: 2353
|
|
101
102
|
export default defineNuxtConfig({
|
|
102
103
|
nitro: {
|
|
103
104
|
preset: 'node-server',
|
|
@@ -5,7 +5,7 @@ navigation.icon: i-lucide-circle-check
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
::tip
|
|
8
|
-
If you are a module author, you can find more specific information in the [Module Author's guide](/docs/4.x/guide/
|
|
8
|
+
If you are a module author, you can find more specific information in the [Module Author's guide](/docs/4.x/guide/modules/testing).
|
|
9
9
|
::
|
|
10
10
|
|
|
11
11
|
Nuxt offers first-class support for end-to-end and unit testing of your Nuxt application via `@nuxt/test-utils`, a library of test utilities and configuration that currently powers the [tests we use on Nuxt itself](https://github.com/nuxt/nuxt/tree/main/test) and tests throughout the module ecosystem.
|
|
@@ -63,7 +63,14 @@ We currently ship an environment for unit testing code that needs a [Nuxt](https
|
|
|
63
63
|
{
|
|
64
64
|
test: {
|
|
65
65
|
name: 'unit',
|
|
66
|
-
include: ['test/
|
|
66
|
+
include: ['test/unit/*.{test,spec}.ts'],
|
|
67
|
+
environment: 'node',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
test: {
|
|
72
|
+
name: 'e2e',
|
|
73
|
+
include: ['test/e2e/*.{test,spec}.ts'],
|
|
67
74
|
environment: 'node',
|
|
68
75
|
},
|
|
69
76
|
},
|
|
@@ -151,6 +158,37 @@ test/
|
|
|
151
158
|
|
|
152
159
|
You can of course opt for any test structure, but keeping the Nuxt runtime environment separated from Nuxt end-to-end tests is important for test stability.
|
|
153
160
|
|
|
161
|
+
#### TypeScript Support in Tests
|
|
162
|
+
|
|
163
|
+
By default, test files in `test/nuxt/` and `tests/nuxt/` directories are included in the [Nuxt app TypeScript context](/docs/4.x/guide/concepts/typescript#how-nuxt-uses-project-references). That means they will recognise Nuxt aliases (like `~/`, `@/`, `#imports`) and TypeScript will be aware of auto-imports that work in your Nuxt app.
|
|
164
|
+
|
|
165
|
+
::tip
|
|
166
|
+
This matches the recommended structure where only tests that need the Nuxt runtime environment are placed in these directories. Unit tests in other directories like `test/unit/` can be added manually if needed.
|
|
167
|
+
::
|
|
168
|
+
|
|
169
|
+
##### Adding other test directories
|
|
170
|
+
|
|
171
|
+
If you have tests in other directories that you will be running in the Nuxt Vitest environment, you can include them in the Nuxt app TypeScript context by adding them to your configuration:
|
|
172
|
+
|
|
173
|
+
<!-- @case-police-ignore tsConfig -->
|
|
174
|
+
|
|
175
|
+
```ts [nuxt.config.ts]
|
|
176
|
+
export default defineNuxtConfig({
|
|
177
|
+
typescript: {
|
|
178
|
+
tsConfig: {
|
|
179
|
+
include: [
|
|
180
|
+
// this path is relative to the generated .nuxt/tsconfig.json
|
|
181
|
+
'../test/other-nuxt-context/**/*',
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
::important
|
|
189
|
+
Unit tests should not depend on Nuxt runtime features like auto-imports or composables. Only add TypeScript path alias support if your tests import from your source files (e.g., `~/utils/helpers`), not for Nuxt-specific features.
|
|
190
|
+
::
|
|
191
|
+
|
|
154
192
|
#### Running Tests
|
|
155
193
|
|
|
156
194
|
With the project setup, you can run different test suites:
|
|
@@ -267,7 +305,7 @@ it('can also mount an app', async () => {
|
|
|
267
305
|
|
|
268
306
|
This should be used together with utilities from Testing Library, e.g. `screen` and `fireEvent`. Install [@testing-library/vue](https://testing-library.com/docs/vue-testing-library/intro/) in your project to use these.
|
|
269
307
|
|
|
270
|
-
Additionally, Testing Library also relies on testing globals for cleanup. You should turn these on in your [Vitest config](https://vitest.dev/config
|
|
308
|
+
Additionally, Testing Library also relies on testing globals for cleanup. You should turn these on in your [Vitest config](https://vitest.dev/config/globals).
|
|
271
309
|
|
|
272
310
|
The passed in component will be rendered inside a `<div id="test-wrapper"></div>`.
|
|
273
311
|
|
|
@@ -730,6 +768,9 @@ pnpm add -D @playwright/test @nuxt/test-utils
|
|
|
730
768
|
```bash [bun]
|
|
731
769
|
bun add --dev @playwright/test @nuxt/test-utils
|
|
732
770
|
```
|
|
771
|
+
```bash [deno]
|
|
772
|
+
deno add --dev npm:@playwright/test npm:@nuxt/test-utils
|
|
773
|
+
```
|
|
733
774
|
::
|
|
734
775
|
|
|
735
776
|
You can provide global Nuxt configuration, with the same configuration details as the `setup()` function mentioned earlier in this section.
|
|
@@ -28,6 +28,10 @@ pnpm nuxt upgrade
|
|
|
28
28
|
bun x nuxt upgrade
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
```bash [deno]
|
|
32
|
+
deno x nuxt upgrade
|
|
33
|
+
```
|
|
34
|
+
|
|
31
35
|
::
|
|
32
36
|
|
|
33
37
|
### Nightly Release Channel
|
|
@@ -198,6 +202,10 @@ pnpm add nuxt@^4.0.0
|
|
|
198
202
|
bun add nuxt@^4.0.0
|
|
199
203
|
```
|
|
200
204
|
|
|
205
|
+
```bash [deno]
|
|
206
|
+
deno add npm:nuxt@^4.0.0
|
|
207
|
+
```
|
|
208
|
+
|
|
201
209
|
::
|
|
202
210
|
|
|
203
211
|
After upgrading, most Nuxt 4 behaviors are now the default. However, some features can still be configured if you need to maintain backward compatibility during your migration.
|
|
@@ -208,7 +216,7 @@ Breaking or significant changes are documented below along with migration steps
|
|
|
208
216
|
|
|
209
217
|
### Migrating Using Codemods
|
|
210
218
|
|
|
211
|
-
To facilitate the upgrade process, we have collaborated with the [Codemod](https://github.com/codemod
|
|
219
|
+
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.
|
|
212
220
|
|
|
213
221
|
::note
|
|
214
222
|
If you encounter any issues, please report them to the Codemod team with `npx codemod feedback` 🙏
|
|
@@ -221,25 +229,30 @@ You can run all the codemods mentioned in this guide using the following `codemo
|
|
|
221
229
|
::code-group
|
|
222
230
|
|
|
223
231
|
```bash [npm]
|
|
224
|
-
# Using pinned version due to https://github.com/codemod
|
|
232
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
225
233
|
npx codemod@0.18.7 nuxt/4/migration-recipe
|
|
226
234
|
```
|
|
227
235
|
|
|
228
236
|
```bash [yarn]
|
|
229
|
-
# Using pinned version due to https://github.com/codemod
|
|
237
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
230
238
|
yarn dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
231
239
|
```
|
|
232
240
|
|
|
233
241
|
```bash [pnpm]
|
|
234
|
-
# Using pinned version due to https://github.com/codemod
|
|
242
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
235
243
|
pnpm dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
236
244
|
```
|
|
237
245
|
|
|
238
246
|
```bash [bun]
|
|
239
|
-
# Using pinned version due to https://github.com/codemod
|
|
247
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
240
248
|
bun x codemod@0.18.7 nuxt/4/migration-recipe
|
|
241
249
|
```
|
|
242
250
|
|
|
251
|
+
```bash [deno]
|
|
252
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
253
|
+
deno x codemod@0.18.7 nuxt/4/migration-recipe
|
|
254
|
+
```
|
|
255
|
+
|
|
243
256
|
::
|
|
244
257
|
|
|
245
258
|
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.
|
|
@@ -463,7 +476,7 @@ export default defineNuxtConfig({
|
|
|
463
476
|
// 4. project-module-2 (can override layer modules)
|
|
464
477
|
```
|
|
465
478
|
|
|
466
|
-
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/4.x/guide/
|
|
479
|
+
If you encounter issues with module order dependencies due to needing to register a hook, consider using the [`modules:done` hook](/docs/4.x/guide/modules/recipes-advanced) 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.
|
|
467
480
|
|
|
468
481
|
👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
|
|
469
482
|
|
|
@@ -1053,7 +1066,7 @@ In Nuxt v3 we moved to a 'virtual' syntax with a `getContents()` function which
|
|
|
1053
1066
|
|
|
1054
1067
|
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.
|
|
1055
1068
|
|
|
1056
|
-
Finally, providing code serialization functions directly within Nuxt is not ideal. Instead, we maintain projects like [unjs/knitwork](
|
|
1069
|
+
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.
|
|
1057
1070
|
|
|
1058
1071
|
#### Migration Steps
|
|
1059
1072
|
|
|
@@ -1312,23 +1325,23 @@ Read more about Nitro's prerender configuration options.
|
|
|
1312
1325
|
|
|
1313
1326
|
In the table below, there is a quick comparison between 3 versions of Nuxt:
|
|
1314
1327
|
|
|
1315
|
-
Feature / Version
|
|
1316
|
-
|
|
1317
|
-
Vue
|
|
1318
|
-
Stability
|
|
1319
|
-
Performance
|
|
1320
|
-
Nitro Engine
|
|
1321
|
-
ESM support
|
|
1322
|
-
TypeScript
|
|
1323
|
-
Composition API
|
|
1324
|
-
Options API
|
|
1325
|
-
Components Auto Import
|
|
1326
|
-
`<script setup>` syntax
|
|
1327
|
-
Auto Imports
|
|
1328
|
-
webpack
|
|
1329
|
-
Vite
|
|
1330
|
-
Nuxt CLI
|
|
1331
|
-
Static sites
|
|
1328
|
+
| Feature / Version | Nuxt 2 | Nuxt Bridge | Nuxt 3+ |
|
|
1329
|
+
|-------------------------|------------|-------------|------------|
|
|
1330
|
+
| Vue | 2 | 2 | 3 |
|
|
1331
|
+
| Stability | 😊 Stable | 😊 Stable | 😊 Stable |
|
|
1332
|
+
| Performance | 🏎 Fast | ✈️ Faster | 🚀 Fastest |
|
|
1333
|
+
| Nitro Engine | ❌ | ✅ | ✅ |
|
|
1334
|
+
| ESM support | 🌙 Partial | 👍 Better | ✅ |
|
|
1335
|
+
| TypeScript | ☑️ Opt-in | 🚧 Partial | ✅ |
|
|
1336
|
+
| Composition API | ❌ | 🚧 Partial | ✅ |
|
|
1337
|
+
| Options API | ✅ | ✅ | ✅ |
|
|
1338
|
+
| Components Auto Import | ✅ | ✅ | ✅ |
|
|
1339
|
+
| `<script setup>` syntax | ❌ | 🚧 Partial | ✅ |
|
|
1340
|
+
| Auto Imports | ❌ | ✅ | ✅ |
|
|
1341
|
+
| webpack | 4 | 4 | 5 |
|
|
1342
|
+
| Vite | ⚠️ Partial | 🚧 Partial | ✅ |
|
|
1343
|
+
| Nuxt CLI | ❌ Old | ✅ nuxt | ✅ nuxt |
|
|
1344
|
+
| Static sites | ✅ | ✅ | ✅ |
|
|
1332
1345
|
|
|
1333
1346
|
## Nuxt 2 to Nuxt 3+
|
|
1334
1347
|
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-vscode-icons-folder-type-temp
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This directory should be added to your [`.gitignore`](/docs/4.x/
|
|
9
|
+
This directory should be added to your [`.gitignore`](/docs/4.x/directory-structure/gitignore) file to avoid pushing the dev build output to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
This directory is interesting if you want to learn more about the files Nuxt generates based on your directory structure.
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-vscode-icons-folder-type-package
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This directory should be added to your [`.gitignore`](/docs/4.x/
|
|
9
|
+
This directory should be added to your [`.gitignore`](/docs/4.x/directory-structure/gitignore) file to avoid pushing the build output to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
Use this directory to deploy your Nuxt application to production.
|
|
@@ -9,8 +9,8 @@ The directory usually contains the following types of files:
|
|
|
9
9
|
|
|
10
10
|
- Stylesheets (CSS, SASS, etc.)
|
|
11
11
|
- Fonts
|
|
12
|
-
- Images that won't be served from the [`public/`](/docs/4.x/
|
|
12
|
+
- Images that won't be served from the [`public/`](/docs/4.x/directory-structure/public) directory.
|
|
13
13
|
|
|
14
|
-
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/4.x/
|
|
14
|
+
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/4.x/directory-structure/public) directory.
|
|
15
15
|
|
|
16
16
|
:read-more{to="/docs/4.x/getting-started/assets"}
|
|
@@ -358,7 +358,7 @@ Any nested directories need to be added first as they are scanned in order.
|
|
|
358
358
|
|
|
359
359
|
## npm Packages
|
|
360
360
|
|
|
361
|
-
If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/4.x/api/kit/components#addcomponent) in a [local module](/docs/4.x/
|
|
361
|
+
If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/4.x/api/kit/components#addcomponent) in a [local module](/docs/4.x/directory-structure/modules) to register them.
|
|
362
362
|
|
|
363
363
|
::code-group
|
|
364
364
|
|
|
@@ -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](/docs/4.x/
|
|
441
|
+
Server components can either be used on their own or paired with a [client component](/docs/4.x/directory-structure/app/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
|
|
@@ -71,7 +71,7 @@ export const useFoo = () => {
|
|
|
71
71
|
|
|
72
72
|
### Access plugin injections
|
|
73
73
|
|
|
74
|
-
You can access [plugin injections](/docs/4.x/
|
|
74
|
+
You can access [plugin injections](/docs/4.x/directory-structure/app/plugins#providing-helpers) from composables:
|
|
75
75
|
|
|
76
76
|
```ts [app/composables/test.ts]
|
|
77
77
|
export const useHello = () => {
|
|
@@ -82,7 +82,7 @@ export const useHello = () => {
|
|
|
82
82
|
|
|
83
83
|
## How Files Are Scanned
|
|
84
84
|
|
|
85
|
-
Nuxt only scans files at the top level of the [`app/composables/` directory](/docs/4.x/
|
|
85
|
+
Nuxt only scans files at the top level of the [`app/composables/` directory](/docs/4.x/directory-structure/app/composables), e.g.:
|
|
86
86
|
|
|
87
87
|
```bash [Directory Structure]
|
|
88
88
|
-| composables/
|
|
@@ -11,7 +11,7 @@ For best performance, components placed in this directory will be automatically
|
|
|
11
11
|
|
|
12
12
|
## Enable Layouts
|
|
13
13
|
|
|
14
|
-
Layouts are enabled by adding [`<NuxtLayout>`](/docs/4.x/api/components/nuxt-layout) to your [`app.vue`](/docs/4.x/
|
|
14
|
+
Layouts are enabled by adding [`<NuxtLayout>`](/docs/4.x/api/components/nuxt-layout) to your [`app.vue`](/docs/4.x/directory-structure/app/app):
|
|
15
15
|
|
|
16
16
|
```vue [app/app.vue]
|
|
17
17
|
<template>
|
|
@@ -24,6 +24,7 @@ Layouts are enabled by adding [`<NuxtLayout>`](/docs/4.x/api/components/nuxt-lay
|
|
|
24
24
|
To use a layout:
|
|
25
25
|
- Set a `layout` property in your page with [definePageMeta](/docs/4.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`.
|
|
@@ -34,7 +35,7 @@ If no layout is specified, `app/layouts/default.vue` will be used.
|
|
|
34
35
|
::
|
|
35
36
|
|
|
36
37
|
::important
|
|
37
|
-
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/4.x/
|
|
38
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/4.x/directory-structure/app/app) instead.
|
|
38
39
|
::
|
|
39
40
|
|
|
40
41
|
::important
|
|
@@ -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/4.x/
|
|
84
|
+
::read-more{to="/docs/4.x/directory-structure/app/pages#page-metadata"}
|
|
78
85
|
Learn more about `definePageMeta`.
|
|
79
86
|
::
|
|
80
87
|
|
|
@@ -117,6 +124,12 @@ You can also use the [`setPageLayout`](/docs/4.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,6 +147,25 @@ definePageMeta({
|
|
|
134
147
|
</template>
|
|
135
148
|
```
|
|
136
149
|
|
|
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
|
+
|
|
137
169
|
:link-example{to="/docs/4.x/examples/features/layouts"}
|
|
138
170
|
|
|
139
171
|
## Overriding a Layout on a Per-page Basis
|
|
@@ -20,7 +20,7 @@ Name of middleware are normalized to kebab-case: `myMiddleware` becomes `my-midd
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from [server middleware](/docs/4.x/
|
|
23
|
+
Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from [server middleware](/docs/4.x/directory-structure/server#server-middleware), which are run in the Nitro server part of your app.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
:video-accordion{title="Watch a video from Vue School on all 3 kinds of middleware" videoId="761471577" platform="vimeo"}
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-vscode-icons-folder-type-view
|
|
|
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/4.x/
|
|
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/4.x/directory-structure/app/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/4.x/guide/recipes/custom-routing#using-routeroptions).
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
@@ -46,7 +46,7 @@ export default defineComponent({
|
|
|
46
46
|
|
|
47
47
|
The `app/pages/index.vue` file will be mapped to the `/` route of your application.
|
|
48
48
|
|
|
49
|
-
If you are using [`app.vue`](/docs/4.x/
|
|
49
|
+
If you are using [`app.vue`](/docs/4.x/directory-structure/app/app), make sure to use the [`<NuxtPage/>`](/docs/4.x/api/components/nuxt-page) component to display the current page:
|
|
50
50
|
|
|
51
51
|
```vue [app/app.vue]
|
|
52
52
|
<template>
|
|
@@ -246,6 +246,27 @@ For example:
|
|
|
246
246
|
|
|
247
247
|
This will produce `/`, `/about` and `/contact` pages in your app. The `marketing` group is ignored for purposes of your URL structure.
|
|
248
248
|
|
|
249
|
+
### Accessing Route Groups
|
|
250
|
+
|
|
251
|
+
Route groups are automatically available in the route metadata as `route.meta.groups`.
|
|
252
|
+
This allows you to access the group information in your components for conditional logic, styling, or other purposes.
|
|
253
|
+
|
|
254
|
+
```vue {}[pages/(marketing)/about.vue]
|
|
255
|
+
<script setup lang="ts">
|
|
256
|
+
const route = useRoute()
|
|
257
|
+
|
|
258
|
+
console.log(route.meta.groups) // Output: ['marketing']
|
|
259
|
+
</script>
|
|
260
|
+
|
|
261
|
+
<template>
|
|
262
|
+
<div>
|
|
263
|
+
<p v-if="route.meta.groups?.includes('marketing')">
|
|
264
|
+
This is a marketing page
|
|
265
|
+
</p>
|
|
266
|
+
</div>
|
|
267
|
+
</template>
|
|
268
|
+
```
|
|
269
|
+
|
|
249
270
|
## Page Metadata
|
|
250
271
|
|
|
251
272
|
You might want to define metadata for each route in your app. You can do this using the `definePageMeta` macro, which will work both in `<script>` and in `<script setup>`:
|
|
@@ -313,11 +334,11 @@ You can set a default value for this property [in your `nuxt.config`](/docs/4.x/
|
|
|
313
334
|
|
|
314
335
|
#### `key`
|
|
315
336
|
|
|
316
|
-
[See above](/docs/4.x/
|
|
337
|
+
[See above](/docs/4.x/directory-structure/app/pages#child-route-keys).
|
|
317
338
|
|
|
318
339
|
#### `layout`
|
|
319
340
|
|
|
320
|
-
You can define the layout used to render the route. This can be either false (to disable any layout), a string or a ref/computed, if you want to make it reactive in some way. [More about layouts](/docs/4.x/
|
|
341
|
+
You can define the layout used to render the route. This can be either false (to disable any layout), a string or a ref/computed, if you want to make it reactive in some way. [More about layouts](/docs/4.x/directory-structure/app/layouts).
|
|
321
342
|
|
|
322
343
|
#### `layoutTransition` and `pageTransition`
|
|
323
344
|
|
|
@@ -327,7 +348,7 @@ You can set default values for these properties [in your `nuxt.config`](/docs/4.
|
|
|
327
348
|
|
|
328
349
|
#### `middleware`
|
|
329
350
|
|
|
330
|
-
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards)), or an array of strings/functions. [More about named middleware](/docs/4.x/
|
|
351
|
+
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards)), or an array of strings/functions. [More about named middleware](/docs/4.x/directory-structure/app/middleware).
|
|
331
352
|
|
|
332
353
|
#### `name`
|
|
333
354
|
|
|
@@ -401,11 +422,11 @@ function navigate () {
|
|
|
401
422
|
|
|
402
423
|
## Client-Only Pages
|
|
403
424
|
|
|
404
|
-
You can define a page as [client only](/docs/4.x/
|
|
425
|
+
You can define a page as [client only](/docs/4.x/directory-structure/app/components#client-components) by giving it a `.client.vue` suffix. None of the content of this page will be rendered on the server.
|
|
405
426
|
|
|
406
427
|
## Server-Only Pages
|
|
407
428
|
|
|
408
|
-
You can define a page as [server only](/docs/4.x/
|
|
429
|
+
You can define a page as [server only](/docs/4.x/directory-structure/app/components#server-components) by giving it a `.server.vue` suffix. While you will be able to navigate to the page using client-side navigation, controlled by `vue-router`, it will be rendered with a server component automatically, meaning the code required to render the page will not be in your client-side bundle.
|
|
409
430
|
|
|
410
431
|
::warning
|
|
411
432
|
Server-only pages must have a single root element. (HTML comments are considered elements as well.)
|
|
@@ -134,7 +134,7 @@ export default defineNuxtPlugin({
|
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/4.x/
|
|
137
|
+
You can use [composables](/docs/4.x/directory-structure/app/composables) as well as [utils](/docs/4.x/directory-structure/app/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
139
|
```ts [app/plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -200,7 +200,7 @@ const { $hello } = useNuxtApp()
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
::important
|
|
203
|
-
Note that we highly recommend using [`composables`](/docs/4.x/
|
|
203
|
+
Note that we highly recommend using [`composables`](/docs/4.x/directory-structure/app/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
|
|
204
204
|
::
|
|
205
205
|
|
|
206
206
|
::warning
|
|
@@ -253,6 +253,9 @@ pnpm add -D vue-gtag-next
|
|
|
253
253
|
```bash [bun]
|
|
254
254
|
bun add -D vue-gtag-next
|
|
255
255
|
```
|
|
256
|
+
```bash [deno]
|
|
257
|
+
deno add -D npm:vue-gtag-next
|
|
258
|
+
```
|
|
256
259
|
::
|
|
257
260
|
|
|
258
261
|
Then create a plugin file:
|