@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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 +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- 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 +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
|
@@ -8,16 +8,42 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Within the [Nuxt context](/docs/
|
|
11
|
+
Within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) you can use `useRequestEvent` to access the incoming request.
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
// Get underlying request event
|
|
15
15
|
const event = useRequestEvent()
|
|
16
16
|
|
|
17
|
-
// Get the
|
|
18
|
-
const
|
|
17
|
+
// Get the path of the incoming request
|
|
18
|
+
const path = event?.path
|
|
19
|
+
|
|
20
|
+
// Read a request header
|
|
21
|
+
const userAgent = event?.headers.get('user-agent')
|
|
19
22
|
```
|
|
20
23
|
|
|
21
24
|
::tip
|
|
22
25
|
In the browser, `useRequestEvent` will return `undefined`.
|
|
23
26
|
::
|
|
27
|
+
|
|
28
|
+
## Type
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
function useRequestEvent (nuxtApp?: NuxtApp): NuxtRequestEvent | undefined
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`NuxtRequestEvent` is the event in the shape your configured [server builder](/docs/guide/going-further/builders) provides. With the default `@nuxt/nitro-server`, that is h3 v1's `H3Event`, which is why the example above reads `event.path` rather than `event.url`.
|
|
35
|
+
|
|
36
|
+
When no server builder contributes an event type, the event resolves to `RequestEvent`, the web-standard part every server runtime provides:
|
|
37
|
+
|
|
38
|
+
| Property | Type | Description |
|
|
39
|
+
| --------- | ------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
40
|
+
| `req` | `Request` | The incoming request, including its `headers`, `method` and body. |
|
|
41
|
+
| `url` | `URL` | The parsed request URL. |
|
|
42
|
+
| `res` | `{ status?, statusText?, headers }` | The response status and headers to be sent. |
|
|
43
|
+
| `context` | `RequestEventContext` | Per-request state, including Nuxt's own state under `context.nuxt`. |
|
|
44
|
+
|
|
45
|
+
Code that should work whichever server builder is configured (a module's server handler, for example) should only read these properties.
|
|
46
|
+
|
|
47
|
+
::read-more{to="/docs/guide/going-further/server-imports"}
|
|
48
|
+
Read more about writing portable server code with `nuxt/server`.
|
|
49
|
+
::
|
|
@@ -20,7 +20,7 @@ Headers that are **not meant to be forwarded** will **not be included** in the r
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::tip
|
|
23
|
-
The [`useFetch`](/docs/
|
|
23
|
+
The [`useFetch`](/docs/api/composables/use-fetch) composable uses `useRequestFetch` under the hood to automatically forward the request context and headers.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
::code-group
|
|
@@ -49,5 +49,5 @@ export default defineEventHandler((event) => {
|
|
|
49
49
|
::
|
|
50
50
|
|
|
51
51
|
::tip
|
|
52
|
-
In the browser during client-side navigation, `useRequestFetch` will behave just like regular [`$fetch`](/docs/
|
|
52
|
+
In the browser during client-side navigation, `useRequestFetch` will behave just like regular [`$fetch`](/docs/api/utils/dollarfetch).
|
|
53
53
|
::
|
|
@@ -9,7 +9,7 @@ links:
|
|
|
9
9
|
size: xs
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
You can use the built-in [`useRequestHeader`](/docs/
|
|
12
|
+
You can use the built-in [`useRequestHeader`](/docs/api/composables/use-request-header) composable to access any incoming request header within your pages, components, and plugins.
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
15
|
// Get the authorization request header
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
You can use built-in [`useRequestHeaders`](/docs/
|
|
11
|
+
You can use built-in [`useRequestHeaders`](/docs/api/composables/use-request-headers) composable to access the incoming request headers within your pages, components, and plugins.
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
// Get all request headers
|
|
@@ -12,7 +12,7 @@ links:
|
|
|
12
12
|
`useRequestURL` is a helper function that returns an [URL object](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) working on both server-side and client-side.
|
|
13
13
|
|
|
14
14
|
::important
|
|
15
|
-
When utilizing [Hybrid Rendering](/docs/
|
|
15
|
+
When utilizing [Hybrid Rendering](/docs/guide/concepts/rendering#hybrid-rendering) with cache strategies, all incoming request headers are dropped when handling the cached responses via the [Nitro caching layer](https://nitro.build/guide/cache) (meaning `useRequestURL` will return `localhost` for the `host`).
|
|
16
16
|
|
|
17
17
|
You can define the [`cache.varies` option](https://nitro.build/guide/cache#options) to specify headers that will be considered when caching and serving the responses, such as `host` and `x-forwarded-host` for multi-tenant environments.
|
|
18
18
|
::
|
|
@@ -13,7 +13,7 @@ links:
|
|
|
13
13
|
This composable is available in Nuxt v3.14+.
|
|
14
14
|
::
|
|
15
15
|
|
|
16
|
-
You can use the built-in [`useResponseHeader`](/docs/
|
|
16
|
+
You can use the built-in [`useResponseHeader`](/docs/api/composables/use-response-header) composable to set any server response header within your pages, components, and plugins.
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
// Set a custom response header
|
|
@@ -38,7 +38,7 @@ header.value = 'my-value'
|
|
|
38
38
|
</template>
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/
|
|
41
|
+
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/directory-structure/app/middleware) to set a response header for all pages.
|
|
42
42
|
|
|
43
43
|
```ts [app/middleware/my-header-middleware.ts]
|
|
44
44
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
@@ -15,9 +15,11 @@ This composable is available in Nuxt v3.12+.
|
|
|
15
15
|
|
|
16
16
|
## Description
|
|
17
17
|
|
|
18
|
-
A composable which observes the page title changes and updates the announcer message accordingly. Used by [`<NuxtRouteAnnouncer>`](/docs/
|
|
18
|
+
A composable which observes the page title changes and updates the announcer message accordingly. Used by [`<NuxtRouteAnnouncer>`](/docs/api/components/nuxt-route-announcer) and controllable.
|
|
19
19
|
It hooks into Unhead's `dom:rendered` hook to read the page's title and set it as the announcer message.
|
|
20
20
|
|
|
21
|
+
:read-more{title="Nuxt accessibility" to="/docs/guide/best-practices/accessibility#route-announcements"}
|
|
22
|
+
|
|
21
23
|
## Parameters
|
|
22
24
|
|
|
23
25
|
- `politeness`: Sets the urgency for screen reader announcements: `off` (disable the announcement), `polite` (waits for silence), or `assertive` (interrupts immediately). (default `polite`).
|
|
@@ -59,5 +61,5 @@ const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
|
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
::callout
|
|
62
|
-
For announcing dynamic in-page content changes (form validation, toasts, loading states), use [`useAnnouncer`](/docs/
|
|
64
|
+
For announcing dynamic in-page content changes (form validation, toasts, loading states), use [`useAnnouncer`](/docs/api/composables/use-announcer) instead.
|
|
63
65
|
::
|
|
@@ -20,7 +20,7 @@ that rely on the route metadata, for example.
|
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
|
-
In the following example, we call an API via [`useFetch`](/docs/
|
|
23
|
+
In the following example, we call an API via [`useFetch`](/docs/api/composables/use-fetch) using a dynamic page parameter - `slug` - as part of the URL.
|
|
24
24
|
|
|
25
25
|
```html [~/pages/[slug\\].vue]
|
|
26
26
|
<script setup lang="ts">
|
|
@@ -76,7 +76,7 @@ The `useRoute()` composable should only be used in the setup function of a Vue c
|
|
|
76
76
|
This applies to any composable that uses `useRoute()` internally too.
|
|
77
77
|
::
|
|
78
78
|
|
|
79
|
-
::read-more{to="/docs/
|
|
79
|
+
::read-more{to="/docs/directory-structure/app/middleware"}
|
|
80
80
|
Read more about accessing the route in the middleware section.
|
|
81
81
|
::
|
|
82
82
|
|
|
@@ -49,7 +49,7 @@ router.resolve({ name: 'home' })
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
::note
|
|
52
|
-
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/
|
|
52
|
+
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/directory-structure/app/plugins) while `router.push()` on the other hand, triggers a new navigation immediately and it is useful in pages, Vue components and composable.
|
|
53
53
|
::
|
|
54
54
|
|
|
55
55
|
## Based on History API
|
|
@@ -57,8 +57,8 @@ router.resolve({ name: 'home' })
|
|
|
57
57
|
- [`back()`](https://router.vuejs.org/api/interfaces/router#back-): Go back in history if possible, same as `router.go(-1)`.
|
|
58
58
|
- [`forward()`](https://router.vuejs.org/api/interfaces/router#forward-): Go forward in history if possible, same as `router.go(1)`.
|
|
59
59
|
- [`go()`](https://router.vuejs.org/api/interfaces/router#go-): Move forward or backward through the history without the hierarchical restrictions enforced in `router.back()` and `router.forward()`.
|
|
60
|
-
- [`push()`](https://router.vuejs.org/api/interfaces/router#push-): Programmatically navigate to a new URL by pushing an entry in the history stack. **It is recommended to use [`navigateTo`](/docs/
|
|
61
|
-
- [`replace()`](https://router.vuejs.org/api/interfaces/router#replace-): Programmatically navigate to a new URL by replacing the current entry in the routes history stack. **It is recommended to use [`navigateTo`](/docs/
|
|
60
|
+
- [`push()`](https://router.vuejs.org/api/interfaces/router#push-): Programmatically navigate to a new URL by pushing an entry in the history stack. **It is recommended to use [`navigateTo`](/docs/api/utils/navigate-to) instead.**
|
|
61
|
+
- [`replace()`](https://router.vuejs.org/api/interfaces/router#replace-): Programmatically navigate to a new URL by replacing the current entry in the routes history stack. **It is recommended to use [`navigateTo`](/docs/api/utils/navigate-to) instead.**
|
|
62
62
|
|
|
63
63
|
```ts [Example]
|
|
64
64
|
const router = useRouter()
|
|
@@ -80,7 +80,7 @@ Read more about the browser's History API.
|
|
|
80
80
|
|
|
81
81
|
However, Nuxt has a concept of **route middleware** that simplifies the implementation of navigation guards and provides a better developer experience.
|
|
82
82
|
|
|
83
|
-
:read-more{to="/docs/
|
|
83
|
+
:read-more{to="/docs/directory-structure/app/middleware"}
|
|
84
84
|
|
|
85
85
|
## Promise and Error Handling
|
|
86
86
|
|
|
@@ -91,4 +91,4 @@ However, Nuxt has a concept of **route middleware** that simplifies the implemen
|
|
|
91
91
|
|
|
92
92
|
## Universal Router Instance
|
|
93
93
|
|
|
94
|
-
If you do not have a `app/pages/` folder, then [`useRouter`](/docs/
|
|
94
|
+
If you do not have a `app/pages/` folder, then [`useRouter`](/docs/api/composables/use-router) will return a universal router instance with similar helper methods, but be aware that not all features may be supported or behave in exactly the same way as with `vue-router`.
|
|
@@ -22,7 +22,7 @@ export default defineEventHandler((event) => {
|
|
|
22
22
|
})
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
:read-more{to="/docs/
|
|
25
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
26
26
|
|
|
27
27
|
## Define Runtime Config
|
|
28
28
|
|
|
@@ -48,7 +48,7 @@ export default defineNuxtConfig({
|
|
|
48
48
|
Variables that need to be accessible on the server are added directly inside `runtimeConfig`. Variables that need to be accessible on both the client and the server are defined in `runtimeConfig.public`.
|
|
49
49
|
::
|
|
50
50
|
|
|
51
|
-
:read-more{to="/docs/
|
|
51
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
52
52
|
|
|
53
53
|
## Access Runtime Config
|
|
54
54
|
|
|
@@ -76,7 +76,7 @@ In this example, since `apiBase` is defined within the `public` namespace, it is
|
|
|
76
76
|
|
|
77
77
|
It is possible to update runtime config values using a matching environment variable name prefixed with `NUXT_`.
|
|
78
78
|
|
|
79
|
-
:read-more{to="/docs/
|
|
79
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
80
80
|
|
|
81
81
|
### Using the `.env` File
|
|
82
82
|
|
|
@@ -95,7 +95,7 @@ Any environment variables set within `.env` file are accessed using `process.env
|
|
|
95
95
|
In **production runtime**, you should use platform environment variables and `.env` is not used.
|
|
96
96
|
::
|
|
97
97
|
|
|
98
|
-
:read-more{to="/docs/
|
|
98
|
+
:read-more{to="/docs/directory-structure/env"}
|
|
99
99
|
|
|
100
100
|
## `app` namespace
|
|
101
101
|
|
|
@@ -139,4 +139,4 @@ export default defineEventHandler((event) => {
|
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
:read-more{to="/docs/
|
|
142
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
@@ -24,7 +24,7 @@ function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> (
|
|
|
24
24
|
|
|
25
25
|
### Parameters
|
|
26
26
|
|
|
27
|
-
- `name`: The name of the runtime hook to register. You can see the full list of [runtime Nuxt hooks here](/docs/
|
|
27
|
+
- `name`: The name of the runtime hook to register. You can see the full list of [runtime Nuxt hooks here](/docs/api/advanced/hooks#app-hooks-runtime).
|
|
28
28
|
- `fn`: The callback function to execute when the hook is triggered. The function signature varies based on the hook name.
|
|
29
29
|
|
|
30
30
|
### Return Values
|
|
@@ -14,7 +14,7 @@ This helps you avoid common mistakes, such as using `name` instead of `property`
|
|
|
14
14
|
This is the recommended way to add meta tags to your site as it is XSS safe and has full TypeScript support.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
|
-
:read-more{to="/docs/
|
|
17
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
@@ -48,7 +48,7 @@ useSeoMeta({
|
|
|
48
48
|
|
|
49
49
|
There are over 100 parameters. See the [full list of parameters in the source code](https://github.com/harlan-zw/zhead/blob/main/packages/zhead/src/metaFlat.ts#L1035).
|
|
50
50
|
|
|
51
|
-
:read-more{to="/docs/
|
|
51
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
52
52
|
|
|
53
53
|
## Performance
|
|
54
54
|
|
|
@@ -77,4 +77,4 @@ useSeoMeta({
|
|
|
77
77
|
</script>
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
This previously used the [`useServerSeoMeta`](/docs/
|
|
80
|
+
This previously used the [`useServerSeoMeta`](/docs/api/composables/use-server-seo-meta) composable, but it has been deprecated in favor of this approach.
|
|
@@ -9,12 +9,12 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::warning
|
|
12
|
-
`useServerSeoMeta` is deprecated. Wrap [`useSeoMeta`](/docs/
|
|
12
|
+
`useServerSeoMeta` is deprecated. Wrap [`useSeoMeta`](/docs/api/composables/use-seo-meta) in an `if (import.meta.server)` block instead. The auto-import is removed under `future.compatibilityVersion: 5`.
|
|
13
13
|
::
|
|
14
14
|
|
|
15
|
-
`useServerSeoMeta` lets you define your site's SEO meta tags as a flat object with full TypeScript support, exactly like [`useSeoMeta`](/docs/
|
|
15
|
+
`useServerSeoMeta` lets you define your site's SEO meta tags as a flat object with full TypeScript support, exactly like [`useSeoMeta`](/docs/api/composables/use-seo-meta), but it only runs server-side and is tree-shaken from the client bundle.
|
|
16
16
|
|
|
17
|
-
:read-more{to="/docs/
|
|
17
|
+
:read-more{to="/docs/api/composables/use-seo-meta"}
|
|
18
18
|
|
|
19
19
|
For new code, use the server-only pattern directly:
|
|
20
20
|
|
|
@@ -28,6 +28,6 @@ if (import.meta.server) {
|
|
|
28
28
|
</script>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
Parameters are exactly the same as with [`useSeoMeta`](/docs/
|
|
31
|
+
Parameters are exactly the same as with [`useSeoMeta`](/docs/api/composables/use-seo-meta).
|
|
32
32
|
|
|
33
|
-
:read-more{to="/docs/
|
|
33
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
@@ -15,7 +15,7 @@ links:
|
|
|
15
15
|
const count = useState('counter', () => Math.round(Math.random() * 100))
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
:read-more{to="/docs/
|
|
18
|
+
:read-more{to="/docs/getting-started/state-management"}
|
|
19
19
|
|
|
20
20
|
::important
|
|
21
21
|
Because the data inside `useState` will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
|
|
@@ -43,7 +43,7 @@ export function useState<T> (init?: () => T | Ref<T>): Ref<T>
|
|
|
43
43
|
export function useState<T> (key: string, init?: () => T | Ref<T>): Ref<T>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
- `key`: A unique key ensuring that data fetching is properly de-duplicated across requests. If you do not provide a key, then a key that is unique to the file and line number of the instance of [`useState`](/docs/
|
|
46
|
+
- `key`: A unique key ensuring that data fetching is properly de-duplicated across requests. If you do not provide a key, then a key that is unique to the file and line number of the instance of [`useState`](/docs/api/composables/use-state) will be generated for you.
|
|
47
47
|
- `init`: A function that provides initial value for the state when not initiated. This function can also return a `Ref`.
|
|
48
48
|
- `T`: (typescript only) Specify the type of state
|
|
49
49
|
|
|
@@ -53,6 +53,6 @@ export function useState<T> (key: string, init?: () => T | Ref<T>): Ref<T>
|
|
|
53
53
|
|
|
54
54
|
This error occurs when you try to store a non-serializable payload with `useState`, such as class instances.
|
|
55
55
|
|
|
56
|
-
If you want to store class instances with `useState` that are not supported by Nuxt, you can use [`definePayloadPlugin`](/docs/
|
|
56
|
+
If you want to store class instances with `useState` that are not supported by Nuxt, you can use [`definePayloadPlugin`](/docs/api/composables/use-nuxt-app#custom-reducerreviver) to add a custom serializer and deserializer for your classes.
|
|
57
57
|
|
|
58
|
-
:read-more{to="/docs/
|
|
58
|
+
:read-more{to="/docs/api/composables/use-nuxt-app#payload"}
|
package/4.api/3.utils/$fetch.md
CHANGED
|
@@ -11,16 +11,16 @@ links:
|
|
|
11
11
|
Nuxt uses [ofetch](https://github.com/unjs/ofetch) to expose globally the `$fetch` helper for making HTTP requests within your Vue app or API routes.
|
|
12
12
|
|
|
13
13
|
::tip{icon="i-lucide-rocket"}
|
|
14
|
-
During server-side rendering, calling `$fetch` to fetch your internal [API routes](/docs/
|
|
14
|
+
During server-side rendering, calling `$fetch` to fetch your internal [API routes](/docs/directory-structure/server) will directly call the relevant function (emulating the request), **saving an additional API call**.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
17
|
::note{color="blue" icon="i-lucide-info"}
|
|
18
|
-
Using `$fetch` in components without wrapping it with [`useAsyncData`](/docs/
|
|
18
|
+
Using `$fetch` in components without wrapping it with [`useAsyncData`](/docs/api/composables/use-async-data) causes fetching the data twice: initially on the server, then again on the client-side during hydration, because `$fetch` does not transfer state from the server to the client. Thus, the fetch will be executed on both sides because the client has to get the data again.
|
|
19
19
|
::
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
We recommend using [`useFetch`](/docs/
|
|
23
|
+
We recommend using [`useFetch`](/docs/api/composables/use-fetch) or [`useAsyncData`](/docs/api/composables/use-async-data) + `$fetch` to prevent double data fetching when fetching the component data.
|
|
24
24
|
|
|
25
25
|
```vue [app/app.vue]
|
|
26
26
|
<script setup lang="ts">
|
|
@@ -35,7 +35,7 @@ const { data } = await useFetch('/api/item')
|
|
|
35
35
|
</script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
:read-more{to="/docs/
|
|
38
|
+
:read-more{to="/docs/getting-started/data-fetching"}
|
|
39
39
|
|
|
40
40
|
You can use `$fetch` in any methods that are executed only on client-side.
|
|
41
41
|
|
|
@@ -97,4 +97,4 @@ const { data } = await useAsyncData(() => requestFetch('/api/cookies'))
|
|
|
97
97
|
</script>
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
However, when calling `useFetch` with a relative URL on the server, Nuxt will use [`useRequestFetch`](/docs/
|
|
100
|
+
However, when calling `useFetch` with a relative URL on the server, Nuxt will use [`useRequestFetch`](/docs/api/composables/use-request-fetch) to proxy headers and cookies (with the exception of headers not meant to be forwarded, like `host`).
|
|
@@ -9,7 +9,7 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::warning
|
|
12
|
-
`abortNavigation` is only usable inside a [route middleware handler](/docs/
|
|
12
|
+
`abortNavigation` is only usable inside a [route middleware handler](/docs/directory-structure/app/middleware).
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
## Type
|
|
@@ -9,7 +9,7 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::note
|
|
12
|
-
Route middleware are navigation guards stored in the [`app/middleware/`](/docs/
|
|
12
|
+
Route middleware are navigation guards stored in the [`app/middleware/`](/docs/directory-structure/app/middleware) directory of your Nuxt application (unless [set otherwise](/docs/api/nuxt-config#middleware)).
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
## Type
|
|
@@ -31,7 +31,7 @@ interface AddRouteMiddlewareOptions {
|
|
|
31
31
|
|
|
32
32
|
Can be either a string or a function of type `RouteMiddleware`. Function takes the next route `to` as the first argument and the current route `from` as the second argument, both of which are Vue route objects.
|
|
33
33
|
|
|
34
|
-
Learn more about available properties of [route objects](/docs/
|
|
34
|
+
Learn more about available properties of [route objects](/docs/api/composables/use-route).
|
|
35
35
|
|
|
36
36
|
### `middleware`
|
|
37
37
|
|
|
@@ -53,14 +53,14 @@ await callOnce(async () => {
|
|
|
53
53
|
`navigation` mode is available since [Nuxt v3.15](/blog/v3-15).
|
|
54
54
|
::
|
|
55
55
|
|
|
56
|
-
::tip{to="/docs/
|
|
56
|
+
::tip{to="/docs/getting-started/state-management#usage-with-pinia"}
|
|
57
57
|
`callOnce` is useful in combination with the [Pinia module](/modules/pinia) to call store actions.
|
|
58
58
|
::
|
|
59
59
|
|
|
60
|
-
:read-more{to="/docs/
|
|
60
|
+
:read-more{to="/docs/getting-started/state-management"}
|
|
61
61
|
|
|
62
62
|
::warning
|
|
63
|
-
Note that `callOnce` doesn't return anything. You should use [`useAsyncData`](/docs/
|
|
63
|
+
Note that `callOnce` doesn't return anything. You should use [`useAsyncData`](/docs/api/composables/use-async-data) or [`useFetch`](/docs/api/composables/use-fetch) if you want to do data fetching during SSR.
|
|
64
64
|
::
|
|
65
65
|
|
|
66
66
|
::note
|
|
@@ -24,6 +24,6 @@ clearError()
|
|
|
24
24
|
clearError({ redirect: '/homepage' })
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Errors are set in state using [`useError()`](/docs/
|
|
27
|
+
Errors are set in state using [`useError()`](/docs/api/composables/use-error). The `clearError` composable will reset this state and calls the `app:error:cleared` hook with the provided options.
|
|
28
28
|
|
|
29
|
-
:read-more{to="/docs/
|
|
29
|
+
:read-more{to="/docs/getting-started/error-handling"}
|
|
@@ -20,4 +20,4 @@ export function clearNuxtData (keys?: string | string[] | ((key: string) => bool
|
|
|
20
20
|
|
|
21
21
|
## Parameters
|
|
22
22
|
|
|
23
|
-
* `keys`: One or an array of keys that are used in [`useAsyncData`](/docs/
|
|
23
|
+
* `keys`: One or an array of keys that are used in [`useAsyncData`](/docs/api/composables/use-async-data) to delete their cached data. If no keys are provided, **all data** will be invalidated.
|
|
@@ -21,6 +21,6 @@ export function clearNuxtState (keys?: string | string[] | ((key: string) => boo
|
|
|
21
21
|
|
|
22
22
|
## Parameters
|
|
23
23
|
|
|
24
|
-
- `keys`: One or an array of keys that are used in [`useState`](/docs/
|
|
24
|
+
- `keys`: One or an array of keys that are used in [`useState`](/docs/api/composables/use-state) to delete their cached state. If no keys are provided, **all state** will be invalidated.
|
|
25
25
|
- `opts`: An options object to configure the clear behavior.
|
|
26
|
-
- `reset` :badge[v4.4]{color="info" size="xs" class="align-middle"}: When set to `true`, resets the state to the initial value provided by the `init` function of [`useState`](/docs/
|
|
26
|
+
- `reset` :badge[v4.4]{color="info" size="xs" class="align-middle"}: When set to `true`, resets the state to the initial value provided by the `init` function of [`useState`](/docs/api/composables/use-state) instead of setting it to `undefined`. When not specified, defaults to the value of `experimental.defaults.useState.resetOnClear` in your Nuxt config (which is `true` with `compatibilityVersion: 5`).
|
|
@@ -35,6 +35,24 @@ if (!data.value) {
|
|
|
35
35
|
</script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Error Causes
|
|
39
|
+
|
|
40
|
+
You can pass a `cause` when creating an error to preserve the original error you are wrapping:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
try {
|
|
44
|
+
await fetchMovie(route.params.slug)
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
throw createError({
|
|
47
|
+
status: 500,
|
|
48
|
+
message: 'Could not load movie',
|
|
49
|
+
cause,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
In development, the cause chain is exposed to your [error page](/docs/getting-started/error-handling#error-page) via the `cause` property of the error, serialized as `{ name, message, stack, cause }` (primitive causes are passed through as-is; other values are omitted). In production, causes are never included in error responses or in the error page payload.
|
|
55
|
+
|
|
38
56
|
## In API Routes
|
|
39
57
|
|
|
40
58
|
Use `createError` to trigger error handling in server API routes.
|
|
@@ -52,4 +70,4 @@ export default eventHandler(() => {
|
|
|
52
70
|
|
|
53
71
|
In API routes, using `createError` by passing an object with a short `statusText` is recommended because it can be accessed on the client side. Otherwise, a `message` passed to `createError` on an API route will not propagate to the client. Alternatively, you can use the `data` property to pass data back to the client. When handling the error with `useFetch`, the custom data is available at `error.value.data.data`. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.
|
|
54
72
|
|
|
55
|
-
:read-more{to="/docs/
|
|
73
|
+
:read-more{to="/docs/getting-started/error-handling"}
|
|
@@ -16,7 +16,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
16
16
|
})
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
:read-more{to="/docs/
|
|
19
|
+
:read-more{to="/docs/directory-structure/app/plugins#creating-plugins"}
|
|
20
20
|
|
|
21
21
|
## Type
|
|
22
22
|
|
|
@@ -42,7 +42,7 @@ interface ObjectPlugin<T> {
|
|
|
42
42
|
## Parameters
|
|
43
43
|
|
|
44
44
|
**plugin**: A plugin can be defined in two ways:
|
|
45
|
-
1. **Function Plugin**: A function that receives the [`NuxtApp`](/docs/
|
|
45
|
+
1. **Function Plugin**: A function that receives the [`NuxtApp`](/docs/guide/going-further/internals#the-nuxtapp-interface) instance and can return a promise with a potential object with a [`provide`](/docs/directory-structure/app/plugins#providing-helpers) property if you want to provide a helper on [`NuxtApp`](/docs/guide/going-further/internals#the-nuxtapp-interface) instance.
|
|
46
46
|
2. **Object Plugin**: An object that can include various properties to configure the plugin's behavior, such as `name`, `enforce`, `dependsOn`, `order`, `parallel`, `setup`, `hooks`, and `env`.
|
|
47
47
|
|
|
48
48
|
| Property | Type | Required | Description |
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Route middleware are stored in the [`app/middleware/`](/docs/
|
|
11
|
+
Route middleware are stored in the [`app/middleware/`](/docs/directory-structure/app/middleware) of your Nuxt application (unless [set otherwise](/docs/api/nuxt-config#middleware)).
|
|
12
12
|
|
|
13
13
|
## Type
|
|
14
14
|
|
|
@@ -48,7 +48,7 @@ The above route middleware will redirect a user to the custom error page defined
|
|
|
48
48
|
|
|
49
49
|
### Redirection
|
|
50
50
|
|
|
51
|
-
Use [`useState`](/docs/
|
|
51
|
+
Use [`useState`](/docs/api/composables/use-state) in combination with `navigateTo` helper function inside the route middleware to redirect users to different routes based on their authentication status:
|
|
52
52
|
|
|
53
53
|
```ts [app/middleware/auth.ts]
|
|
54
54
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
@@ -64,4 +64,4 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
64
64
|
})
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
Both [navigateTo](/docs/
|
|
67
|
+
Both [navigateTo](/docs/api/utils/navigate-to) and [abortNavigation](/docs/api/utils/abort-navigation) are globally available helper functions that you can use inside `defineNuxtRouteMiddleware`.
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
`definePageMeta` is a compiler macro that you can use to set metadata for your **page** components located in the [`app/pages/`](/docs/
|
|
11
|
+
`definePageMeta` is a compiler macro that you can use to set metadata for your **page** components located in the [`app/pages/`](/docs/directory-structure/app/pages) directory (unless [set otherwise](/docs/api/nuxt-config#pages)). This way you can set custom metadata for each static or dynamic route of your Nuxt application.
|
|
12
12
|
|
|
13
13
|
```vue [app/pages/some-page.vue]
|
|
14
14
|
<script setup lang="ts">
|
|
@@ -18,7 +18,7 @@ definePageMeta({
|
|
|
18
18
|
</script>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
:read-more{to="/docs/
|
|
21
|
+
:read-more{to="/docs/directory-structure/app/pages#page-metadata"}
|
|
22
22
|
|
|
23
23
|
## Type
|
|
24
24
|
|
|
@@ -57,13 +57,13 @@ interface PageMeta {
|
|
|
57
57
|
|
|
58
58
|
- **Type**: `string`
|
|
59
59
|
|
|
60
|
-
You may define a name for this page's route. By default, name is generated based on path inside the [`app/pages/` directory](/docs/
|
|
60
|
+
You may define a name for this page's route. By default, name is generated based on path inside the [`app/pages/` directory](/docs/directory-structure/app/pages).
|
|
61
61
|
|
|
62
62
|
**`path`**
|
|
63
63
|
|
|
64
64
|
- **Type**: `string`
|
|
65
65
|
|
|
66
|
-
You may define a [custom regular expression](/docs/
|
|
66
|
+
You may define a [custom regular expression](/docs/api/utils/define-page-meta#using-a-custom-regular-expression) if you have a more complex pattern than can be expressed with the file name.
|
|
67
67
|
|
|
68
68
|
**`props`**
|
|
69
69
|
|
|
@@ -81,7 +81,7 @@ interface PageMeta {
|
|
|
81
81
|
|
|
82
82
|
- **Type**: `string[]`
|
|
83
83
|
|
|
84
|
-
Route groups the page belongs to, based on the folder structure. Automatically populated for pages within [route groups](/docs/
|
|
84
|
+
Route groups the page belongs to, based on the folder structure. Automatically populated for pages within [route groups](/docs/guide/directory-structure/app/pages#route-groups).
|
|
85
85
|
|
|
86
86
|
**`keepalive`**
|
|
87
87
|
|
|
@@ -113,7 +113,7 @@ interface PageMeta {
|
|
|
113
113
|
|
|
114
114
|
- **Type**: `MiddlewareKey` | [`NavigationGuard`](https://router.vuejs.org/api/interfaces/navigationguard) | `Array<MiddlewareKey | NavigationGuard>`
|
|
115
115
|
|
|
116
|
-
Define anonymous or named middleware directly within `definePageMeta`. Learn more about [route middleware](/docs/
|
|
116
|
+
Define anonymous or named middleware directly within `definePageMeta`. Learn more about [route middleware](/docs/directory-structure/app/middleware).
|
|
117
117
|
|
|
118
118
|
**`pageTransition`**
|
|
119
119
|
|
|
@@ -125,11 +125,11 @@ interface PageMeta {
|
|
|
125
125
|
|
|
126
126
|
- **Type**: `boolean | 'always' | ViewTransitionPageOptions`
|
|
127
127
|
|
|
128
|
-
**Experimental feature, only available when [enabled in your nuxt.config file](/docs/
|
|
128
|
+
**Experimental feature, only available when [enabled in your nuxt.config file](/docs/getting-started/transitions#view-transitions-api-experimental)**</br>
|
|
129
129
|
Enable/disable View Transitions for the current page.
|
|
130
130
|
If set to true, Nuxt will not apply the transition if the users browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition.
|
|
131
131
|
|
|
132
|
-
You can also pass a `ViewTransitionPageOptions` object to configure [view transition types](/docs/
|
|
132
|
+
You can also pass a `ViewTransitionPageOptions` object to configure [view transition types](/docs/getting-started/transitions#view-transition-types):
|
|
133
133
|
- `enabled`: `boolean | 'always'` - enable/disable the transition
|
|
134
134
|
- `types`: `string[] | (to, from) => string[]` - types applied to any transition involving this page
|
|
135
135
|
- `toTypes`: `string[] | (to, from) => string[]` - types applied only when navigating **to** this page
|
|
@@ -151,13 +151,13 @@ interface PageMeta {
|
|
|
151
151
|
|
|
152
152
|
- **Type**: `boolean | (to: RouteLocationNormalized, from: RouteLocationNormalized) => boolean`
|
|
153
153
|
|
|
154
|
-
Tell Nuxt to scroll to the top before rendering the page or not. Navigation is independent from rendering, so scroll behavior is always triggered even when the page doesn't re-render (e.g. when using a fixed [`key`](/docs/
|
|
154
|
+
Tell Nuxt to scroll to the top before rendering the page or not. Navigation is independent from rendering, so scroll behavior is always triggered even when the page doesn't re-render (e.g. when using a fixed [`key`](/docs/api/utils/define-page-meta#key)). Set `scrollToTop: false` to disable scrolling in such cases. If you want to overwrite the default scroll behavior of Nuxt, you can do so in `~/router.options.ts` (see [custom routing](/docs/guide/recipes/custom-routing#using-routeroptions)) for more info.
|
|
155
155
|
|
|
156
156
|
**`[key: string]`**
|
|
157
157
|
|
|
158
158
|
- **Type**: `any`
|
|
159
159
|
|
|
160
|
-
Apart from the above properties, you can also set **custom** metadata. You may wish to do so in a type-safe way by [augmenting the type of the `meta` object](/docs/
|
|
160
|
+
Apart from the above properties, you can also set **custom** metadata. You may wish to do so in a type-safe way by [augmenting the type of the `meta` object](/docs/directory-structure/app/pages/#typing-custom-metadata).
|
|
161
161
|
|
|
162
162
|
## Example
|
|
163
163
|
|
|
@@ -234,7 +234,7 @@ For more examples see [Vue Router's Matching Syntax](https://router.vuejs.org/gu
|
|
|
234
234
|
|
|
235
235
|
### Defining Layout
|
|
236
236
|
|
|
237
|
-
You can define the layout that matches the layout's file name located (by default) in the [`app/layouts/` directory](/docs/
|
|
237
|
+
You can define the layout that matches the layout's file name located (by default) in the [`app/layouts/` directory](/docs/directory-structure/app/layouts). You can also disable the layout by setting the `layout` to `false`:
|
|
238
238
|
|
|
239
239
|
```vue [app/pages/some-page.vue]
|
|
240
240
|
<script setup lang="ts">
|
|
@@ -295,4 +295,4 @@ const props = defineProps<{
|
|
|
295
295
|
Layout props set via `definePageMeta` are fully typed based on the layout's `defineProps`. You'll get autocomplete and type-checking in your editor.
|
|
296
296
|
::
|
|
297
297
|
|
|
298
|
-
:read-more{to="/docs/
|
|
298
|
+
:read-more{to="/docs/directory-structure/app/layouts#passing-props-to-layouts"}
|