@nuxt/docs-nightly 4.3.0-29356103.2f7957ac → 4.3.0-29430616.754c35a4
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 +4 -6
- 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 +8 -8
- package/1.getting-started/06.styling.md +15 -15
- package/1.getting-started/07.routing.md +10 -6
- package/1.getting-started/08.seo-meta.md +3 -3
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +16 -16
- package/1.getting-started/11.state-management.md +3 -3
- package/1.getting-started/12.error-handling.md +6 -6
- package/1.getting-started/13.server.md +6 -6
- package/1.getting-started/14.layers.md +32 -13
- package/1.getting-started/16.deployment.md +1 -1
- package/1.getting-started/17.testing.md +36 -5
- package/1.getting-started/18.upgrade.md +43 -35
- 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 -6
- 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 +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.middleware.md +5 -5
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.pages.md +17 -17
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.plugins.md +3 -7
- 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 +1 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +2 -2
- 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.public.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +7 -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 +1 -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.directory-structure/3.tsconfig.md +69 -0
- package/2.directory-structure/index.md +61 -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} +4 -30
- package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +7 -6
- package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +32 -25
- package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +7 -7
- 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 +2 -2
- package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +3 -2
- package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +15 -38
- 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 +2 -2
- package/3.guide/3.ai/.navigation.yml +3 -0
- package/3.guide/3.ai/1.mcp.md +255 -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 +299 -0
- package/3.guide/4.modules/4.recipes-advanced.md +231 -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 +5 -5
- package/{2.guide/4.recipes → 3.guide/5.recipes}/2.vite-plugin.md +1 -1
- package/{2.guide/4.recipes → 3.guide/5.recipes}/3.custom-usefetch.md +1 -1
- package/{2.guide/4.recipes → 3.guide/5.recipes}/4.sessions-and-authentication.md +1 -1
- 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 +10 -10
- package/{2.guide/3.going-further → 3.guide/6.going-further}/1.features.md +1 -1
- 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 +2 -2
- 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 +5 -5
- package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +42 -25
- package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +1 -1
- package/{3.api → 4.api}/1.components/10.nuxt-picture.md +1 -1
- package/{3.api → 4.api}/1.components/11.teleports.md +1 -1
- 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 +3 -3
- package/{3.api → 4.api}/1.components/3.nuxt-layout.md +5 -5
- package/{3.api → 4.api}/1.components/4.nuxt-link.md +11 -11
- package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +1 -1
- package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +1 -1
- package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +2 -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 +76 -13
- package/4.api/2.composables/use-cookie.md +183 -0
- package/{3.api → 4.api}/2.composables/use-fetch.md +33 -33
- package/{3.api → 4.api}/2.composables/use-head-safe.md +37 -20
- package/4.api/2.composables/use-head.md +184 -0
- package/{3.api → 4.api}/2.composables/use-hydration.md +24 -18
- package/4.api/2.composables/use-lazy-async-data.md +96 -0
- package/4.api/2.composables/use-lazy-fetch.md +111 -0
- package/{3.api → 4.api}/2.composables/use-nuxt-app.md +7 -7
- package/{3.api → 4.api}/2.composables/use-nuxt-data.md +1 -1
- package/{3.api → 4.api}/2.composables/use-request-fetch.md +1 -1
- 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 +1 -1
- package/{3.api → 4.api}/2.composables/use-runtime-hook.md +1 -1
- package/{3.api → 4.api}/2.composables/use-state.md +1 -1
- package/{3.api → 4.api}/3.utils/$fetch.md +1 -1
- 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 +0 -2
- package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +4 -4
- package/{3.api → 4.api}/3.utils/define-nuxt-component.md +1 -1
- package/4.api/3.utils/define-nuxt-plugin.md +102 -0
- 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 -14
- package/{3.api → 4.api}/3.utils/navigate-to.md +15 -15
- 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/refresh-cookie.md +1 -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 +18 -18
- 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 +21 -21
- 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 +29 -28
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +4 -4
- package/5.community/5.framework-contribution.md +8 -8
- package/5.community/6.roadmap.md +25 -25
- package/5.community/7.changelog.md +10 -0
- package/6.bridge/1.overview.md +1 -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 +2 -2
- package/7.migration/11.server.md +1 -1
- package/7.migration/2.configuration.md +5 -5
- 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/README.md +1 -1
- package/package.json +1 -1
- package/2.guide/1.directory-structure/3.tsconfig.md +0 -38
- 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-head.md +0 -69
- package/3.api/2.composables/use-lazy-async-data.md +0 -47
- package/3.api/2.composables/use-lazy-fetch.md +0 -55
- package/3.api/2.composables/use-router.md +0 -94
- package/3.api/3.utils/define-nuxt-plugin.md +0 -102
- 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}/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}/11.nightly-release-channel.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/1.nuxt-client-fallback.md +0 -0
- /package/{3.api → 4.api}/1.components/8.nuxt-island.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-error.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-loading-indicator.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-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-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/create-error.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-route-rules.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}/3.utils/set-page-layout.md +0 -0
- /package/{3.api → 4.api}/3.utils/set-response-status.md +0 -0
- /package/{3.api → 4.api}/3.utils/show-error.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
|
@@ -6,7 +6,7 @@ navigation.icon: i-lucide-database
|
|
|
6
6
|
|
|
7
7
|
Nuxt provides the [`useState`](/docs/4.x/api/composables/use-state) composable to create a reactive and SSR-friendly shared state across components.
|
|
8
8
|
|
|
9
|
-
[`useState`](/docs/4.x/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core
|
|
9
|
+
[`useState`](/docs/4.x/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core#ref) replacement. Its value will be preserved after server-side rendering (during client-side hydration) and shared across all components using a unique key.
|
|
10
10
|
|
|
11
11
|
:video-accordion{title="Watch a video from Alexander Lichter about why and when to use useState" videoId="mv0WcBABcIk"}
|
|
12
12
|
|
|
@@ -61,7 +61,7 @@ To globally invalidate cached state, see [`clearNuxtState`](/docs/4.x/api/utils/
|
|
|
61
61
|
|
|
62
62
|
### Initializing State
|
|
63
63
|
|
|
64
|
-
Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/4.x/
|
|
64
|
+
Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/4.x/directory-structure/app/app) component with the [`callOnce`](/docs/4.x/api/utils/call-once) util to do so.
|
|
65
65
|
|
|
66
66
|
```vue twoslash [app/app.vue]
|
|
67
67
|
<script setup lang="ts">
|
|
@@ -198,7 +198,7 @@ const date = useLocaleDate(new Date('2016-10-26'))
|
|
|
198
198
|
|
|
199
199
|
## Shared State
|
|
200
200
|
|
|
201
|
-
By using [auto-imported composables](/docs/4.x/
|
|
201
|
+
By using [auto-imported composables](/docs/4.x/directory-structure/app/composables) we can define global type-safe states and import them across the app.
|
|
202
202
|
|
|
203
203
|
```ts twoslash [composables/states.ts]
|
|
204
204
|
export const useColor = () => useState<string>('color', () => 'pink')
|
|
@@ -8,7 +8,7 @@ Nuxt is a full-stack framework, which means there are several sources of unpreve
|
|
|
8
8
|
|
|
9
9
|
- Errors during the Vue rendering lifecycle (SSR & CSR)
|
|
10
10
|
- Server and client startup errors (SSR + CSR)
|
|
11
|
-
- Errors during Nitro server lifecycle ([`server/`](/docs/4.x/
|
|
11
|
+
- Errors during Nitro server lifecycle ([`server/`](/docs/4.x/directory-structure/server) directory)
|
|
12
12
|
- Errors downloading JS chunks
|
|
13
13
|
|
|
14
14
|
::tip
|
|
@@ -17,11 +17,11 @@ Nuxt is a full-stack framework, which means there are several sources of unpreve
|
|
|
17
17
|
|
|
18
18
|
## Vue Errors
|
|
19
19
|
|
|
20
|
-
You can hook into Vue errors using [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle
|
|
20
|
+
You can hook into Vue errors using [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle#onerrorcaptured).
|
|
21
21
|
|
|
22
22
|
In addition, Nuxt provides a [`vue:error`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook that will be called if any errors propagate up to the top level.
|
|
23
23
|
|
|
24
|
-
If you are using an error reporting framework, you can provide a global handler through [`vueApp.config.errorHandler`](https://vuejs.org/api/application
|
|
24
|
+
If you are using an error reporting framework, you can provide a global handler through [`vueApp.config.errorHandler`](https://vuejs.org/api/application#app-config-errorhandler). It will receive all Vue errors, even if they are handled.
|
|
25
25
|
|
|
26
26
|
```ts twoslash [plugins/error-handler.ts]
|
|
27
27
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -37,7 +37,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
::note
|
|
40
|
-
Note that the `vue:error` hook is based on [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle
|
|
40
|
+
Note that the `vue:error` hook is based on [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle#onerrorcaptured) lifecycle hook.
|
|
41
41
|
::
|
|
42
42
|
|
|
43
43
|
## Startup Errors
|
|
@@ -45,7 +45,7 @@ Note that the `vue:error` hook is based on [`onErrorCaptured`](https://vuejs.org
|
|
|
45
45
|
Nuxt will call the `app:error` hook if there are any errors in starting your Nuxt application.
|
|
46
46
|
|
|
47
47
|
This includes:
|
|
48
|
-
- running [Nuxt plugins](/docs/4.x/
|
|
48
|
+
- running [Nuxt plugins](/docs/4.x/directory-structure/app/plugins)
|
|
49
49
|
- processing `app:created` and `app:beforeMount` hooks
|
|
50
50
|
- rendering your Vue app to HTML (during SSR)
|
|
51
51
|
- mounting the app (on client-side), though you should handle this case with `onErrorCaptured` or with `vue:error`
|
|
@@ -107,7 +107,7 @@ const handleError = () => clearError({ redirect: '/' })
|
|
|
107
107
|
</template>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
::read-more{to="/docs/4.x/
|
|
110
|
+
::read-more{to="/docs/4.x/directory-structure/app/error"}
|
|
111
111
|
Read more about `error.vue` and its uses.
|
|
112
112
|
::
|
|
113
113
|
|
|
@@ -4,7 +4,7 @@ description: Build full-stack applications with Nuxt's server framework. You can
|
|
|
4
4
|
navigation.icon: i-lucide-pc-case
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
:read-more{to="/docs/4.x/
|
|
7
|
+
:read-more{to="/docs/4.x/directory-structure/server"}
|
|
8
8
|
|
|
9
9
|
## Powered by Nitro
|
|
10
10
|
|
|
@@ -38,7 +38,7 @@ And you can directly return `text`, `json`, `html` or even a `stream`.
|
|
|
38
38
|
|
|
39
39
|
Out-of-the-box, it supports **hot module replacement** and **auto-import** like the other parts of your Nuxt application.
|
|
40
40
|
|
|
41
|
-
:read-more{to="/docs/4.x/
|
|
41
|
+
:read-more{to="/docs/4.x/directory-structure/server"}
|
|
42
42
|
|
|
43
43
|
## Universal Deployment
|
|
44
44
|
|
|
@@ -49,14 +49,14 @@ Nitro offers the ability to deploy your Nuxt app anywhere, from a bare metal ser
|
|
|
49
49
|
There are more than 15 presets to build your Nuxt app for different cloud providers and servers, including:
|
|
50
50
|
|
|
51
51
|
- [Cloudflare Workers](https://workers.cloudflare.com)
|
|
52
|
-
- [Netlify Functions](https://www.netlify.com/
|
|
53
|
-
- [Vercel
|
|
52
|
+
- [Netlify Functions](https://www.netlify.com/platform/core/functions/)
|
|
53
|
+
- [Vercel Cloud](https://vercel.com/home)
|
|
54
54
|
|
|
55
55
|
Or for other runtimes:
|
|
56
56
|
|
|
57
57
|
::card-group
|
|
58
|
-
:card{icon="i-logos-deno" title="Deno" to="https://deno.
|
|
59
|
-
:card{icon="i-logos-bun" title="Bun" to="https://bun.
|
|
58
|
+
:card{icon="i-logos-deno" title="Deno" to="https://deno.com" target="_blank"}
|
|
59
|
+
:card{icon="i-logos-bun" title="Bun" to="https://bun.com" target="_blank"}
|
|
60
60
|
::
|
|
61
61
|
|
|
62
62
|
:read-more{to="/docs/4.x/getting-started/deployment"}
|
|
@@ -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({
|
|
@@ -76,31 +76,50 @@ export default defineNuxtConfig({
|
|
|
76
76
|
|
|
77
77
|
::
|
|
78
78
|
|
|
79
|
-
Nuxt uses [unjs/c12](https://
|
|
79
|
+
Nuxt uses [unjs/c12](https://github.com/unjs/c12) and [unjs/giget](https://github.com/unjs/giget) for extending remote layers. Check the documentation for more information and all available options.
|
|
80
80
|
|
|
81
81
|
## Layer Priority
|
|
82
82
|
|
|
83
|
-
When using multiple layers, it's important to understand
|
|
83
|
+
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
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
The priority order from highest to lowest is:
|
|
86
|
+
|
|
87
|
+
1. **Your project files** - always have the highest priority
|
|
88
|
+
2. **Auto-scanned layers** from `~~/layers` directory - sorted alphabetically (Z has higher priority than A)
|
|
89
|
+
3. **Layers in `extends`** config - first entry has higher priority than second
|
|
90
|
+
|
|
91
|
+
### When to Use Each
|
|
92
|
+
|
|
93
|
+
- **`extends`** - Use for external dependencies (npm packages, remote repositories) or layers outside your project directory
|
|
94
|
+
- **`~~/layers` directory** - Use for local layers that are part of your project
|
|
95
|
+
|
|
96
|
+
::tip
|
|
97
|
+
If you need to control the order of auto-scanned layers, you can prefix them with numbers: `~/layers/1.z-layer`, `~/layers/2.a-layer`. This way `2.a-layer` will have higher priority than `1.z-layer`.
|
|
98
|
+
::
|
|
99
|
+
|
|
100
|
+
### Example
|
|
88
101
|
|
|
89
102
|
```ts [nuxt.config.ts]
|
|
90
103
|
export default defineNuxtConfig({
|
|
91
104
|
extends: [
|
|
92
|
-
//
|
|
105
|
+
// Local layer outside the project
|
|
93
106
|
'../base',
|
|
94
|
-
//
|
|
107
|
+
// NPM package
|
|
95
108
|
'@my-themes/awesome',
|
|
96
|
-
//
|
|
109
|
+
// Remote repository
|
|
97
110
|
'github:my-themes/awesome#v1',
|
|
98
111
|
],
|
|
99
|
-
// Your project has the highest priority
|
|
100
112
|
})
|
|
101
113
|
```
|
|
102
114
|
|
|
103
|
-
|
|
115
|
+
If you also have `~~/layers/custom`, the priority order is:
|
|
116
|
+
- Your project files (highest)
|
|
117
|
+
- `~~/layers/custom`
|
|
118
|
+
- `../base`
|
|
119
|
+
- `@my-themes/awesome`
|
|
120
|
+
- `github:my-themes/awesome#v1` (lowest)
|
|
121
|
+
|
|
122
|
+
This means your project files will override any layer, and `~~/layers/custom` will override anything in `extends`.
|
|
104
123
|
|
|
105
124
|
::read-more{to="/docs/4.x/guide/going-further/layers"}
|
|
106
125
|
Read more about layers in the **Layer Author Guide**.
|
|
@@ -95,7 +95,7 @@ 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
101
|
export default defineNuxtConfig({
|
|
@@ -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.
|
|
@@ -151,6 +151,37 @@ test/
|
|
|
151
151
|
|
|
152
152
|
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
153
|
|
|
154
|
+
#### TypeScript Support in Tests
|
|
155
|
+
|
|
156
|
+
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.
|
|
157
|
+
|
|
158
|
+
::tip
|
|
159
|
+
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.
|
|
160
|
+
::
|
|
161
|
+
|
|
162
|
+
##### Adding other test directories
|
|
163
|
+
|
|
164
|
+
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:
|
|
165
|
+
|
|
166
|
+
<!-- @case-police-ignore tsConfig -->
|
|
167
|
+
|
|
168
|
+
```ts [nuxt.config.ts]
|
|
169
|
+
export default defineNuxtConfig({
|
|
170
|
+
typescript: {
|
|
171
|
+
tsConfig: {
|
|
172
|
+
include: [
|
|
173
|
+
// this path is relative to the generated .nuxt/tsconfig.json
|
|
174
|
+
'../test/other-nuxt-context/**/*',
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
::important
|
|
182
|
+
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.
|
|
183
|
+
::
|
|
184
|
+
|
|
154
185
|
#### Running Tests
|
|
155
186
|
|
|
156
187
|
With the project setup, you can run different test suites:
|
|
@@ -265,9 +296,9 @@ it('can also mount an app', async () => {
|
|
|
265
296
|
|
|
266
297
|
`renderSuspended` allows you to render any Vue component within the Nuxt environment using `@testing-library/vue`, allowing async setup and access to injections from your Nuxt plugins.
|
|
267
298
|
|
|
268
|
-
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.
|
|
299
|
+
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
300
|
|
|
270
|
-
Additionally, Testing Library also relies on testing globals for cleanup. You should turn these on in your [Vitest config](https://vitest.dev/config
|
|
301
|
+
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
302
|
|
|
272
303
|
The passed in component will be rendered inside a `<div id="test-wrapper"></div>`.
|
|
273
304
|
|
|
@@ -330,10 +361,10 @@ mockNuxtImport('useStorage', () => {
|
|
|
330
361
|
```
|
|
331
362
|
|
|
332
363
|
::note
|
|
333
|
-
`mockNuxtImport` can only be used once per mocked import per test file. It is actually a macro that gets transformed to `vi.mock` and `vi.mock` is hoisted, as described [in the Vitest docs](https://vitest.dev/api/vi
|
|
364
|
+
`mockNuxtImport` can only be used once per mocked import per test file. It is actually a macro that gets transformed to `vi.mock` and `vi.mock` is hoisted, as described [in the Vitest docs](https://vitest.dev/api/vi#vi-mock).
|
|
334
365
|
::
|
|
335
366
|
|
|
336
|
-
If you need to mock a Nuxt import and provide different implementations between tests, you can do it by creating and exposing your mocks using [`vi.hoisted`](https://vitest.dev/api/vi
|
|
367
|
+
If you need to mock a Nuxt import and provide different implementations between tests, you can do it by creating and exposing your mocks using [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted), and then use those mocks in `mockNuxtImport`. You then have access to the mocked imports, and can change the implementation between tests. Be careful to [restore mocks](https://vitest.dev/api/mock#mockrestore) before or after each test to undo mock state changes between runs.
|
|
337
368
|
|
|
338
369
|
```ts twoslash
|
|
339
370
|
import { vi } from 'vitest'
|
|
@@ -54,7 +54,7 @@ export default defineNuxtConfig({
|
|
|
54
54
|
|
|
55
55
|
When you set your `future.compatibilityVersion` to `5`, defaults throughout your Nuxt configuration will change to opt in to Nuxt v5 behavior, including:
|
|
56
56
|
|
|
57
|
-
- **Vite Environment API**: Automatically enables the new [Vite Environment API](#migration-to-vite-environment-api) for improved build configuration
|
|
57
|
+
- **Vite Environment API**: Automatically enables the new [Vite Environment API](/docs/4.x/getting-started/upgrade#migration-to-vite-environment-api) for improved build configuration
|
|
58
58
|
- Other Nuxt 5 improvements and changes as they become available
|
|
59
59
|
|
|
60
60
|
::note
|
|
@@ -74,7 +74,7 @@ Nuxt 5 migrates to Vite 6's new [Environment API](https://vite.dev/guide/api-env
|
|
|
74
74
|
Previously, Nuxt used separate client and server Vite configurations. Now, Nuxt uses a shared Vite configuration with environment-specific plugins that use the `applyToEnvironment()` method to target specific environments.
|
|
75
75
|
|
|
76
76
|
::tip
|
|
77
|
-
You can test this feature early by setting `future.compatibilityVersion: 5` (see [Testing Nuxt 5](#testing-nuxt-5)) or by enabling it explicitly with `experimental.viteEnvironmentApi: true`.
|
|
77
|
+
You can test this feature early by setting `future.compatibilityVersion: 5` (see [Testing Nuxt 5](/docs/4.x/getting-started/upgrade#testing-nuxt-5)) or by enabling it explicitly with `experimental.viteEnvironmentApi: true`.
|
|
78
78
|
::
|
|
79
79
|
|
|
80
80
|
**Key changes:**
|
|
@@ -208,35 +208,35 @@ Breaking or significant changes are documented below along with migration steps
|
|
|
208
208
|
|
|
209
209
|
### Migrating Using Codemods
|
|
210
210
|
|
|
211
|
-
To facilitate the upgrade process, we have collaborated with the [Codemod](https://github.com/codemod
|
|
211
|
+
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
212
|
|
|
213
213
|
::note
|
|
214
214
|
If you encounter any issues, please report them to the Codemod team with `npx codemod feedback` 🙏
|
|
215
215
|
::
|
|
216
216
|
|
|
217
|
-
For a complete list of Nuxt 4 codemods, detailed information on each, their source, and various ways to run them, visit the [Codemod Registry](https://
|
|
217
|
+
For a complete list of Nuxt 4 codemods, detailed information on each, their source, and various ways to run them, visit the [Codemod Registry](https://app.codemod.com/registry).
|
|
218
218
|
|
|
219
219
|
You can run all the codemods mentioned in this guide using the following `codemod` recipe:
|
|
220
220
|
|
|
221
221
|
::code-group
|
|
222
222
|
|
|
223
223
|
```bash [npm]
|
|
224
|
-
# Using pinned version due to https://github.com/codemod
|
|
224
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
225
225
|
npx codemod@0.18.7 nuxt/4/migration-recipe
|
|
226
226
|
```
|
|
227
227
|
|
|
228
228
|
```bash [yarn]
|
|
229
|
-
# Using pinned version due to https://github.com/codemod
|
|
229
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
230
230
|
yarn dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
231
231
|
```
|
|
232
232
|
|
|
233
233
|
```bash [pnpm]
|
|
234
|
-
# Using pinned version due to https://github.com/codemod
|
|
234
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
235
235
|
pnpm dlx codemod@0.18.7 nuxt/4/migration-recipe
|
|
236
236
|
```
|
|
237
237
|
|
|
238
238
|
```bash [bun]
|
|
239
|
-
# Using pinned version due to https://github.com/codemod
|
|
239
|
+
# Using pinned version due to https://github.com/codemod/codemod/issues/1710
|
|
240
240
|
bun x codemod@0.18.7 nuxt/4/migration-recipe
|
|
241
241
|
```
|
|
242
242
|
|
|
@@ -463,7 +463,7 @@ export default defineNuxtConfig({
|
|
|
463
463
|
// 4. project-module-2 (can override layer modules)
|
|
464
464
|
```
|
|
465
465
|
|
|
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/
|
|
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/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
467
|
|
|
468
468
|
👉 See [PR #31507](https://github.com/nuxt/nuxt/pull/31507) and [issue #25719](https://github.com/nuxt/nuxt/issues/25719) for more details.
|
|
469
469
|
|
|
@@ -1053,7 +1053,7 @@ In Nuxt v3 we moved to a 'virtual' syntax with a `getContents()` function which
|
|
|
1053
1053
|
|
|
1054
1054
|
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
1055
|
|
|
1056
|
-
Finally, providing code serialization functions directly within Nuxt is not ideal. Instead, we maintain projects like [unjs/knitwork](
|
|
1056
|
+
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
1057
|
|
|
1058
1058
|
#### Migration Steps
|
|
1059
1059
|
|
|
@@ -1212,22 +1212,30 @@ However, to take advantage of improved type checking, you can opt in to the new
|
|
|
1212
1212
|
Augmenting types from outside the `app/`, `server/`, or `shared/` directories will not work with the new project references setup.
|
|
1213
1213
|
::
|
|
1214
1214
|
|
|
1215
|
-
5. **Configure
|
|
1215
|
+
5. **Configure TypeScript options** if needed:
|
|
1216
1216
|
<!-- @case-police-ignore tsConfig -->
|
|
1217
1217
|
|
|
1218
1218
|
```ts
|
|
1219
1219
|
export default defineNuxtConfig({
|
|
1220
1220
|
typescript: {
|
|
1221
|
-
//
|
|
1221
|
+
// customize tsconfig.app.json
|
|
1222
1222
|
tsConfig: {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1223
|
+
// ...
|
|
1224
|
+
},
|
|
1225
|
+
// customize tsconfig.shared.json
|
|
1226
|
+
sharedTsConfig: {
|
|
1227
|
+
// ...
|
|
1226
1228
|
},
|
|
1227
|
-
//
|
|
1229
|
+
// customize tsconfig.node.json
|
|
1228
1230
|
nodeTsConfig: {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
+
// ...
|
|
1232
|
+
},
|
|
1233
|
+
},
|
|
1234
|
+
nitro: {
|
|
1235
|
+
typescript: {
|
|
1236
|
+
// customize tsconfig.server.json
|
|
1237
|
+
tsConfig: {
|
|
1238
|
+
// ...
|
|
1231
1239
|
},
|
|
1232
1240
|
},
|
|
1233
1241
|
},
|
|
@@ -1304,23 +1312,23 @@ Read more about Nitro's prerender configuration options.
|
|
|
1304
1312
|
|
|
1305
1313
|
In the table below, there is a quick comparison between 3 versions of Nuxt:
|
|
1306
1314
|
|
|
1307
|
-
Feature / Version
|
|
1308
|
-
|
|
1309
|
-
Vue
|
|
1310
|
-
Stability
|
|
1311
|
-
Performance
|
|
1312
|
-
Nitro Engine
|
|
1313
|
-
ESM support
|
|
1314
|
-
TypeScript
|
|
1315
|
-
Composition API
|
|
1316
|
-
Options API
|
|
1317
|
-
Components Auto Import
|
|
1318
|
-
`<script setup>` syntax
|
|
1319
|
-
Auto Imports
|
|
1320
|
-
webpack
|
|
1321
|
-
Vite
|
|
1322
|
-
Nuxt CLI
|
|
1323
|
-
Static sites
|
|
1315
|
+
| Feature / Version | Nuxt 2 | Nuxt Bridge | Nuxt 3+ |
|
|
1316
|
+
|-------------------------|------------|-------------|------------|
|
|
1317
|
+
| Vue | 2 | 2 | 3 |
|
|
1318
|
+
| Stability | 😊 Stable | 😊 Stable | 😊 Stable |
|
|
1319
|
+
| Performance | 🏎 Fast | ✈️ Faster | 🚀 Fastest |
|
|
1320
|
+
| Nitro Engine | ❌ | ✅ | ✅ |
|
|
1321
|
+
| ESM support | 🌙 Partial | 👍 Better | ✅ |
|
|
1322
|
+
| TypeScript | ☑️ Opt-in | 🚧 Partial | ✅ |
|
|
1323
|
+
| Composition API | ❌ | 🚧 Partial | ✅ |
|
|
1324
|
+
| Options API | ✅ | ✅ | ✅ |
|
|
1325
|
+
| Components Auto Import | ✅ | ✅ | ✅ |
|
|
1326
|
+
| `<script setup>` syntax | ❌ | 🚧 Partial | ✅ |
|
|
1327
|
+
| Auto Imports | ❌ | ✅ | ✅ |
|
|
1328
|
+
| webpack | 4 | 4 | 5 |
|
|
1329
|
+
| Vite | ⚠️ Partial | 🚧 Partial | ✅ |
|
|
1330
|
+
| Nuxt CLI | ❌ Old | ✅ nuxt | ✅ nuxt |
|
|
1331
|
+
| Static sites | ✅ | ✅ | ✅ |
|
|
1324
1332
|
|
|
1325
1333
|
## Nuxt 2 to Nuxt 3+
|
|
1326
1334
|
|
|
@@ -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"}
|
|
@@ -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/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
|
|
|
@@ -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>
|
|
@@ -34,7 +34,7 @@ If no layout is specified, `app/layouts/default.vue` will be used.
|
|
|
34
34
|
::
|
|
35
35
|
|
|
36
36
|
::important
|
|
37
|
-
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/4.x/
|
|
37
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/4.x/directory-structure/app/app) instead.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
::important
|
|
@@ -74,7 +74,7 @@ definePageMeta({
|
|
|
74
74
|
</script>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
::read-more{to="/docs/4.x/
|
|
77
|
+
::read-more{to="/docs/4.x/directory-structure/app/pages#page-metadata"}
|
|
78
78
|
Learn more about `definePageMeta`.
|
|
79
79
|
::
|
|
80
80
|
|
|
@@ -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"}
|
|
@@ -48,13 +48,13 @@ Nuxt provides two globally available helpers that can be returned directly from
|
|
|
48
48
|
1. [`navigateTo`](/docs/4.x/api/utils/navigate-to) - Redirects to the given route
|
|
49
49
|
2. [`abortNavigation`](/docs/4.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
|
|
|
@@ -62,7 +62,7 @@ Possible return values are:
|
|
|
62
62
|
:read-more{to="/docs/4.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
|