@nuxt/docs 4.1.2 → 4.2.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 +6 -6
- package/1.getting-started/02.installation.md +3 -2
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +241 -110
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +334 -85
- package/2.guide/3.going-further/1.features.md +58 -11
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +126 -108
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +76 -59
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +45 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +49 -18
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +26 -22
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +62 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +123 -37
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +66 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +61 -4
- package/3.api/5.kit/15.examples.md +5 -7
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +8 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.head.md +132 -0
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +365 -859
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +3 -3
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +2 -2
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -4,11 +4,11 @@ description: Nuxt file-system routing creates a route for every file in the page
|
|
|
4
4
|
navigation.icon: i-lucide-milestone
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
One core feature of Nuxt is the file system router. Every Vue file inside the [`app/pages/`](/docs/guide/directory-structure/app/pages) directory creates a corresponding URL (or route) that displays the contents of the file. By using dynamic imports for each page, Nuxt leverages code-splitting to ship the minimum amount of JavaScript for the requested route.
|
|
7
|
+
One core feature of Nuxt is the file system router. Every Vue file inside the [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory creates a corresponding URL (or route) that displays the contents of the file. By using dynamic imports for each page, Nuxt leverages code-splitting to ship the minimum amount of JavaScript for the requested route.
|
|
8
8
|
|
|
9
9
|
## Pages
|
|
10
10
|
|
|
11
|
-
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`app/pages/` directory](/docs/guide/directory-structure/app/pages), based on their filename.
|
|
11
|
+
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`app/pages/` directory](/docs/4.x/guide/directory-structure/app/pages), based on their filename.
|
|
12
12
|
|
|
13
13
|
This file system routing uses naming conventions to create dynamic and nested routes:
|
|
14
14
|
|
|
@@ -43,13 +43,13 @@ This file system routing uses naming conventions to create dynamic and nested ro
|
|
|
43
43
|
|
|
44
44
|
::
|
|
45
45
|
|
|
46
|
-
:read-more{to="/docs/guide/directory-structure/app/pages"}
|
|
46
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/pages"}
|
|
47
47
|
|
|
48
48
|
## Navigation
|
|
49
49
|
|
|
50
|
-
The [`<NuxtLink>`](/docs/api/components/nuxt-link) component links pages between them. It renders an `<a>` tag with the `href` attribute set to the route of the page. Once the application is hydrated, page transitions are performed in JavaScript by updating the browser URL. This prevents full-page refreshes and allows for animated transitions.
|
|
50
|
+
The [`<NuxtLink>`](/docs/4.x/api/components/nuxt-link) component links pages between them. It renders an `<a>` tag with the `href` attribute set to the route of the page. Once the application is hydrated, page transitions are performed in JavaScript by updating the browser URL. This prevents full-page refreshes and allows for animated transitions.
|
|
51
51
|
|
|
52
|
-
When a [`<NuxtLink>`](/docs/api/components/nuxt-link) enters the viewport on the client side, Nuxt will automatically prefetch components and payload (generated pages) of the linked pages ahead of time, resulting in faster navigation.
|
|
52
|
+
When a [`<NuxtLink>`](/docs/4.x/api/components/nuxt-link) enters the viewport on the client side, Nuxt will automatically prefetch components and payload (generated pages) of the linked pages ahead of time, resulting in faster navigation.
|
|
53
53
|
|
|
54
54
|
```vue [app/pages/index.vue]
|
|
55
55
|
<template>
|
|
@@ -65,11 +65,11 @@ When a [`<NuxtLink>`](/docs/api/components/nuxt-link) enters the viewport on the
|
|
|
65
65
|
</template>
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
:read-more{to="/docs/api/components/nuxt-link"}
|
|
68
|
+
:read-more{to="/docs/4.x/api/components/nuxt-link"}
|
|
69
69
|
|
|
70
70
|
## Route Parameters
|
|
71
71
|
|
|
72
|
-
The [`useRoute()`](/docs/api/composables/use-route) composable can be used in a `<script setup>` block or a `setup()` method of a Vue component to access the current route details.
|
|
72
|
+
The [`useRoute()`](/docs/4.x/api/composables/use-route) composable can be used in a `<script setup>` block or a `setup()` method of a Vue component to access the current route details.
|
|
73
73
|
|
|
74
74
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
75
75
|
<script setup lang="ts">
|
|
@@ -80,7 +80,7 @@ console.log(route.params.id)
|
|
|
80
80
|
</script>
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
:read-more{to="/docs/api/composables/use-route"}
|
|
83
|
+
:read-more{to="/docs/4.x/api/composables/use-route"}
|
|
84
84
|
|
|
85
85
|
## Route Middleware
|
|
86
86
|
|
|
@@ -93,15 +93,15 @@ Route middleware runs within the Vue part of your Nuxt app. Despite the similar
|
|
|
93
93
|
There are three kinds of route middleware:
|
|
94
94
|
|
|
95
95
|
1. Anonymous (or inline) route middleware, which are defined directly in the pages where they are used.
|
|
96
|
-
2. Named route middleware, which are placed in the [`app/middleware/`](/docs/guide/directory-structure/app/middleware) directory and will be automatically loaded via asynchronous import when used on a page. (**Note**: The route middleware name is normalized to kebab-case, so `someMiddleware` becomes `some-middleware`.)
|
|
97
|
-
3. Global route middleware, which are placed in the [`app/middleware/`](/docs/guide/directory-structure/app/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
96
|
+
2. Named route middleware, which are placed in the [`app/middleware/`](/docs/4.x/guide/directory-structure/app/middleware) directory and will be automatically loaded via asynchronous import when used on a page. (**Note**: The route middleware name is normalized to kebab-case, so `someMiddleware` becomes `some-middleware`.)
|
|
97
|
+
3. Global route middleware, which are placed in the [`app/middleware/`](/docs/4.x/guide/directory-structure/app/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
98
98
|
|
|
99
99
|
Example of an `auth` middleware protecting the `/dashboard` page:
|
|
100
100
|
|
|
101
101
|
::code-group
|
|
102
102
|
|
|
103
103
|
```ts twoslash [middleware/auth.ts]
|
|
104
|
-
function isAuthenticated(): boolean { return false }
|
|
104
|
+
function isAuthenticated (): boolean { return false }
|
|
105
105
|
// ---cut---
|
|
106
106
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
107
107
|
// isAuthenticated() is an example method verifying if a user is authenticated
|
|
@@ -114,7 +114,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
114
114
|
```vue twoslash [pages/dashboard.vue]
|
|
115
115
|
<script setup lang="ts">
|
|
116
116
|
definePageMeta({
|
|
117
|
-
middleware: 'auth'
|
|
117
|
+
middleware: 'auth',
|
|
118
118
|
})
|
|
119
119
|
</script>
|
|
120
120
|
|
|
@@ -125,11 +125,11 @@ definePageMeta({
|
|
|
125
125
|
|
|
126
126
|
::
|
|
127
127
|
|
|
128
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
128
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
|
|
129
129
|
|
|
130
130
|
## Route Validation
|
|
131
131
|
|
|
132
|
-
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/api/utils/define-page-meta) in each page you wish to validate.
|
|
132
|
+
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/4.x/api/utils/define-page-meta) in each page you wish to validate.
|
|
133
133
|
|
|
134
134
|
The `validate` property accepts the `route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return `false`, this will cause a 404 error. You can also directly return an object with `statusCode`/`statusMessage` to customize the error returned.
|
|
135
135
|
|
|
@@ -138,12 +138,12 @@ If you have a more complex use case, then you can use anonymous route middleware
|
|
|
138
138
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
139
139
|
<script setup lang="ts">
|
|
140
140
|
definePageMeta({
|
|
141
|
-
validate
|
|
141
|
+
validate (route) {
|
|
142
142
|
// Check if the id is made up of digits
|
|
143
143
|
return typeof route.params.id === 'string' && /^\d+$/.test(route.params.id)
|
|
144
|
-
}
|
|
144
|
+
},
|
|
145
145
|
})
|
|
146
146
|
</script>
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
:read-more{to="/docs/api/utils/define-page-meta"}
|
|
149
|
+
:read-more{to="/docs/4.x/api/utils/define-page-meta"}
|
|
@@ -9,7 +9,7 @@ and numerous configuration options to manage your app's head and SEO meta tags.
|
|
|
9
9
|
|
|
10
10
|
## Nuxt Config
|
|
11
11
|
|
|
12
|
-
Providing an [`app.head`](/docs/api/nuxt-config#head) property in your [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) allows you to statically customize the head for your entire app.
|
|
12
|
+
Providing an [`app.head`](/docs/4.x/api/nuxt-config#head) property in your [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) allows you to statically customize the head for your entire app.
|
|
13
13
|
|
|
14
14
|
::important
|
|
15
15
|
This method does not allow you to provide reactive data. We recommend using `useHead()` in `app.vue`.
|
|
@@ -27,13 +27,13 @@ export default defineNuxtConfig({
|
|
|
27
27
|
},
|
|
28
28
|
link: [
|
|
29
29
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
}
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
You can also provide any of the keys listed below in [Types](#types).
|
|
36
|
+
You can also provide any of the keys listed below in [Types](/docs/4.x/getting-started/seo-meta#types).
|
|
37
37
|
|
|
38
38
|
### Defaults Tags
|
|
39
39
|
|
|
@@ -51,35 +51,35 @@ export default defineNuxtConfig({
|
|
|
51
51
|
// update Nuxt defaults
|
|
52
52
|
charset: 'utf-16',
|
|
53
53
|
viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
|
|
54
|
-
}
|
|
55
|
-
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
56
|
})
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
## `useHead`
|
|
60
60
|
|
|
61
|
-
The [`useHead`](/docs/api/composables/use-head) composable function supports reactive input, allowing you to manage your head tags programmatically.
|
|
61
|
+
The [`useHead`](/docs/4.x/api/composables/use-head) composable function supports reactive input, allowing you to manage your head tags programmatically.
|
|
62
62
|
|
|
63
63
|
```vue twoslash [app/app.vue]
|
|
64
64
|
<script setup lang="ts">
|
|
65
65
|
useHead({
|
|
66
66
|
title: 'My App',
|
|
67
67
|
meta: [
|
|
68
|
-
{ name: 'description', content: 'My amazing site.' }
|
|
68
|
+
{ name: 'description', content: 'My amazing site.' },
|
|
69
69
|
],
|
|
70
70
|
bodyAttrs: {
|
|
71
|
-
class: 'test'
|
|
71
|
+
class: 'test',
|
|
72
72
|
},
|
|
73
|
-
script: [
|
|
73
|
+
script: [{ innerHTML: 'console.log(\'Hello world\')' }],
|
|
74
74
|
})
|
|
75
75
|
</script>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
We recommend taking a look at the [`useHead`](/docs/api/composables/use-head) and [`useHeadSafe`](/docs/api/composables/use-head-safe) composables.
|
|
78
|
+
We recommend taking a look at the [`useHead`](/docs/4.x/api/composables/use-head) and [`useHeadSafe`](/docs/4.x/api/composables/use-head-safe) composables.
|
|
79
79
|
|
|
80
80
|
## `useSeoMeta`
|
|
81
81
|
|
|
82
|
-
The [`useSeoMeta`](/docs/api/composables/use-seo-meta) composable lets you define your site's SEO meta tags as an object with full type safety.
|
|
82
|
+
The [`useSeoMeta`](/docs/4.x/api/composables/use-seo-meta) composable lets you define your site's SEO meta tags as an object with full type safety.
|
|
83
83
|
|
|
84
84
|
This helps you avoid typos and common mistakes, such as using `name` instead of `property`.
|
|
85
85
|
|
|
@@ -96,11 +96,11 @@ useSeoMeta({
|
|
|
96
96
|
</script>
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
:read-more{to="/docs/api/composables/use-seo-meta"}
|
|
99
|
+
:read-more{to="/docs/4.x/api/composables/use-seo-meta"}
|
|
100
100
|
|
|
101
101
|
## Components
|
|
102
102
|
|
|
103
|
-
While using [`useHead`](/docs/api/composables/use-head) is recommended in all cases, you may have a personal preference for defining your head tags in your template using components.
|
|
103
|
+
While using [`useHead`](/docs/4.x/api/composables/use-head) is recommended in all cases, you may have a personal preference for defining your head tags in your template using components.
|
|
104
104
|
|
|
105
105
|
Nuxt provides the following components for this purpose: `<Title>`, `<Base>`, `<NoScript>`, `<Style>`, `<Meta>`, `<Link>`, `<Body>`, `<Html>` and `<Head>`. Note
|
|
106
106
|
the capitalization of these components ensuring we don't use invalid native HTML tags.
|
|
@@ -118,9 +118,12 @@ const title = ref('Hello World')
|
|
|
118
118
|
<div>
|
|
119
119
|
<Head>
|
|
120
120
|
<Title>{{ title }}</Title>
|
|
121
|
-
<Meta
|
|
121
|
+
<Meta
|
|
122
|
+
name="description"
|
|
123
|
+
:content="title"
|
|
124
|
+
/>
|
|
122
125
|
<Style>
|
|
123
|
-
|
|
126
|
+
body { background-color: green; }
|
|
124
127
|
</Style>
|
|
125
128
|
</Head>
|
|
126
129
|
|
|
@@ -133,7 +136,7 @@ It's suggested to wrap your components in either a `<Head>` or `<Html>` componen
|
|
|
133
136
|
|
|
134
137
|
## Types
|
|
135
138
|
|
|
136
|
-
Below are the non-reactive types used for [`useHead`](/docs/api/composables/use-head), [`app.head`](/docs/api/nuxt-config#head) and components.
|
|
139
|
+
Below are the non-reactive types used for [`useHead`](/docs/4.x/api/composables/use-head), [`app.head`](/docs/4.x/api/nuxt-config#head) and components.
|
|
137
140
|
|
|
138
141
|
```ts
|
|
139
142
|
interface MetaObject {
|
|
@@ -145,9 +148,9 @@ interface MetaObject {
|
|
|
145
148
|
meta?: Meta[]
|
|
146
149
|
style?: Style[]
|
|
147
150
|
script?: Script[]
|
|
148
|
-
noscript?: Noscript[]
|
|
149
|
-
htmlAttrs?: HtmlAttributes
|
|
150
|
-
bodyAttrs?: BodyAttributes
|
|
151
|
+
noscript?: Noscript[]
|
|
152
|
+
htmlAttrs?: HtmlAttributes
|
|
153
|
+
bodyAttrs?: BodyAttributes
|
|
151
154
|
}
|
|
152
155
|
```
|
|
153
156
|
|
|
@@ -167,7 +170,7 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
167
170
|
|
|
168
171
|
useHead({
|
|
169
172
|
meta: [
|
|
170
|
-
{ name: 'description', content: description }
|
|
173
|
+
{ name: 'description', content: description },
|
|
171
174
|
],
|
|
172
175
|
})
|
|
173
176
|
</script>
|
|
@@ -178,7 +181,7 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
178
181
|
const description = ref('My amazing site.')
|
|
179
182
|
|
|
180
183
|
useSeoMeta({
|
|
181
|
-
description
|
|
184
|
+
description,
|
|
182
185
|
})
|
|
183
186
|
</script>
|
|
184
187
|
```
|
|
@@ -190,7 +193,10 @@ Reactivity is supported on all properties, by providing a computed value, a gett
|
|
|
190
193
|
|
|
191
194
|
<template>
|
|
192
195
|
<div>
|
|
193
|
-
<Meta
|
|
196
|
+
<Meta
|
|
197
|
+
name="description"
|
|
198
|
+
:content="description"
|
|
199
|
+
/>
|
|
194
200
|
</div>
|
|
195
201
|
</template>
|
|
196
202
|
```
|
|
@@ -211,15 +217,15 @@ If you want to use a function (for full control), then this cannot be set in you
|
|
|
211
217
|
<script setup lang="ts">
|
|
212
218
|
useHead({
|
|
213
219
|
titleTemplate: (titleChunk) => {
|
|
214
|
-
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title'
|
|
215
|
-
}
|
|
220
|
+
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title'
|
|
221
|
+
},
|
|
216
222
|
})
|
|
217
223
|
</script>
|
|
218
224
|
```
|
|
219
225
|
|
|
220
226
|
::
|
|
221
227
|
|
|
222
|
-
Now, if you set the title to `My Page` with [`useHead`](/docs/api/composables/use-head) on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `null` to default to 'Site Title'.
|
|
228
|
+
Now, if you set the title to `My Page` with [`useHead`](/docs/4.x/api/composables/use-head) on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `null` to default to 'Site Title'.
|
|
223
229
|
|
|
224
230
|
### Template Params
|
|
225
231
|
|
|
@@ -231,12 +237,12 @@ You can use `templateParams` to provide additional placeholders in your `titleTe
|
|
|
231
237
|
<script setup lang="ts">
|
|
232
238
|
useHead({
|
|
233
239
|
titleTemplate: (titleChunk) => {
|
|
234
|
-
return titleChunk ? `${titleChunk} %separator %siteName` : '%siteName'
|
|
240
|
+
return titleChunk ? `${titleChunk} %separator %siteName` : '%siteName'
|
|
235
241
|
},
|
|
236
242
|
templateParams: {
|
|
237
243
|
siteName: 'Site Title',
|
|
238
|
-
separator: '-'
|
|
239
|
-
}
|
|
244
|
+
separator: '-',
|
|
245
|
+
},
|
|
240
246
|
})
|
|
241
247
|
</script>
|
|
242
248
|
```
|
|
@@ -256,9 +262,9 @@ useHead({
|
|
|
256
262
|
{
|
|
257
263
|
src: 'https://third-party-script.com',
|
|
258
264
|
// valid options are: 'head' | 'bodyClose' | 'bodyOpen'
|
|
259
|
-
tagPosition: 'bodyClose'
|
|
260
|
-
}
|
|
261
|
-
]
|
|
265
|
+
tagPosition: 'bodyClose',
|
|
266
|
+
},
|
|
267
|
+
],
|
|
262
268
|
})
|
|
263
269
|
</script>
|
|
264
270
|
```
|
|
@@ -267,14 +273,14 @@ useHead({
|
|
|
267
273
|
|
|
268
274
|
### With `definePageMeta`
|
|
269
275
|
|
|
270
|
-
Within your [`app/pages/` directory](/docs/guide/directory-structure/app/pages), you can use `definePageMeta` along with [`useHead`](/docs/api/composables/use-head) to set metadata based on the current route.
|
|
276
|
+
Within your [`app/pages/` directory](/docs/4.x/guide/directory-structure/app/pages), you can use `definePageMeta` along with [`useHead`](/docs/4.x/api/composables/use-head) to set metadata based on the current route.
|
|
271
277
|
|
|
272
278
|
For example, you can first set the current page title (this is extracted at build time via a macro, so it can't be set dynamically):
|
|
273
279
|
|
|
274
280
|
```vue twoslash [pages/some-page.vue]
|
|
275
281
|
<script setup lang="ts">
|
|
276
282
|
definePageMeta({
|
|
277
|
-
title: 'Some Page'
|
|
283
|
+
title: 'Some Page',
|
|
278
284
|
})
|
|
279
285
|
</script>
|
|
280
286
|
```
|
|
@@ -286,14 +292,14 @@ And then in your layout file, you might use the route's metadata you have previo
|
|
|
286
292
|
const route = useRoute()
|
|
287
293
|
|
|
288
294
|
useHead({
|
|
289
|
-
meta: [{ property: 'og:title', content: `App Name - ${route.meta.title}` }]
|
|
295
|
+
meta: [{ property: 'og:title', content: `App Name - ${route.meta.title}` }],
|
|
290
296
|
})
|
|
291
297
|
</script>
|
|
292
298
|
```
|
|
293
299
|
|
|
294
|
-
:link-example{to="/docs/examples/features/meta-tags"}
|
|
300
|
+
:link-example{to="/docs/4.x/examples/features/meta-tags"}
|
|
295
301
|
|
|
296
|
-
:read-more{to="/docs/guide/directory-structure/app/pages/#page-metadata"}
|
|
302
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/pages/#page-metadata"}
|
|
297
303
|
|
|
298
304
|
### Dynamic Title
|
|
299
305
|
|
|
@@ -317,7 +323,7 @@ useHead({
|
|
|
317
323
|
return productCategory
|
|
318
324
|
? `${productCategory} - Site Title`
|
|
319
325
|
: 'Site Title'
|
|
320
|
-
}
|
|
326
|
+
},
|
|
321
327
|
})
|
|
322
328
|
</script>
|
|
323
329
|
```
|
|
@@ -326,7 +332,7 @@ useHead({
|
|
|
326
332
|
|
|
327
333
|
### External CSS
|
|
328
334
|
|
|
329
|
-
The example below shows how you might enable Google Fonts using either the `link` property of the [`useHead`](/docs/api/composables/use-head) composable or using the `<Link>` component:
|
|
335
|
+
The example below shows how you might enable Google Fonts using either the `link` property of the [`useHead`](/docs/4.x/api/composables/use-head) composable or using the `<Link>` component:
|
|
330
336
|
|
|
331
337
|
::code-group
|
|
332
338
|
|
|
@@ -336,14 +342,14 @@ The example below shows how you might enable Google Fonts using either the `link
|
|
|
336
342
|
link: [
|
|
337
343
|
{
|
|
338
344
|
rel: 'preconnect',
|
|
339
|
-
href: 'https://fonts.googleapis.com'
|
|
345
|
+
href: 'https://fonts.googleapis.com',
|
|
340
346
|
},
|
|
341
347
|
{
|
|
342
348
|
rel: 'stylesheet',
|
|
343
349
|
href: 'https://fonts.googleapis.com/css2?family=Roboto&display=swap',
|
|
344
|
-
crossorigin: ''
|
|
345
|
-
}
|
|
346
|
-
]
|
|
350
|
+
crossorigin: '',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
347
353
|
})
|
|
348
354
|
</script>
|
|
349
355
|
```
|
|
@@ -351,8 +357,15 @@ The example below shows how you might enable Google Fonts using either the `link
|
|
|
351
357
|
```vue [app/Components]
|
|
352
358
|
<template>
|
|
353
359
|
<div>
|
|
354
|
-
<Link
|
|
355
|
-
|
|
360
|
+
<Link
|
|
361
|
+
rel="preconnect"
|
|
362
|
+
href="https://fonts.googleapis.com"
|
|
363
|
+
/>
|
|
364
|
+
<Link
|
|
365
|
+
rel="stylesheet"
|
|
366
|
+
href="https://fonts.googleapis.com/css2?family=Roboto&display=swap"
|
|
367
|
+
crossorigin=""
|
|
368
|
+
/>
|
|
356
369
|
</div>
|
|
357
370
|
</template>
|
|
358
371
|
```
|
|
@@ -10,21 +10,21 @@ Nuxt leverages Vue's [`<Transition>`](https://vuejs.org/guide/built-ins/transiti
|
|
|
10
10
|
|
|
11
11
|
## Page Transitions
|
|
12
12
|
|
|
13
|
-
You can enable page transitions to apply an automatic transition for all your [pages](/docs/guide/directory-structure/app/pages).
|
|
13
|
+
You can enable page transitions to apply an automatic transition for all your [pages](/docs/4.x/guide/directory-structure/app/pages).
|
|
14
14
|
|
|
15
15
|
```ts twoslash [nuxt.config.ts]
|
|
16
16
|
export default defineNuxtConfig({
|
|
17
17
|
app: {
|
|
18
|
-
pageTransition: { name: 'page', mode: 'out-in' }
|
|
19
|
-
}
|
|
18
|
+
pageTransition: { name: 'page', mode: 'out-in' },
|
|
19
|
+
},
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
::note
|
|
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/getting-started/transitions#layout-transitions).
|
|
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/4.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/guide/directory-structure/app):
|
|
27
|
+
To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/4.x/guide/directory-structure/app):
|
|
28
28
|
|
|
29
29
|
::code-group
|
|
30
30
|
|
|
@@ -72,7 +72,7 @@ This produces the following result when navigating between pages:
|
|
|
72
72
|
<source src="https://res.cloudinary.com/nuxt/video/upload/v1665061349/nuxt3/nuxt3-page-transitions_umwvmh.mp4" type="video/mp4">
|
|
73
73
|
</video>
|
|
74
74
|
|
|
75
|
-
To set a different transition for a page, set the `pageTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page:
|
|
75
|
+
To set a different transition for a page, set the `pageTransition` key in [`definePageMeta`](/docs/4.x/api/utils/define-page-meta) of the page:
|
|
76
76
|
|
|
77
77
|
::code-group
|
|
78
78
|
|
|
@@ -80,8 +80,8 @@ To set a different transition for a page, set the `pageTransition` key in [`defi
|
|
|
80
80
|
<script setup lang="ts">
|
|
81
81
|
definePageMeta({
|
|
82
82
|
pageTransition: {
|
|
83
|
-
name: 'rotate'
|
|
84
|
-
}
|
|
83
|
+
name: 'rotate',
|
|
84
|
+
},
|
|
85
85
|
})
|
|
86
86
|
</script>
|
|
87
87
|
```
|
|
@@ -115,17 +115,17 @@ 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/guide/directory-structure/app/layouts).
|
|
118
|
+
You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/4.x/guide/directory-structure/app/layouts).
|
|
119
119
|
|
|
120
120
|
```ts twoslash [nuxt.config.ts]
|
|
121
121
|
export default defineNuxtConfig({
|
|
122
122
|
app: {
|
|
123
|
-
layoutTransition: { name: 'layout', mode: 'out-in' }
|
|
124
|
-
}
|
|
123
|
+
layoutTransition: { name: 'layout', mode: 'out-in' },
|
|
124
|
+
},
|
|
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/guide/directory-structure/app):
|
|
128
|
+
To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/4.x/guide/directory-structure/app):
|
|
129
129
|
|
|
130
130
|
::code-group
|
|
131
131
|
|
|
@@ -192,7 +192,7 @@ div {
|
|
|
192
192
|
```vue [app/pages/about.vue]
|
|
193
193
|
<script setup lang="ts">
|
|
194
194
|
definePageMeta({
|
|
195
|
-
layout: 'orange'
|
|
195
|
+
layout: 'orange',
|
|
196
196
|
})
|
|
197
197
|
</script>
|
|
198
198
|
|
|
@@ -219,8 +219,8 @@ Similar to `pageTransition`, you can apply a custom `layoutTransition` to the pa
|
|
|
219
219
|
definePageMeta({
|
|
220
220
|
layout: 'orange',
|
|
221
221
|
layoutTransition: {
|
|
222
|
-
name: 'slide-in'
|
|
223
|
-
}
|
|
222
|
+
name: 'slide-in',
|
|
223
|
+
},
|
|
224
224
|
})
|
|
225
225
|
</script>
|
|
226
226
|
```
|
|
@@ -236,13 +236,13 @@ export default defineNuxtConfig({
|
|
|
236
236
|
app: {
|
|
237
237
|
pageTransition: {
|
|
238
238
|
name: 'fade',
|
|
239
|
-
mode: 'out-in' // default
|
|
239
|
+
mode: 'out-in', // default
|
|
240
240
|
},
|
|
241
241
|
layoutTransition: {
|
|
242
242
|
name: 'slide',
|
|
243
|
-
mode: 'out-in' // default
|
|
244
|
-
}
|
|
245
|
-
}
|
|
243
|
+
mode: 'out-in', // default
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
246
|
})
|
|
247
247
|
```
|
|
248
248
|
|
|
@@ -257,8 +257,8 @@ To override the global transition property, use the `definePageMeta` to define p
|
|
|
257
257
|
definePageMeta({
|
|
258
258
|
pageTransition: {
|
|
259
259
|
name: 'bounce',
|
|
260
|
-
mode: 'out-in' // default
|
|
261
|
-
}
|
|
260
|
+
mode: 'out-in', // default
|
|
261
|
+
},
|
|
262
262
|
})
|
|
263
263
|
</script>
|
|
264
264
|
```
|
|
@@ -271,7 +271,7 @@ definePageMeta({
|
|
|
271
271
|
<script setup lang="ts">
|
|
272
272
|
definePageMeta({
|
|
273
273
|
pageTransition: false,
|
|
274
|
-
layoutTransition: false
|
|
274
|
+
layoutTransition: false,
|
|
275
275
|
})
|
|
276
276
|
</script>
|
|
277
277
|
```
|
|
@@ -282,8 +282,8 @@ Or globally in the `nuxt.config`:
|
|
|
282
282
|
export default defineNuxtConfig({
|
|
283
283
|
app: {
|
|
284
284
|
pageTransition: false,
|
|
285
|
-
layoutTransition: false
|
|
286
|
-
}
|
|
285
|
+
layoutTransition: false,
|
|
286
|
+
},
|
|
287
287
|
})
|
|
288
288
|
```
|
|
289
289
|
|
|
@@ -303,8 +303,8 @@ definePageMeta({
|
|
|
303
303
|
console.log('Before enter...')
|
|
304
304
|
},
|
|
305
305
|
onEnter: (el, done) => {},
|
|
306
|
-
onAfterEnter: (el) => {}
|
|
307
|
-
}
|
|
306
|
+
onAfterEnter: (el) => {},
|
|
307
|
+
},
|
|
308
308
|
})
|
|
309
309
|
</script>
|
|
310
310
|
```
|
|
@@ -315,7 +315,7 @@ Learn more about additional [JavaScript hooks](https://vuejs.org/guide/built-ins
|
|
|
315
315
|
|
|
316
316
|
## Dynamic Transitions
|
|
317
317
|
|
|
318
|
-
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/guide/directory-structure/app/middleware) to assign a different transition name to `to.meta.pageTransition`.
|
|
318
|
+
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/4.x/guide/directory-structure/app/middleware) to assign a different transition name to `to.meta.pageTransition`.
|
|
319
319
|
|
|
320
320
|
::code-group
|
|
321
321
|
|
|
@@ -324,12 +324,13 @@ To apply dynamic transitions using conditional logic, you can leverage inline [m
|
|
|
324
324
|
definePageMeta({
|
|
325
325
|
pageTransition: {
|
|
326
326
|
name: 'slide-right',
|
|
327
|
-
mode: 'out-in'
|
|
327
|
+
mode: 'out-in',
|
|
328
328
|
},
|
|
329
329
|
middleware (to, from) {
|
|
330
|
-
if (to.meta.pageTransition && typeof to.meta.pageTransition !== 'boolean')
|
|
330
|
+
if (to.meta.pageTransition && typeof to.meta.pageTransition !== 'boolean') {
|
|
331
331
|
to.meta.pageTransition.name = +to.params.id! > +from.params.id! ? 'slide-left' : 'slide-right'
|
|
332
|
-
|
|
332
|
+
}
|
|
333
|
+
},
|
|
333
334
|
})
|
|
334
335
|
</script>
|
|
335
336
|
|
|
@@ -398,10 +399,12 @@ When `<NuxtPage />` is used in `app.vue`, transitions can be configured with the
|
|
|
398
399
|
<template>
|
|
399
400
|
<div>
|
|
400
401
|
<NuxtLayout>
|
|
401
|
-
<NuxtPage
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
402
|
+
<NuxtPage
|
|
403
|
+
:transition="{
|
|
404
|
+
name: 'bounce',
|
|
405
|
+
mode: 'out-in',
|
|
406
|
+
}"
|
|
407
|
+
/>
|
|
405
408
|
</NuxtLayout>
|
|
406
409
|
</div>
|
|
407
410
|
</template>
|
|
@@ -415,15 +418,15 @@ Remember, this page transition cannot be overridden with `definePageMeta` on ind
|
|
|
415
418
|
|
|
416
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_Transitions_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.
|
|
417
420
|
|
|
418
|
-
You can check a demo
|
|
421
|
+
You can check a demo [on StackBlitz](https://stackblitz.com/edit/nuxt-view-transitions).
|
|
419
422
|
|
|
420
|
-
The Nuxt integration
|
|
423
|
+
The Nuxt integration can be enabled with the `experimental.viewTransition` option in your configuration file:
|
|
421
424
|
|
|
422
425
|
```ts twoslash [nuxt.config.ts]
|
|
423
426
|
export default defineNuxtConfig({
|
|
424
427
|
experimental: {
|
|
425
|
-
viewTransition: true
|
|
426
|
-
}
|
|
428
|
+
viewTransition: true,
|
|
429
|
+
},
|
|
427
430
|
})
|
|
428
431
|
```
|
|
429
432
|
|
|
@@ -431,23 +434,23 @@ The possible values are: `false`, `true`, or `'always'`.
|
|
|
431
434
|
|
|
432
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.
|
|
433
436
|
|
|
434
|
-
By default, view transitions are enabled for all [pages](/docs/guide/directory-structure/app/pages), but you can set a different global default.
|
|
437
|
+
By default, view transitions are enabled for all [pages](/docs/4.x/guide/directory-structure/app/pages), but you can set a different global default.
|
|
435
438
|
|
|
436
439
|
```ts twoslash [nuxt.config.ts]
|
|
437
440
|
export default defineNuxtConfig({
|
|
438
441
|
app: {
|
|
439
442
|
// Disable view transitions globally, and opt-in on a per page basis
|
|
440
|
-
viewTransition: false
|
|
443
|
+
viewTransition: false,
|
|
441
444
|
},
|
|
442
445
|
})
|
|
443
446
|
```
|
|
444
447
|
|
|
445
|
-
It is possible to override the default `viewTransition` value for a page by setting the `viewTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page:
|
|
448
|
+
It is possible to override the default `viewTransition` value for a page by setting the `viewTransition` key in [`definePageMeta`](/docs/4.x/api/utils/define-page-meta) of the page:
|
|
446
449
|
|
|
447
450
|
```vue twoslash [pages/about.vue]
|
|
448
451
|
<script setup lang="ts">
|
|
449
452
|
definePageMeta({
|
|
450
|
-
viewTransition: false
|
|
453
|
+
viewTransition: false,
|
|
451
454
|
})
|
|
452
455
|
</script>
|
|
453
456
|
```
|
|
@@ -459,8 +462,10 @@ Overriding view transitions on a per-page basis will only have an effect if you
|
|
|
459
462
|
If you are also using Vue transitions like `pageTransition` and `layoutTransition` (see above) to achieve the same result as the new View Transitions API, then you may wish to _disable_ Vue transitions if the user's browser supports the newer, native web API. You can do this by creating `~/middleware/disable-vue-transitions.global.ts` with the following contents:
|
|
460
463
|
|
|
461
464
|
```ts
|
|
462
|
-
export default defineNuxtRouteMiddleware(to => {
|
|
463
|
-
if (import.meta.server || !document.startViewTransition) {
|
|
465
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
466
|
+
if (import.meta.server || !document.startViewTransition) {
|
|
467
|
+
return
|
|
468
|
+
}
|
|
464
469
|
|
|
465
470
|
// Disable built-in Vue transitions
|
|
466
471
|
to.meta.pageTransition = false
|