@nuxt/docs 3.20.1 → 3.21.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 +5 -5
- package/1.getting-started/02.installation.md +4 -7
- package/1.getting-started/03.configuration.md +32 -32
- package/1.getting-started/04.views.md +10 -8
- package/1.getting-started/05.assets.md +8 -8
- package/1.getting-started/06.styling.md +24 -18
- package/1.getting-started/07.routing.md +11 -11
- package/1.getting-started/08.seo-meta.md +10 -6
- package/1.getting-started/09.transitions.md +12 -12
- package/1.getting-started/10.data-fetching.md +18 -18
- package/1.getting-started/11.state-management.md +7 -7
- package/1.getting-started/12.error-handling.md +28 -22
- package/1.getting-started/13.server.md +9 -9
- package/1.getting-started/14.layers.md +52 -18
- package/1.getting-started/15.prerendering.md +10 -4
- package/1.getting-started/16.deployment.md +3 -2
- package/1.getting-started/17.testing.md +18 -8
- package/1.getting-started/18.upgrade.md +111 -60
- 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 +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.assets.md +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.components.md +13 -9
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.composables.md +4 -4
- 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.layouts.md +37 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.middleware.md +8 -8
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +10 -4
- 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.pages.md +43 -22
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.plugins.md +6 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +29 -9
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.utils.md +5 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +4 -4
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +2 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +6 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.app-config.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.app.md +5 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.error.md +10 -8
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +2 -2
- 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 +3 -2
- package/2.directory-structure/index.md +65 -0
- package/3.guide/0.index.md +28 -0
- package/{2.guide/2.concepts/3.rendering.md → 3.guide/1.concepts/1.rendering.md} +8 -33
- package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +11 -10
- package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +34 -27
- package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +10 -10
- 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 +5 -4
- package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +11 -17
- package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +1 -1
- package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +1 -1
- package/{2.guide/5.best-practices → 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 +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 +4 -4
- 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 +3 -3
- 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 +3 -4
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.experimental-features.md +212 -87
- package/3.guide/6.going-further/1.features.md +108 -0
- 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}/11.nightly-release-channel.md +1 -1
- package/{2.guide/3.going-further → 3.guide/6.going-further}/2.hooks.md +7 -7
- package/{2.guide/3.going-further → 3.guide/6.going-further}/4.kit.md +3 -3
- package/{2.guide/3.going-further → 3.guide/6.going-further}/6.nuxt-app.md +6 -6
- package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +40 -14
- package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +3 -2
- package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +5 -1
- package/{3.api → 4.api}/1.components/10.nuxt-picture.md +1 -1
- package/{3.api → 4.api}/1.components/11.teleports.md +2 -2
- 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 +4 -4
- package/{3.api → 4.api}/1.components/3.nuxt-layout.md +7 -7
- package/{3.api → 4.api}/1.components/4.nuxt-link.md +13 -13
- package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +2 -2
- package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +2 -2
- 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 +5 -5
- package/4.api/2.composables/use-cookie.md +183 -0
- package/{3.api → 4.api}/2.composables/use-error.md +3 -3
- package/{3.api → 4.api}/2.composables/use-fetch.md +37 -37
- package/{3.api → 4.api}/2.composables/use-head-safe.md +1 -1
- package/{3.api → 4.api}/2.composables/use-head.md +22 -7
- package/{3.api → 4.api}/2.composables/use-lazy-async-data.md +1 -1
- package/{3.api → 4.api}/2.composables/use-lazy-fetch.md +9 -9
- package/{3.api → 4.api}/2.composables/use-nuxt-app.md +11 -9
- 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 +2 -2
- package/4.api/2.composables/use-router.md +94 -0
- package/{3.api → 4.api}/2.composables/use-runtime-config.md +5 -5
- package/{3.api → 4.api}/2.composables/use-seo-meta.md +2 -2
- package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +2 -2
- package/{3.api → 4.api}/2.composables/use-state.md +12 -2
- package/{3.api → 4.api}/3.utils/$fetch.md +2 -2
- package/{3.api → 4.api}/3.utils/abort-navigation.md +3 -3
- package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
- package/{3.api → 4.api}/3.utils/call-once.md +2 -4
- package/{3.api → 4.api}/3.utils/clear-error.md +1 -1
- package/{3.api → 4.api}/3.utils/create-error.md +7 -7
- package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +5 -5
- package/{3.api → 4.api}/3.utils/define-nuxt-component.md +1 -1
- 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 +3 -3
- package/{3.api → 4.api}/3.utils/define-page-meta.md +23 -16
- package/{3.api → 4.api}/3.utils/define-route-rules.md +2 -2
- package/{3.api → 4.api}/3.utils/navigate-to.md +14 -14
- package/{3.api → 4.api}/3.utils/on-before-route-leave.md +1 -1
- package/{3.api → 4.api}/3.utils/on-before-route-update.md +1 -1
- package/{3.api → 4.api}/3.utils/preload-route-components.md +2 -2
- package/{3.api → 4.api}/3.utils/refresh-cookie.md +0 -2
- package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +1 -1
- package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +1 -1
- package/{3.api → 4.api}/3.utils/set-page-layout.md +36 -0
- package/{3.api → 4.api}/3.utils/set-response-status.md +3 -3
- package/{3.api → 4.api}/3.utils/show-error.md +4 -4
- 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 +31 -18
- package/{3.api → 4.api}/5.kit/10.templates.md +23 -23
- package/{3.api → 4.api}/5.kit/11.nitro.md +36 -36
- package/{3.api → 4.api}/5.kit/12.resolving.md +2 -2
- package/{3.api → 4.api}/5.kit/14.builder.md +35 -23
- package/{3.api → 4.api}/5.kit/16.layers.md +16 -16
- package/{3.api → 4.api}/5.kit/2.programmatic.md +2 -2
- package/{3.api → 4.api}/5.kit/3.compatibility.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/{3.api → 4.api}/5.kit/6.context.md +1 -1
- package/{3.api → 4.api}/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +105 -0
- package/{3.api → 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 +25 -25
- package/5.community/7.changelog.md +20 -0
- package/6.bridge/1.overview.md +9 -1
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- 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 +6 -6
- package/7.migration/20.module-authors.md +3 -3
- package/7.migration/3.auto-imports.md +1 -1
- 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 +9 -9
- package/7.migration/7.component-options.md +6 -6
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
- package/2.guide/0.index.md +0 -25
- package/2.guide/3.going-further/1.features.md +0 -103
- package/2.guide/3.going-further/3.modules.md +0 -901
- package/3.api/2.composables/use-cookie.md +0 -183
- package/3.api/2.composables/use-router.md +0 -94
- 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}/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/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +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}/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/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-hydration.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}/3.utils/.navigation.yml +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/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/prerender-routes.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/13.logging.md +0 -0
- /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
- /package/{3.api → 4.api}/5.kit/7.pages.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}/6.nuxt-config.md +0 -0
|
@@ -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`
|
|
@@ -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/3.x/api/kit/components#addcomponent) in a [local module](/docs/3.x/
|
|
361
|
+
If you want to auto-import components from an npm package, you can use [`addComponent`](/docs/3.x/api/kit/components#addcomponent) in a [local module](/docs/3.x/directory-structure/modules) to register them.
|
|
362
362
|
|
|
363
363
|
::code-group
|
|
364
364
|
|
|
@@ -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
|
|
|
@@ -71,7 +71,7 @@ export const useFoo = () => {
|
|
|
71
71
|
|
|
72
72
|
### Access plugin injections
|
|
73
73
|
|
|
74
|
-
You can access [plugin injections](/docs/3.x/
|
|
74
|
+
You can access [plugin injections](/docs/3.x/directory-structure/plugins#providing-helpers) from composables:
|
|
75
75
|
|
|
76
76
|
```ts [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 [`composables/` directory](/docs/3.x/
|
|
85
|
+
Nuxt only scans files at the top level of the [`composables/` directory](/docs/3.x/directory-structure/composables), e.g.:
|
|
86
86
|
|
|
87
87
|
```bash [Directory Structure]
|
|
88
88
|
-| composables/
|
|
@@ -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.
|
|
@@ -36,7 +36,7 @@ The module automatically loads and parses them.
|
|
|
36
36
|
|
|
37
37
|
## Render Content
|
|
38
38
|
|
|
39
|
-
To render content pages, add a [catch-all route](/docs/3.x/
|
|
39
|
+
To render content pages, add a [catch-all route](/docs/3.x/directory-structure/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
40
40
|
|
|
41
41
|
```vue [pages/[...slug\\].vue]
|
|
42
42
|
<script lang="ts" setup>
|
|
@@ -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"}
|
|
@@ -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/3.x/api/components/nuxt-layout) to your [`app.vue`](/docs/3.x/
|
|
14
|
+
Layouts are enabled by adding [`<NuxtLayout>`](/docs/3.x/api/components/nuxt-layout) to your [`app.vue`](/docs/3.x/directory-structure/app):
|
|
15
15
|
|
|
16
16
|
```vue [app.vue]
|
|
17
17
|
<template>
|
|
@@ -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`.
|
|
@@ -34,7 +35,7 @@ If no layout is specified, `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/3.x/
|
|
38
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/3.x/directory-structure/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/
|
|
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
|
|
|
@@ -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/3.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/3.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"}
|
|
@@ -48,21 +48,21 @@ Nuxt provides two globally available helpers that can be returned directly from
|
|
|
48
48
|
1. [`navigateTo`](/docs/3.x/api/utils/navigate-to) - Redirects to the given route
|
|
49
49
|
2. [`abortNavigation`](/docs/3.x/api/utils/abort-navigation) - Aborts the navigation, with an optional error message.
|
|
50
50
|
|
|
51
|
-
Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-guards
|
|
51
|
+
Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards) from `vue-router`, a third `next()` argument is not passed, and **redirect or route cancellation is handled by returning a value from the middleware**.
|
|
52
52
|
|
|
53
53
|
Possible return values are:
|
|
54
54
|
|
|
55
55
|
* nothing (a simple `return` or no return at all) - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
|
|
56
|
-
* `return navigateTo('/')` - redirects to the given path and will set the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) if the redirect happens on the server side
|
|
57
|
-
* `return navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) if the redirect happens on the server side
|
|
56
|
+
* `return navigateTo('/')` - redirects to the given path and will set the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302) if the redirect happens on the server side
|
|
57
|
+
* `return navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301) if the redirect happens on the server side
|
|
58
58
|
* `return abortNavigation()` - stops the current navigation
|
|
59
59
|
* `return abortNavigation(error)` - rejects the current navigation with an error
|
|
60
60
|
|
|
61
|
-
:read-more{to="/docs/api/utils/navigate-to"}
|
|
62
|
-
:read-more{to="/docs/api/utils/abort-navigation"}
|
|
61
|
+
:read-more{to="/docs/3.x/api/utils/navigate-to"}
|
|
62
|
+
:read-more{to="/docs/3.x/api/utils/abort-navigation"}
|
|
63
63
|
|
|
64
64
|
::important
|
|
65
|
-
We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards
|
|
65
|
+
We recommend using the helper functions above for performing redirects or stopping navigation. Other possible return values described in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards#Global-Before-Guards) may work but there may be breaking changes in future.
|
|
66
66
|
::
|
|
67
67
|
|
|
68
68
|
## Middleware Order
|
|
@@ -222,7 +222,7 @@ definePageMeta({
|
|
|
222
222
|
|
|
223
223
|
Now, before navigation to that page can complete, the `auth` route middleware will be run.
|
|
224
224
|
|
|
225
|
-
:link-example{to="/docs/examples/routing/middleware"}
|
|
225
|
+
:link-example{to="/docs/3.x/examples/routing/middleware"}
|
|
226
226
|
|
|
227
227
|
## Setting Middleware at Build Time
|
|
228
228
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: 'modules'
|
|
3
3
|
head.title: 'modules/'
|
|
4
4
|
description: Use the modules/ directory to automatically register local modules within your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-nuxt
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
It is a good place to place any local modules you develop while building your application.
|
|
@@ -11,14 +11,14 @@ The auto-registered files patterns are:
|
|
|
11
11
|
- `modules/*/index.ts`
|
|
12
12
|
- `modules/*.ts`
|
|
13
13
|
|
|
14
|
-
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/3.x/
|
|
14
|
+
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) separately.
|
|
15
15
|
|
|
16
16
|
::code-group
|
|
17
17
|
|
|
18
18
|
```ts twoslash [modules/hello/index.ts]
|
|
19
19
|
// `nuxt/kit` is a helper subpath import you can use when defining local modules
|
|
20
20
|
// that means you do not need to add `@nuxt/kit` to your project's dependencies
|
|
21
|
-
import { addServerHandler, createResolver, defineNuxtModule } from 'nuxt/kit'
|
|
21
|
+
import { addComponentsDir, addServerHandler, createResolver, defineNuxtModule } from 'nuxt/kit'
|
|
22
22
|
|
|
23
23
|
export default defineNuxtModule({
|
|
24
24
|
meta: {
|
|
@@ -32,6 +32,12 @@ export default defineNuxtModule({
|
|
|
32
32
|
route: '/api/hello',
|
|
33
33
|
handler: resolver.resolve('./runtime/api-route'),
|
|
34
34
|
})
|
|
35
|
+
|
|
36
|
+
// Add components
|
|
37
|
+
addComponentsDir({
|
|
38
|
+
path: resolver.resolve('./runtime/app/components'),
|
|
39
|
+
pathPrefix: true, // Prefix your exports to avoid conflicts with user code or other modules
|
|
40
|
+
})
|
|
35
41
|
},
|
|
36
42
|
})
|
|
37
43
|
```
|
|
@@ -59,7 +65,7 @@ modules/
|
|
|
59
65
|
2.second-module.ts
|
|
60
66
|
```
|
|
61
67
|
|
|
62
|
-
:read-more{to="/docs/guide/
|
|
68
|
+
:read-more{to="/docs/3.x/guide/modules"}
|
|
63
69
|
|
|
64
70
|
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/creating-your-first-module-from-scratch?friend=nuxt" target="_blank"}
|
|
65
71
|
Watch Vue School video about Nuxt private modules.
|
|
@@ -5,8 +5,8 @@ head.title: "node_modules/"
|
|
|
5
5
|
navigation.icon: i-vscode-icons-folder-type-node
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm/) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.com/package-manager)) creates this directory to store the dependencies of your project.
|
|
8
|
+
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm/) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.com/package-manager) or [`deno`](https://docs.deno.com/runtime/getting_started/installation/)) creates this directory to store the dependencies of your project.
|
|
9
9
|
|
|
10
10
|
::important
|
|
11
|
-
This directory should be added to your [`.gitignore`](/docs/3.x/
|
|
11
|
+
This directory should be added to your [`.gitignore`](/docs/3.x/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
12
12
|
::
|
|
@@ -6,12 +6,12 @@ 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/3.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/3.x/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/3.x/guide/recipes/custom-routing#using-routeroptions).
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
Pages are Vue components and can have any [valid extension](/docs/3.x/api/
|
|
14
|
+
Pages are Vue components and can have any [valid extension](/docs/3.x/api/nuxt-config#extensions) that Nuxt supports (by default `.vue`, `.js`, `.jsx`, `.mjs`, `.ts` or `.tsx`).
|
|
15
15
|
|
|
16
16
|
Nuxt will automatically create a route for every page in your `~/pages/` directory.
|
|
17
17
|
|
|
@@ -33,7 +33,7 @@ export default defineComponent({
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
```tsx twoslash [pages/index.tsx]
|
|
36
|
-
// https://nuxt.com/docs/examples/advanced/jsx
|
|
36
|
+
// https://nuxt.com/docs/3.x/examples/advanced/jsx
|
|
37
37
|
// https://vuejs.org/guide/extras/render-function.html#jsx-tsx
|
|
38
38
|
export default defineComponent({
|
|
39
39
|
render () {
|
|
@@ -46,7 +46,7 @@ export default defineComponent({
|
|
|
46
46
|
|
|
47
47
|
The `pages/index.vue` file will be mapped to the `/` route of your application.
|
|
48
48
|
|
|
49
|
-
If you are using [`app.vue`](/docs/3.x/
|
|
49
|
+
If you are using [`app.vue`](/docs/3.x/directory-structure/app), make sure to use the [`<NuxtPage/>`](/docs/3.x/api/components/nuxt-page) component to display the current page:
|
|
50
50
|
|
|
51
51
|
```vue [app.vue]
|
|
52
52
|
<template>
|
|
@@ -93,7 +93,7 @@ Here are some examples to illustrate what a page with a single root element look
|
|
|
93
93
|
|
|
94
94
|
## Dynamic Routes
|
|
95
95
|
|
|
96
|
-
If you place anything within square brackets, it will be turned into a [dynamic route](https://router.vuejs.org/guide/essentials/dynamic-matching
|
|
96
|
+
If you place anything within square brackets, it will be turned into a [dynamic route](https://router.vuejs.org/guide/essentials/dynamic-matching) parameter. You can mix and match multiple parameters and even non-dynamic text within a file name or directory.
|
|
97
97
|
|
|
98
98
|
If you want a parameter to be _optional_, you must enclose it in double square brackets - for example, `~/pages/[[slug]]/index.vue` or `~/pages/[[slug]].vue` will match both `/` and `/test`.
|
|
99
99
|
|
|
@@ -154,7 +154,7 @@ Navigating to `/hello/world` would render:
|
|
|
154
154
|
|
|
155
155
|
## Nested Routes
|
|
156
156
|
|
|
157
|
-
It is possible to display [nested routes](https://
|
|
157
|
+
It is possible to display [nested routes](https://router.vuejs.org/guide/essentials/nested-routes) with `<NuxtPage>`.
|
|
158
158
|
|
|
159
159
|
Example:
|
|
160
160
|
|
|
@@ -228,7 +228,7 @@ definePageMeta({
|
|
|
228
228
|
</script>
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
:link-example{to="/docs/examples/routing/pages"}
|
|
231
|
+
:link-example{to="/docs/3.x/examples/routing/pages"}
|
|
232
232
|
|
|
233
233
|
## Route Groups
|
|
234
234
|
|
|
@@ -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>`:
|
|
@@ -268,9 +289,9 @@ console.log(route.meta.title) // My home page
|
|
|
268
289
|
</script>
|
|
269
290
|
```
|
|
270
291
|
|
|
271
|
-
If you are using nested routes, the page metadata from all these routes will be merged into a single object. For more on route meta, see the [vue-router docs](https://router.vuejs.org/guide/advanced/meta
|
|
292
|
+
If you are using nested routes, the page metadata from all these routes will be merged into a single object. For more on route meta, see the [vue-router docs](https://router.vuejs.org/guide/advanced/meta).
|
|
272
293
|
|
|
273
|
-
Much like `defineEmits` or `defineProps` (see [Vue docs](https://vuejs.org/api/sfc-script-setup
|
|
294
|
+
Much like `defineEmits` or `defineProps` (see [Vue docs](https://vuejs.org/api/sfc-script-setup#defineprops-defineemits)), `definePageMeta` is a **compiler macro**. It will be compiled away so you cannot reference it within your component. Instead, the metadata passed to it will be hoisted out of the component.
|
|
274
295
|
Therefore, the page meta object cannot reference the component. However, it can reference imported bindings, as well as locally defined **pure functions**.
|
|
275
296
|
|
|
276
297
|
::warning
|
|
@@ -301,33 +322,33 @@ Of course, you are welcome to define metadata for your own use throughout your a
|
|
|
301
322
|
|
|
302
323
|
#### `alias`
|
|
303
324
|
|
|
304
|
-
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [in the vue-router documentation](https://router.vuejs.org/guide/essentials/redirect-and-alias
|
|
325
|
+
You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of strings as defined [in the vue-router documentation](https://router.vuejs.org/guide/essentials/redirect-and-alias#Alias).
|
|
305
326
|
|
|
306
327
|
#### `keepalive`
|
|
307
328
|
|
|
308
|
-
Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](https://vuejs.org/guide/built-ins/keep-alive
|
|
329
|
+
Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](https://vuejs.org/guide/built-ins/keep-alive#keepalive) if you set `keepalive: true` in your `definePageMeta`. This might be useful to do, for example, in a parent route that has dynamic child routes, if you want to preserve page state across route changes.
|
|
309
330
|
|
|
310
|
-
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components
|
|
331
|
+
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components#keepalive)).
|
|
311
332
|
|
|
312
333
|
You can set a default value for this property [in your `nuxt.config`](/docs/3.x/api/nuxt-config#keepalive).
|
|
313
334
|
|
|
314
335
|
#### `key`
|
|
315
336
|
|
|
316
|
-
[See above](#child-route-keys).
|
|
337
|
+
[See above](/docs/3.x/directory-structure/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/3.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/3.x/directory-structure/layouts).
|
|
321
342
|
|
|
322
343
|
#### `layoutTransition` and `pageTransition`
|
|
323
344
|
|
|
324
|
-
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components
|
|
345
|
+
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components#transition) or read [more about how transitions work](https://vuejs.org/guide/built-ins/transition#transition).
|
|
325
346
|
|
|
326
347
|
You can set default values for these properties [in your `nuxt.config`](/docs/3.x/api/nuxt-config#layouttransition).
|
|
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
|
|
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/3.x/directory-structure/middleware).
|
|
331
352
|
|
|
332
353
|
#### `name`
|
|
333
354
|
|
|
@@ -335,7 +356,7 @@ You may define a name for this page's route.
|
|
|
335
356
|
|
|
336
357
|
#### `path`
|
|
337
358
|
|
|
338
|
-
You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/route-matching-syntax
|
|
359
|
+
You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/route-matching-syntax#Custom-regex-in-params) for more information.
|
|
339
360
|
|
|
340
361
|
#### `props`
|
|
341
362
|
|
|
@@ -370,7 +391,7 @@ A simple link to the `index.vue` page in your `pages` folder:
|
|
|
370
391
|
</template>
|
|
371
392
|
```
|
|
372
393
|
|
|
373
|
-
::read-more{to="/docs/api/components/nuxt-link"}
|
|
394
|
+
::read-more{to="/docs/3.x/api/components/nuxt-link"}
|
|
374
395
|
Learn more about `<NuxtLink>` usage.
|
|
375
396
|
::
|
|
376
397
|
|
|
@@ -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/3.x/
|
|
425
|
+
You can define a page as [client only](/docs/3.x/directory-structure/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/3.x/
|
|
429
|
+
You can define a page as [server only](/docs/3.x/directory-structure/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.)
|
|
@@ -415,7 +436,7 @@ Server-only pages must have a single root element. (HTML comments are considered
|
|
|
415
436
|
|
|
416
437
|
As your app gets bigger and more complex, your routing might require more flexibility. For this reason, Nuxt directly exposes the router, routes and router options for customization in different ways.
|
|
417
438
|
|
|
418
|
-
:read-more{to="/docs/guide/recipes/custom-routing"}
|
|
439
|
+
:read-more{to="/docs/3.x/guide/recipes/custom-routing"}
|
|
419
440
|
|
|
420
441
|
## Multiple Pages Directories
|
|
421
442
|
|
|
@@ -443,4 +464,4 @@ export default defineNuxtConfig({
|
|
|
443
464
|
})
|
|
444
465
|
```
|
|
445
466
|
|
|
446
|
-
:read-more{to="/docs/guide/going-further/layers"}
|
|
467
|
+
:read-more{to="/docs/3.x/guide/going-further/layers"}
|
|
@@ -134,7 +134,7 @@ export default defineNuxtPlugin({
|
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/3.x/
|
|
137
|
+
You can use [composables](/docs/3.x/directory-structure/composables) as well as [utils](/docs/3.x/directory-structure/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
139
|
```ts [plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -200,12 +200,12 @@ const { $hello } = useNuxtApp()
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
::important
|
|
203
|
-
Note that we highly recommend using [`composables`](/docs/3.x/
|
|
203
|
+
Note that we highly recommend using [`composables`](/docs/3.x/directory-structure/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
|
|
207
207
|
**If your plugin provides a `ref` or `computed`, it will not be unwrapped in a component `<template>`.** :br
|
|
208
|
-
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals
|
|
208
|
+
This is due to how Vue works with refs that aren't top-level to the template. You can read more about it [in the Vue documentation](https://vuejs.org/guide/essentials/reactivity-fundamentals#caveat-when-unwrapping-in-templates).
|
|
209
209
|
::
|
|
210
210
|
|
|
211
211
|
## Typing Plugins
|
|
@@ -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:
|