@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
|
@@ -5,12 +5,12 @@ navigation.icon: i-lucide-toggle-right
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
::note
|
|
8
|
-
Nuxt leverages Vue's [`<Transition>`](https://vuejs.org/guide/built-ins/transition
|
|
8
|
+
Nuxt leverages Vue's [`<Transition>`](https://vuejs.org/guide/built-ins/transition#the-transition-component) component to apply transitions between pages and layouts.
|
|
9
9
|
::
|
|
10
10
|
|
|
11
11
|
## Page Transitions
|
|
12
12
|
|
|
13
|
-
You can enable page transitions to apply an automatic transition for all your [pages](/docs/3.x/
|
|
13
|
+
You can enable page transitions to apply an automatic transition for all your [pages](/docs/3.x/directory-structure/pages).
|
|
14
14
|
|
|
15
15
|
```ts twoslash [nuxt.config.ts]
|
|
16
16
|
export default defineNuxtConfig({
|
|
@@ -24,7 +24,7 @@ export default defineNuxtConfig({
|
|
|
24
24
|
If you are changing layouts as well as page, the page transition you set here will not run. Instead, you should set a [layout transition](/docs/3.x/getting-started/transitions#layout-transitions).
|
|
25
25
|
::
|
|
26
26
|
|
|
27
|
-
To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/3.x/
|
|
27
|
+
To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/3.x/directory-structure/app):
|
|
28
28
|
|
|
29
29
|
::code-group
|
|
30
30
|
|
|
@@ -115,7 +115,7 @@ Moving to the about page will add the 3d rotation effect:
|
|
|
115
115
|
|
|
116
116
|
## Layout Transitions
|
|
117
117
|
|
|
118
|
-
You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/3.x/
|
|
118
|
+
You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/3.x/directory-structure/layouts).
|
|
119
119
|
|
|
120
120
|
```ts twoslash [nuxt.config.ts]
|
|
121
121
|
export default defineNuxtConfig({
|
|
@@ -125,7 +125,7 @@ export default defineNuxtConfig({
|
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/3.x/
|
|
128
|
+
To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/3.x/directory-structure/app):
|
|
129
129
|
|
|
130
130
|
::code-group
|
|
131
131
|
|
|
@@ -229,7 +229,7 @@ definePageMeta({
|
|
|
229
229
|
|
|
230
230
|
You can customize these default transition names globally using `nuxt.config`.
|
|
231
231
|
|
|
232
|
-
Both `pageTransition` and `layoutTransition` keys accept [`TransitionProps`](https://vuejs.org/api/built-in-components
|
|
232
|
+
Both `pageTransition` and `layoutTransition` keys accept [`TransitionProps`](https://vuejs.org/api/built-in-components#transition) as JSON serializable values where you can pass the `name`, `mode` and other valid transition-props of the custom CSS transition.
|
|
233
233
|
|
|
234
234
|
```ts twoslash [nuxt.config.ts]
|
|
235
235
|
export default defineNuxtConfig({
|
|
@@ -310,12 +310,12 @@ definePageMeta({
|
|
|
310
310
|
```
|
|
311
311
|
|
|
312
312
|
::tip
|
|
313
|
-
Learn more about additional [JavaScript hooks](https://vuejs.org/guide/built-ins/transition
|
|
313
|
+
Learn more about additional [JavaScript hooks](https://vuejs.org/guide/built-ins/transition#javascript-hooks) available in the `Transition` component.
|
|
314
314
|
::
|
|
315
315
|
|
|
316
316
|
## Dynamic Transitions
|
|
317
317
|
|
|
318
|
-
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/3.x/
|
|
318
|
+
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/3.x/directory-structure/middleware) to assign a different transition name to `to.meta.pageTransition`.
|
|
319
319
|
|
|
320
320
|
::code-group
|
|
321
321
|
|
|
@@ -416,11 +416,11 @@ Remember, this page transition cannot be overridden with `definePageMeta` on ind
|
|
|
416
416
|
|
|
417
417
|
## View Transitions API (experimental)
|
|
418
418
|
|
|
419
|
-
Nuxt ships with an experimental implementation of the [**View Transitions API**](https://developer.chrome.com/docs/web-platform/view-transitions) (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/
|
|
419
|
+
Nuxt ships with an experimental implementation of the [**View Transitions API**](https://developer.chrome.com/docs/web-platform/view-transitions) (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API)). This is an exciting new way to implement native browser transitions which (among other things) have the ability to transition between unrelated elements on different pages.
|
|
420
420
|
|
|
421
|
-
You can check a demo
|
|
421
|
+
You can check a demo [on StackBlitz](https://stackblitz.com/edit/nuxt-view-transitions).
|
|
422
422
|
|
|
423
|
-
The Nuxt integration
|
|
423
|
+
The Nuxt integration can be enabled with the `experimental.viewTransition` option in your configuration file:
|
|
424
424
|
|
|
425
425
|
```ts twoslash [nuxt.config.ts]
|
|
426
426
|
export default defineNuxtConfig({
|
|
@@ -434,7 +434,7 @@ The possible values are: `false`, `true`, or `'always'`.
|
|
|
434
434
|
|
|
435
435
|
If set to true, Nuxt will not apply transitions if the user's browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition and it is up to you to respect the user's preference.
|
|
436
436
|
|
|
437
|
-
By default, view transitions are enabled for all [pages](/docs/3.x/
|
|
437
|
+
By default, view transitions are enabled for all [pages](/docs/3.x/directory-structure/pages), but you can set a different global default.
|
|
438
438
|
|
|
439
439
|
```ts twoslash [nuxt.config.ts]
|
|
440
440
|
export default defineNuxtConfig({
|
|
@@ -80,11 +80,11 @@ async function addTodo () {
|
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
::warning
|
|
83
|
-
Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](#the-need-for-usefetch-and-useasyncdata). :br
|
|
84
|
-
It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](#useasyncdata) when fetching the initial component data.
|
|
83
|
+
Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](/docs/3.x/getting-started/data-fetching#the-need-for-usefetch-and-useasyncdata). :br
|
|
84
|
+
It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](/docs/3.x/getting-started/data-fetching#useasyncdata) when fetching the initial component data.
|
|
85
85
|
::
|
|
86
86
|
|
|
87
|
-
::read-more{to="/docs/api/utils/dollarfetch"}
|
|
87
|
+
::read-more{to="/docs/3.x/api/utils/dollarfetch"}
|
|
88
88
|
Read more about `$fetch`.
|
|
89
89
|
::
|
|
90
90
|
|
|
@@ -146,9 +146,9 @@ This composable is a wrapper around the [`useAsyncData`](/docs/3.x/api/composabl
|
|
|
146
146
|
|
|
147
147
|
:video-accordion{title="Watch a video from Alexander Lichter to avoid using useFetch the wrong way" videoId="njsGVmcWviY"}
|
|
148
148
|
|
|
149
|
-
:read-more{to="/docs/api/composables/use-fetch"}
|
|
149
|
+
:read-more{to="/docs/3.x/api/composables/use-fetch"}
|
|
150
150
|
|
|
151
|
-
:link-example{to="/docs/examples/features/data-fetching"}
|
|
151
|
+
:link-example{to="/docs/3.x/examples/features/data-fetching"}
|
|
152
152
|
|
|
153
153
|
## `useAsyncData`
|
|
154
154
|
|
|
@@ -220,7 +220,7 @@ await useAsyncData(() => offersStore.getOffer(route.params.slug))
|
|
|
220
220
|
```
|
|
221
221
|
::
|
|
222
222
|
|
|
223
|
-
::read-more{to="/docs/api/composables/use-async-data"}
|
|
223
|
+
::read-more{to="/docs/3.x/api/composables/use-async-data"}
|
|
224
224
|
Read more about `useAsyncData`.
|
|
225
225
|
::
|
|
226
226
|
|
|
@@ -280,11 +280,11 @@ const { status, data: posts } = useLazyFetch('/api/posts')
|
|
|
280
280
|
</script>
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
-
::read-more{to="/docs/api/composables/use-lazy-fetch"}
|
|
283
|
+
::read-more{to="/docs/3.x/api/composables/use-lazy-fetch"}
|
|
284
284
|
Read more about `useLazyFetch`.
|
|
285
285
|
::
|
|
286
286
|
|
|
287
|
-
::read-more{to="/docs/api/composables/use-lazy-async-data"}
|
|
287
|
+
::read-more{to="/docs/3.x/api/composables/use-lazy-async-data"}
|
|
288
288
|
Read more about `useLazyAsyncData`.
|
|
289
289
|
::
|
|
290
290
|
|
|
@@ -307,7 +307,7 @@ const { status, data: comments } = useFetch('/api/comments', {
|
|
|
307
307
|
})
|
|
308
308
|
```
|
|
309
309
|
|
|
310
|
-
The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](#fetch).
|
|
310
|
+
The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](/docs/3.x/getting-started/data-fetching#fetch).
|
|
311
311
|
|
|
312
312
|
### Minimize payload size
|
|
313
313
|
|
|
@@ -433,7 +433,7 @@ const { data, error, execute, refresh } = await useFetch('/api/users')
|
|
|
433
433
|
</template>
|
|
434
434
|
```
|
|
435
435
|
|
|
436
|
-
The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](#not-immediate).
|
|
436
|
+
The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](/docs/3.x/getting-started/data-fetching#not-immediate).
|
|
437
437
|
|
|
438
438
|
::tip
|
|
439
439
|
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/3.x/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/3.x/api/utils/refresh-nuxt-data).
|
|
@@ -483,7 +483,7 @@ const { data, error, refresh } = await useFetch(`/api/users/${id.value}`, {
|
|
|
483
483
|
</script>
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
-
If you need to change the URL based on a reactive value, you may want to use a [computed URL](#computed-url) instead.
|
|
486
|
+
If you need to change the URL based on a reactive value, you may want to use a [computed URL](/docs/3.x/getting-started/data-fetching#computed-url) instead.
|
|
487
487
|
|
|
488
488
|
When reactive fetch options are provided, they'll be automatically watched and trigger refetches. In some cases, it can be useful to opt-out of this behavior by specifying `watch: false`.
|
|
489
489
|
|
|
@@ -516,9 +516,9 @@ const { data, status } = useLazyFetch('/api/user', {
|
|
|
516
516
|
</script>
|
|
517
517
|
```
|
|
518
518
|
|
|
519
|
-
In the case of more complex URL construction, you may use a callback as a [computed getter](https://vuejs.org/guide/essentials/computed
|
|
519
|
+
In the case of more complex URL construction, you may use a callback as a [computed getter](https://vuejs.org/guide/essentials/computed) that returns the URL string.
|
|
520
520
|
|
|
521
|
-
Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](#not-immediate), and you can wait until the reactive element changes before fetching.
|
|
521
|
+
Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](/docs/3.x/getting-started/data-fetching#not-immediate), and you can wait until the reactive element changes before fetching.
|
|
522
522
|
|
|
523
523
|
```vue
|
|
524
524
|
<script setup lang="ts">
|
|
@@ -555,7 +555,7 @@ const pending = computed(() => status.value === 'pending')
|
|
|
555
555
|
</template>
|
|
556
556
|
```
|
|
557
557
|
|
|
558
|
-
If you need to force a refresh when other reactive values change, you can also [watch other values](#watch).
|
|
558
|
+
If you need to force a refresh when other reactive values change, you can also [watch other values](/docs/3.x/getting-started/data-fetching#watch).
|
|
559
559
|
|
|
560
560
|
### Not immediate
|
|
561
561
|
|
|
@@ -657,11 +657,11 @@ export default defineNuxtComponent({
|
|
|
657
657
|
Using `<script setup>` or `<script setup lang="ts">` are the recommended way of declaring Vue components in Nuxt.
|
|
658
658
|
::
|
|
659
659
|
|
|
660
|
-
:read-more{to="/docs/api/utils/define-nuxt-component"}
|
|
660
|
+
:read-more{to="/docs/3.x/api/utils/define-nuxt-component"}
|
|
661
661
|
|
|
662
662
|
## Serializing Data From Server to Client
|
|
663
663
|
|
|
664
|
-
When using `useAsyncData` and `useLazyAsyncData` to transfer data fetched on server to the client (as well as anything else that utilizes [the Nuxt payload](/docs/3.x/api/composables/use-nuxt-app#payload)), the payload is serialized with [`devalue`](https://github.com/
|
|
664
|
+
When using `useAsyncData` and `useLazyAsyncData` to transfer data fetched on server to the client (as well as anything else that utilizes [the Nuxt payload](/docs/3.x/api/composables/use-nuxt-app#payload)), the payload is serialized with [`devalue`](https://github.com/sveltejs/devalue). This allows us to transfer not just basic JSON but also to serialize and revive/deserialize more advanced kinds of data, such as regular expressions, Dates, Map and Set, `ref`, `reactive`, `shallowRef`, `shallowReactive` and `NuxtError` - and more.
|
|
665
665
|
|
|
666
666
|
It is also possible to define your own serializer/deserializer for types that are not supported by Nuxt. You can read more in the [`useNuxtApp`](/docs/3.x/api/composables/use-nuxt-app#payload) docs.
|
|
667
667
|
|
|
@@ -733,7 +733,7 @@ const { data } = await useFetch('/api/bar')
|
|
|
733
733
|
|
|
734
734
|
Nuxt does not currently support an alternative serializer to `JSON.stringify`. However, you can return your payload as a normal string and utilize the `toJSON` method to maintain type safety.
|
|
735
735
|
|
|
736
|
-
In the example below, we use [superjson](https://github.com/
|
|
736
|
+
In the example below, we use [superjson](https://github.com/flightcontrolhq/superjson) as our serializer.
|
|
737
737
|
|
|
738
738
|
```ts [server/api/superjson.ts]
|
|
739
739
|
import superjson from 'superjson'
|
|
@@ -771,7 +771,7 @@ const { data } = await useFetch('/api/superjson', {
|
|
|
771
771
|
### Consuming SSE (Server-Sent Events) via POST request
|
|
772
772
|
|
|
773
773
|
::tip
|
|
774
|
-
If you're consuming SSE via GET request, you can use [`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) or VueUse composable [`useEventSource`](https://vueuse.org/core/
|
|
774
|
+
If you're consuming SSE via GET request, you can use [`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) or VueUse composable [`useEventSource`](https://vueuse.org/core/useeventsource/).
|
|
775
775
|
::
|
|
776
776
|
|
|
777
777
|
When consuming SSE via POST request, you need to handle the connection manually. Here's how you can do it:
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-lucide-database
|
|
|
6
6
|
|
|
7
7
|
Nuxt provides the [`useState`](/docs/3.x/api/composables/use-state) composable to create a reactive and SSR-friendly shared state across components.
|
|
8
8
|
|
|
9
|
-
[`useState`](/docs/3.x/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core
|
|
9
|
+
[`useState`](/docs/3.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
|
|
|
@@ -14,7 +14,7 @@ Nuxt provides the [`useState`](/docs/3.x/api/composables/use-state) composable t
|
|
|
14
14
|
Because the data inside [`useState`](/docs/3.x/api/composables/use-state) will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
|
-
::read-more{to="/docs/api/composables/use-state"}
|
|
17
|
+
::read-more{to="/docs/3.x/api/composables/use-state"}
|
|
18
18
|
Read more about `useState` composable.
|
|
19
19
|
::
|
|
20
20
|
|
|
@@ -53,7 +53,7 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))
|
|
|
53
53
|
</template>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
:link-example{to="/docs/examples/features/state-management"}
|
|
56
|
+
:link-example{to="/docs/3.x/examples/features/state-management"}
|
|
57
57
|
|
|
58
58
|
::note
|
|
59
59
|
To globally invalidate cached state, see [`clearNuxtState`](/docs/3.x/api/utils/clear-nuxt-state) util.
|
|
@@ -61,7 +61,7 @@ To globally invalidate cached state, see [`clearNuxtState`](/docs/3.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/3.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/3.x/directory-structure/app) component with the [`callOnce`](/docs/3.x/api/utils/call-once) util to do so.
|
|
65
65
|
|
|
66
66
|
```vue twoslash [app.vue]
|
|
67
67
|
<script setup lang="ts">
|
|
@@ -77,7 +77,7 @@ await callOnce(async () => {
|
|
|
77
77
|
This is similar to the [`nuxtServerInit` action](https://v2.nuxt.com/docs/directory-structure/store/#the-nuxtserverinit-action) in Nuxt 2, which allows filling the initial state of your store server-side before rendering the page.
|
|
78
78
|
::
|
|
79
79
|
|
|
80
|
-
:read-more{to="/docs/api/utils/call-once"}
|
|
80
|
+
:read-more{to="/docs/3.x/api/utils/call-once"}
|
|
81
81
|
|
|
82
82
|
### Usage with Pinia
|
|
83
83
|
|
|
@@ -194,11 +194,11 @@ const date = useLocaleDate(new Date('2016-10-26'))
|
|
|
194
194
|
```
|
|
195
195
|
::
|
|
196
196
|
|
|
197
|
-
:link-example{to="/docs/examples/advanced/locale"}
|
|
197
|
+
:link-example{to="/docs/3.x/examples/advanced/locale"}
|
|
198
198
|
|
|
199
199
|
## Shared State
|
|
200
200
|
|
|
201
|
-
By using [auto-imported composables](/docs/3.x/
|
|
201
|
+
By using [auto-imported composables](/docs/3.x/directory-structure/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/3.x/
|
|
11
|
+
- Errors during Nitro server lifecycle ([`server/`](/docs/3.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/3.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/3.x/
|
|
48
|
+
- running [Nuxt plugins](/docs/3.x/directory-structure/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`
|
|
@@ -53,7 +53,7 @@ This includes:
|
|
|
53
53
|
|
|
54
54
|
## Nitro Server Errors
|
|
55
55
|
|
|
56
|
-
You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](#error-page) section.
|
|
56
|
+
You cannot currently define a server-side handler for these errors, but can render an error page, see the [Render an Error Page](/docs/3.x/getting-started/error-handling#error-page) section.
|
|
57
57
|
|
|
58
58
|
## Errors with JS Chunks
|
|
59
59
|
|
|
@@ -78,7 +78,7 @@ It can also occur on the client side when:
|
|
|
78
78
|
- mounting your app if the error was not handled with `onErrorCaptured` or `vue:error` hook
|
|
79
79
|
- the Vue app is initialized and mounted in browser (`app:mounted`).
|
|
80
80
|
|
|
81
|
-
::read-more{to="/docs/api/advanced/hooks"}
|
|
81
|
+
::read-more{to="/docs/3.x/api/advanced/hooks"}
|
|
82
82
|
Discover all the Nuxt lifecycle hooks.
|
|
83
83
|
::
|
|
84
84
|
|
|
@@ -99,7 +99,7 @@ const handleError = () => clearError({ redirect: '/' })
|
|
|
99
99
|
|
|
100
100
|
<template>
|
|
101
101
|
<div>
|
|
102
|
-
<h2>{{ error?.
|
|
102
|
+
<h2>{{ error?.status }}</h2>
|
|
103
103
|
<button @click="handleError">
|
|
104
104
|
Clear errors
|
|
105
105
|
</button>
|
|
@@ -107,7 +107,7 @@ const handleError = () => clearError({ redirect: '/' })
|
|
|
107
107
|
</template>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
::read-more{to="/docs/
|
|
110
|
+
::read-more{to="/docs/3.x/directory-structure/error"}
|
|
111
111
|
Read more about `error.vue` and its uses.
|
|
112
112
|
::
|
|
113
113
|
|
|
@@ -128,7 +128,7 @@ Make sure to check before using anything dependent on Nuxt plugins, such as `$ro
|
|
|
128
128
|
::
|
|
129
129
|
|
|
130
130
|
::note
|
|
131
|
-
Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](#useerror) in middleware to check if an error is being handled.
|
|
131
|
+
Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/3.x/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
|
|
132
132
|
::
|
|
133
133
|
|
|
134
134
|
::note
|
|
@@ -140,25 +140,25 @@ If you are running on Node 16 and you set any cookies when rendering your error
|
|
|
140
140
|
### `useError`
|
|
141
141
|
|
|
142
142
|
```ts [TS Signature]
|
|
143
|
-
function useError (): Ref<Error | { url,
|
|
143
|
+
function useError (): Ref<Error | { url, status, statusText, message, description, data }>
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
This function will return the global Nuxt error that is being handled.
|
|
147
147
|
|
|
148
|
-
::read-more{to="/docs/api/composables/use-error"}
|
|
148
|
+
::read-more{to="/docs/3.x/api/composables/use-error"}
|
|
149
149
|
Read more about `useError` composable.
|
|
150
150
|
::
|
|
151
151
|
|
|
152
152
|
### `createError`
|
|
153
153
|
|
|
154
154
|
```ts [TS Signature]
|
|
155
|
-
function createError (err: string | { cause, data, message, name, stack,
|
|
155
|
+
function createError (err: string | { cause, data, message, name, stack, status, statusText, fatal }): Error
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Create an error object with additional metadata. You can pass a string to be set as the error `message` or an object containing error properties. It is usable in both the Vue and Server portions of your app, and is meant to be thrown.
|
|
159
159
|
|
|
160
160
|
If you throw an error created with `createError`:
|
|
161
|
-
- on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](#clearerror).
|
|
161
|
+
- on server-side, it will trigger a full-screen error page which you can clear with [`clearError`](/docs/3.x/getting-started/error-handling#clearerror).
|
|
162
162
|
- on client-side, it will throw a non-fatal error for you to handle. If you need to trigger a full-screen error page, then you can do this by setting `fatal: true`.
|
|
163
163
|
|
|
164
164
|
```vue twoslash [pages/movies/[slug\\].vue]
|
|
@@ -168,28 +168,34 @@ const { data } = await useFetch(`/api/movies/${route.params.slug}`)
|
|
|
168
168
|
|
|
169
169
|
if (!data.value) {
|
|
170
170
|
throw createError({
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
status: 404,
|
|
172
|
+
statusText: 'Page Not Found',
|
|
173
173
|
})
|
|
174
174
|
}
|
|
175
175
|
</script>
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
::
|
|
178
|
+
::tip
|
|
179
|
+
The `statusText` property is intended for short, HTTP-compliant status texts (e.g., "Not Found"). It should only contain horizontal tabs, spaces, and visible ASCII characters (`[\t\u0020-\u007E]`).
|
|
180
|
+
|
|
181
|
+
For any detailed descriptions, multi-line messages, or content with non-ASCII characters, you should always use the `message` property instead.
|
|
182
|
+
::
|
|
183
|
+
|
|
184
|
+
::read-more{to="/docs/3.x/api/utils/create-error"}
|
|
179
185
|
Read more about `createError` util.
|
|
180
186
|
::
|
|
181
187
|
|
|
182
188
|
### `showError`
|
|
183
189
|
|
|
184
190
|
```ts [TS Signature]
|
|
185
|
-
function showError (err: string | Error | {
|
|
191
|
+
function showError (err: string | Error | { status, statusText }): Error
|
|
186
192
|
```
|
|
187
193
|
|
|
188
|
-
You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](#clearerror).
|
|
194
|
+
You can call this function at any point on client-side, or (on server side) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/3.x/getting-started/error-handling#clearerror).
|
|
189
195
|
|
|
190
196
|
It is recommended instead to use `throw createError()`.
|
|
191
197
|
|
|
192
|
-
::read-more{to="/docs/api/utils/show-error"}
|
|
198
|
+
::read-more{to="/docs/3.x/api/utils/show-error"}
|
|
193
199
|
Read more about `showError` util.
|
|
194
200
|
::
|
|
195
201
|
|
|
@@ -201,7 +207,7 @@ function clearError (options?: { redirect?: string }): Promise<void>
|
|
|
201
207
|
|
|
202
208
|
This function will clear the currently handled Nuxt error. It also takes an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
|
|
203
209
|
|
|
204
|
-
::read-more{to="/docs/api/utils/clear-error"}
|
|
210
|
+
::read-more{to="/docs/3.x/api/utils/clear-error"}
|
|
205
211
|
Read more about `clearError` util.
|
|
206
212
|
::
|
|
207
213
|
|
|
@@ -232,4 +238,4 @@ If you navigate to another route, the error will be cleared automatically.
|
|
|
232
238
|
</template>
|
|
233
239
|
```
|
|
234
240
|
|
|
235
|
-
:link-example{to="/docs/examples/advanced/error-handling"}
|
|
241
|
+
:link-example{to="/docs/3.x/examples/advanced/error-handling"}
|
|
@@ -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/
|
|
7
|
+
:read-more{to="/docs/3.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/
|
|
41
|
+
:read-more{to="/docs/3.x/directory-structure/server"}
|
|
42
42
|
|
|
43
43
|
## Universal Deployment
|
|
44
44
|
|
|
@@ -49,17 +49,17 @@ 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
|
-
:read-more{to="/docs/getting-started/deployment"}
|
|
62
|
+
:read-more{to="/docs/3.x/getting-started/deployment"}
|
|
63
63
|
|
|
64
64
|
## Hybrid Rendering
|
|
65
65
|
|
|
@@ -81,7 +81,7 @@ export default defineNuxtConfig({
|
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering"}
|
|
84
|
+
::read-more{to="/docs/3.x/guide/concepts/rendering#hybrid-rendering"}
|
|
85
85
|
Learn about all available route rules are available to customize the rendering mode of your routes.
|
|
86
86
|
::
|
|
87
87
|
|
|
@@ -91,4 +91,4 @@ Some route rules (`appMiddleware`, `redirect` and `prerender`) also affect clien
|
|
|
91
91
|
|
|
92
92
|
Nitro is used to build the app for server side rendering, as well as pre-rendering.
|
|
93
93
|
|
|
94
|
-
:read-more{to="/docs/guide/concepts/rendering"}
|
|
94
|
+
:read-more{to="/docs/3.x/guide/concepts/rendering"}
|
|
@@ -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 [`components/`](/docs/3.x/
|
|
13
|
-
- Create utility and composable library using [`composables/`](/docs/3.x/
|
|
12
|
+
- Create a component library using [`components/`](/docs/3.x/directory-structure/components) directory
|
|
13
|
+
- Create utility and composable library using [`composables/`](/docs/3.x/directory-structure/composables) and [`utils/`](/docs/3.x/directory-structure/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/3.x/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/3.x/
|
|
33
|
+
In addition, you can extend from a layer by adding the [extends](/docs/3.x/api/nuxt-config#extends) property to your [`nuxt.config`](/docs/3.x/directory-structure/nuxt-config) file.
|
|
34
34
|
|
|
35
35
|
```ts [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
@@ -56,6 +56,10 @@ export default defineNuxtConfig({
|
|
|
56
56
|
})
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
::note
|
|
60
|
+
If a branch is not specified, this will clone `main`.
|
|
61
|
+
::
|
|
62
|
+
|
|
59
63
|
::tip
|
|
60
64
|
You can override a layer's alias by specifying it in the options next to the layer source.
|
|
61
65
|
|
|
@@ -76,38 +80,66 @@ export default defineNuxtConfig({
|
|
|
76
80
|
|
|
77
81
|
::
|
|
78
82
|
|
|
79
|
-
Nuxt uses [unjs/c12](https://
|
|
83
|
+
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
84
|
|
|
81
85
|
## Layer Priority
|
|
82
86
|
|
|
83
87
|
When using multiple layers, it's important to understand the override order. Layers with **higher priority** override layers with lower priority when they define the same files or components.
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
### Priority Order
|
|
90
|
+
|
|
91
|
+
From highest to lowest priority:
|
|
86
92
|
|
|
87
93
|
1. **Your project files** - always have the highest priority
|
|
88
94
|
2. **Auto-scanned layers** from `~~/layers` directory - sorted alphabetically (Z has higher priority than A)
|
|
89
95
|
3. **Layers in `extends`** config - first entry has higher priority than second
|
|
90
96
|
|
|
91
|
-
###
|
|
97
|
+
### Practical Example
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
Consider multiple layers defining the same component:
|
|
100
|
+
|
|
101
|
+
```bash [Directory structure]
|
|
102
|
+
layers/
|
|
103
|
+
1.base/
|
|
104
|
+
components/Button.vue # Base button style
|
|
105
|
+
2.theme/
|
|
106
|
+
components/Button.vue # Themed button (overrides base)
|
|
107
|
+
app/
|
|
108
|
+
components/Button.vue # Project button (overrides all layers)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
In this case:
|
|
112
|
+
- If only layers exist, `2.theme/Button.vue` is used (higher alphabetically)
|
|
113
|
+
- If `components/Button.vue` exists in your project, it overrides all layers
|
|
114
|
+
|
|
115
|
+
### Controlling Priority
|
|
116
|
+
|
|
117
|
+
You can prefix layer directories with numbers to control the order:
|
|
118
|
+
|
|
119
|
+
```bash [Directory structure]
|
|
120
|
+
layers/
|
|
121
|
+
1.base/ # Lowest priority
|
|
122
|
+
2.features/ # Medium priority
|
|
123
|
+
3.admin/ # Highest priority (among layers)
|
|
124
|
+
```
|
|
95
125
|
|
|
96
126
|
::tip
|
|
97
|
-
|
|
127
|
+
This pattern is useful for creating base layers with defaults that can be progressively overridden by more specific layers.
|
|
98
128
|
::
|
|
99
129
|
|
|
100
|
-
###
|
|
130
|
+
### When to Use Each
|
|
131
|
+
|
|
132
|
+
- **`~~/layers` directory** - Use for local layers that are part of your project
|
|
133
|
+
- **`extends`** - Use for external dependencies (npm packages, remote repositories) or layers outside your project directory
|
|
134
|
+
|
|
135
|
+
### Full Example with extends
|
|
101
136
|
|
|
102
137
|
```ts [nuxt.config.ts]
|
|
103
138
|
export default defineNuxtConfig({
|
|
104
139
|
extends: [
|
|
105
|
-
// Local layer outside
|
|
106
|
-
'
|
|
107
|
-
//
|
|
108
|
-
'@my-themes/awesome',
|
|
109
|
-
// Remote repository
|
|
110
|
-
'github:my-themes/awesome#v1',
|
|
140
|
+
'../base', // Local layer outside project
|
|
141
|
+
'@my-themes/awesome', // NPM package
|
|
142
|
+
'github:my-themes/awesome#v1', // Remote repository
|
|
111
143
|
],
|
|
112
144
|
})
|
|
113
145
|
```
|
|
@@ -119,9 +151,11 @@ If you also have `~~/layers/custom`, the priority order is:
|
|
|
119
151
|
- `@my-themes/awesome`
|
|
120
152
|
- `github:my-themes/awesome#v1` (lowest)
|
|
121
153
|
|
|
122
|
-
|
|
154
|
+
::read-more{to="/docs/3.x/directory-structure/layers"}
|
|
155
|
+
Learn about the **layers/ directory** to organize and share reusable code, components, composables, and configurations across your Nuxt application.
|
|
156
|
+
::
|
|
123
157
|
|
|
124
|
-
::read-more{to="/docs/guide/going-further/layers"}
|
|
158
|
+
::read-more{to="/docs/3.x/guide/going-further/layers"}
|
|
125
159
|
Read more about layers in the **Layer Author Guide**.
|
|
126
160
|
::
|
|
127
161
|
|