@nuxt/docs-nightly 4.1.3-29313386.edc02e27 → 4.1.3-29316215.910d159d
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 +4 -4
- package/1.getting-started/02.installation.md +1 -1
- package/1.getting-started/03.configuration.md +25 -25
- package/1.getting-started/04.views.md +3 -3
- package/1.getting-started/05.assets.md +9 -3
- package/1.getting-started/06.styling.md +53 -43
- package/1.getting-started/07.routing.md +9 -9
- package/1.getting-started/08.seo-meta.md +50 -37
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +61 -53
- package/1.getting-started/11.state-management.md +19 -12
- package/1.getting-started/12.error-handling.md +17 -15
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +19 -13
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +8 -8
- package/1.getting-started/17.testing.md +42 -42
- package/1.getting-started/18.upgrade.md +50 -68
- package/2.guide/0.index.md +5 -5
- package/2.guide/1.directory-structure/0.output.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.assets.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.components.md +40 -23
- package/2.guide/1.directory-structure/1.app/1.composables.md +9 -9
- package/2.guide/1.directory-structure/1.app/1.layouts.md +12 -8
- package/2.guide/1.directory-structure/1.app/1.middleware.md +23 -17
- package/2.guide/1.directory-structure/1.app/1.pages.md +25 -23
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.app-config.md +7 -7
- package/2.guide/1.directory-structure/1.app/3.app.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +5 -5
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +30 -30
- package/2.guide/1.directory-structure/1.shared.md +3 -3
- package/2.guide/1.directory-structure/2.env.md +3 -3
- package/2.guide/1.directory-structure/2.nuxtrc.md +1 -1
- package/2.guide/1.directory-structure/3.nuxt-config.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +15 -15
- package/2.guide/2.concepts/10.nuxt-lifecycle.md +7 -7
- package/2.guide/2.concepts/2.vuejs-development.md +9 -9
- package/2.guide/2.concepts/3.rendering.md +17 -15
- package/2.guide/2.concepts/4.server-engine.md +1 -1
- package/2.guide/2.concepts/5.modules.md +3 -3
- package/2.guide/2.concepts/7.esm.md +16 -14
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +238 -77
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +8 -8
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +83 -81
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +4 -4
- package/2.guide/3.going-further/7.layers.md +51 -42
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +10 -10
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/performance.md +13 -13
- 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/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +13 -8
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
- 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 +14 -14
- package/3.api/2.composables/use-cookie.md +27 -19
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +17 -17
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +3 -3
- package/3.api/2.composables/use-hydration.md +5 -5
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +10 -10
- package/3.api/2.composables/use-nuxt-app.md +10 -10
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +6 -4
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +3 -3
- package/3.api/2.composables/use-server-seo-meta.md +3 -3
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +6 -4
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +5 -5
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- 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 +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +16 -16
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- 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 +2 -2
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +10 -5
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +3 -3
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/generate.md +1 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/4.commands/typecheck.md +1 -1
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +299 -864
- package/3.api/index.md +7 -7
- package/5.community/4.contribution.md +5 -5
- package/5.community/5.framework-contribution.md +1 -1
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +4 -4
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +12 -9
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +18 -16
- package/7.migration/20.module-authors.md +1 -1
- package/7.migration/4.meta.md +18 -15
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +20 -16
- package/7.migration/7.component-options.md +7 -7
- package/7.migration/8.runtime-config.md +4 -4
- package/package.json +1 -1
|
@@ -10,18 +10,18 @@ links:
|
|
|
10
10
|
|
|
11
11
|
Just like [`useSeoMeta`](/docs/4.x/api/composables/use-seo-meta), `useServerSeoMeta` composable lets you define your site's SEO meta tags as a flat object with full TypeScript support.
|
|
12
12
|
|
|
13
|
-
:read-more{to="/docs/api/composables/use-seo-meta"}
|
|
13
|
+
:read-more{to="/docs/4.x/api/composables/use-seo-meta"}
|
|
14
14
|
|
|
15
15
|
In most instances, the meta doesn't need to be reactive as robots will only scan the initial load. So we recommend using [`useServerSeoMeta`](/docs/4.x/api/composables/use-server-seo-meta) as a performance-focused utility that will not do anything (or return a `head` object) on the client.
|
|
16
16
|
|
|
17
17
|
```vue [app/app.vue]
|
|
18
18
|
<script setup lang="ts">
|
|
19
19
|
useServerSeoMeta({
|
|
20
|
-
robots: 'index, follow'
|
|
20
|
+
robots: 'index, follow',
|
|
21
21
|
})
|
|
22
22
|
</script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Parameters are exactly the same as with [`useSeoMeta`](/docs/4.x/api/composables/use-seo-meta)
|
|
26
26
|
|
|
27
|
-
:read-more{to="/docs/getting-started/seo-meta"}
|
|
27
|
+
:read-more{to="/docs/4.x/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/getting-started/state-management"}
|
|
18
|
+
:read-more{to="/docs/4.x/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.
|
|
@@ -38,9 +38,9 @@ const state = useState('my-shallow-state', () => shallowRef({ deep: 'not reactiv
|
|
|
38
38
|
|
|
39
39
|
## Type
|
|
40
40
|
|
|
41
|
-
```ts
|
|
42
|
-
useState<T>(init?: () => T | Ref<T>): Ref<T>
|
|
43
|
-
useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
|
|
41
|
+
```ts [Signature]
|
|
42
|
+
export function useState<T> (init?: () => T | Ref<T>): Ref<T>
|
|
43
|
+
export function useState<T> (key: string, init?: () => T | Ref<T>): Ref<T>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
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/4.x/api/composables/use-state) will be generated for you.
|
package/3.api/3.utils/$fetch.md
CHANGED
|
@@ -35,22 +35,24 @@ const { data } = await useFetch('/api/item')
|
|
|
35
35
|
</script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
:read-more{to="/docs/getting-started/data-fetching"}
|
|
38
|
+
:read-more{to="/docs/4.x/getting-started/data-fetching"}
|
|
39
39
|
|
|
40
40
|
You can use `$fetch` in any methods that are executed only on client-side.
|
|
41
41
|
|
|
42
42
|
```vue [app/pages/contact.vue]
|
|
43
43
|
<script setup lang="ts">
|
|
44
|
-
async function contactForm() {
|
|
44
|
+
async function contactForm () {
|
|
45
45
|
await $fetch('/api/contact', {
|
|
46
46
|
method: 'POST',
|
|
47
|
-
body: { hello: 'world
|
|
47
|
+
body: { hello: 'world' },
|
|
48
48
|
})
|
|
49
49
|
}
|
|
50
50
|
</script>
|
|
51
51
|
|
|
52
52
|
<template>
|
|
53
|
-
<button @click="contactForm">
|
|
53
|
+
<button @click="contactForm">
|
|
54
|
+
Contact
|
|
55
|
+
</button>
|
|
54
56
|
</template>
|
|
55
57
|
```
|
|
56
58
|
|
|
@@ -80,9 +80,9 @@ Global route middleware can be defined in two ways:
|
|
|
80
80
|
```ts [app/plugins/my-plugin.ts]
|
|
81
81
|
export default defineNuxtPlugin(() => {
|
|
82
82
|
addRouteMiddleware('global-middleware', (to, from) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
console.log('global middleware that runs on every route change')
|
|
84
|
+
},
|
|
85
|
+
{ global: true },
|
|
86
86
|
)
|
|
87
87
|
})
|
|
88
88
|
```
|
|
@@ -54,11 +54,11 @@ await callOnce(async () => {
|
|
|
54
54
|
`navigation` mode is available since [Nuxt v3.15](/blog/v3-15).
|
|
55
55
|
::
|
|
56
56
|
|
|
57
|
-
::tip{to="/docs/getting-started/state-management#usage-with-pinia"}
|
|
57
|
+
::tip{to="/docs/4.x/getting-started/state-management#usage-with-pinia"}
|
|
58
58
|
`callOnce` is useful in combination with the [Pinia module](/modules/pinia) to call store actions.
|
|
59
59
|
::
|
|
60
60
|
|
|
61
|
-
:read-more{to="/docs/getting-started/state-management"}
|
|
61
|
+
:read-more{to="/docs/4.x/getting-started/state-management"}
|
|
62
62
|
|
|
63
63
|
::warning
|
|
64
64
|
Note that `callOnce` doesn't return anything. You should use [`useAsyncData`](/docs/4.x/api/composables/use-async-data) or [`useFetch`](/docs/4.x/api/composables/use-fetch) if you want to do data fetching during SSR.
|
|
@@ -70,9 +70,9 @@ Note that `callOnce` doesn't return anything. You should use [`useAsyncData`](/d
|
|
|
70
70
|
|
|
71
71
|
## Type
|
|
72
72
|
|
|
73
|
-
```ts
|
|
74
|
-
callOnce (key?: string, fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
|
|
75
|
-
callOnce(fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
|
|
73
|
+
```ts [Signature]
|
|
74
|
+
export function callOnce (key?: string, fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
|
|
75
|
+
export function callOnce (fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
|
|
76
76
|
|
|
77
77
|
type CallOnceOptions = {
|
|
78
78
|
/**
|
|
@@ -16,7 +16,7 @@ Within your pages, components, and plugins, you can use `clearError` to clear al
|
|
|
16
16
|
|
|
17
17
|
You can provide an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
|
|
18
18
|
|
|
19
|
-
```
|
|
19
|
+
```ts
|
|
20
20
|
// Without redirect
|
|
21
21
|
clearError()
|
|
22
22
|
|
|
@@ -26,4 +26,4 @@ clearError({ redirect: '/homepage' })
|
|
|
26
26
|
|
|
27
27
|
Errors are set in state using [`useError()`](/docs/4.x/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/getting-started/error-handling"}
|
|
29
|
+
:read-more{to="/docs/4.x/getting-started/error-handling"}
|
|
@@ -14,8 +14,8 @@ This method is useful if you want to invalidate the data fetching for another pa
|
|
|
14
14
|
|
|
15
15
|
## Type
|
|
16
16
|
|
|
17
|
-
```ts
|
|
18
|
-
clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void
|
|
17
|
+
```ts [Signature]
|
|
18
|
+
export function clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Parameters
|
|
@@ -14,8 +14,8 @@ This method is useful if you want to invalidate the state of `useState`.
|
|
|
14
14
|
|
|
15
15
|
## Type
|
|
16
16
|
|
|
17
|
-
```ts
|
|
18
|
-
clearNuxtState (keys?: string | string[] | ((key: string) => boolean)): void
|
|
17
|
+
```ts [Signature]
|
|
18
|
+
export function clearNuxtState (keys?: string | string[] | ((key: string) => boolean)): void
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Parameters
|
|
@@ -45,11 +45,11 @@ Use `createError` to trigger error handling in server API routes.
|
|
|
45
45
|
export default eventHandler(() => {
|
|
46
46
|
throw createError({
|
|
47
47
|
statusCode: 404,
|
|
48
|
-
statusMessage: 'Page Not Found'
|
|
48
|
+
statusMessage: 'Page Not Found',
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
In API routes, using `createError` by passing an object with a short `statusMessage` 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. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.
|
|
54
54
|
|
|
55
|
-
:read-more{to="/docs/getting-started/error-handling"}
|
|
55
|
+
:read-more{to="/docs/4.x/getting-started/error-handling"}
|
|
@@ -20,13 +20,13 @@ Hydrates the component when it becomes visible in the viewport.
|
|
|
20
20
|
<script setup lang="ts">
|
|
21
21
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
22
22
|
'visible',
|
|
23
|
-
() => import('./components/MyComponent.vue')
|
|
23
|
+
() => import('./components/MyComponent.vue'),
|
|
24
24
|
)
|
|
25
25
|
</script>
|
|
26
26
|
|
|
27
27
|
<template>
|
|
28
28
|
<div>
|
|
29
|
-
<!--
|
|
29
|
+
<!--
|
|
30
30
|
Hydration will be triggered when
|
|
31
31
|
the element(s) is 100px away from entering the viewport.
|
|
32
32
|
-->
|
|
@@ -53,7 +53,7 @@ Hydrates the component when the browser is idle. This is suitable if you need th
|
|
|
53
53
|
<script setup lang="ts">
|
|
54
54
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
55
55
|
'idle',
|
|
56
|
-
() => import('./components/MyComponent.vue')
|
|
56
|
+
() => import('./components/MyComponent.vue'),
|
|
57
57
|
)
|
|
58
58
|
</script>
|
|
59
59
|
|
|
@@ -81,7 +81,7 @@ Hydrates the component after a specified interaction (e.g., click, mouseover).
|
|
|
81
81
|
<script setup lang="ts">
|
|
82
82
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
83
83
|
'interaction',
|
|
84
|
-
() => import('./components/MyComponent.vue')
|
|
84
|
+
() => import('./components/MyComponent.vue'),
|
|
85
85
|
)
|
|
86
86
|
</script>
|
|
87
87
|
|
|
@@ -110,7 +110,7 @@ Hydrates the component when the window matches a media query.
|
|
|
110
110
|
<script setup lang="ts">
|
|
111
111
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
112
112
|
'mediaQuery',
|
|
113
|
-
() => import('./components/MyComponent.vue')
|
|
113
|
+
() => import('./components/MyComponent.vue'),
|
|
114
114
|
)
|
|
115
115
|
</script>
|
|
116
116
|
|
|
@@ -136,8 +136,8 @@ Hydrates the component after a specified delay (in milliseconds).
|
|
|
136
136
|
```vue
|
|
137
137
|
<script setup lang="ts">
|
|
138
138
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
139
|
-
'time',
|
|
140
|
-
() => import('./components/MyComponent.vue')
|
|
139
|
+
'time',
|
|
140
|
+
() => import('./components/MyComponent.vue'),
|
|
141
141
|
)
|
|
142
142
|
</script>
|
|
143
143
|
|
|
@@ -159,12 +159,12 @@ Hydrates the component based on a boolean condition.
|
|
|
159
159
|
<script setup lang="ts">
|
|
160
160
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
161
161
|
'if',
|
|
162
|
-
() => import('./components/MyComponent.vue')
|
|
162
|
+
() => import('./components/MyComponent.vue'),
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
const isReady = ref(false)
|
|
166
166
|
|
|
167
|
-
function myFunction() {
|
|
167
|
+
function myFunction () {
|
|
168
168
|
// Trigger custom hydration strategy...
|
|
169
169
|
isReady.value = true
|
|
170
170
|
}
|
|
@@ -188,7 +188,7 @@ Never hydrates the component.
|
|
|
188
188
|
<script setup lang="ts">
|
|
189
189
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
190
190
|
'never',
|
|
191
|
-
() => import('./components/MyComponent.vue')
|
|
191
|
+
() => import('./components/MyComponent.vue'),
|
|
192
192
|
)
|
|
193
193
|
</script>
|
|
194
194
|
|
|
@@ -208,11 +208,11 @@ All delayed hydration components emit a `@hydrated` event when they are hydrated
|
|
|
208
208
|
<script setup lang="ts">
|
|
209
209
|
const LazyHydrationMyComponent = defineLazyHydrationComponent(
|
|
210
210
|
'visible',
|
|
211
|
-
() => import('./components/MyComponent.vue')
|
|
211
|
+
() => import('./components/MyComponent.vue'),
|
|
212
212
|
)
|
|
213
213
|
|
|
214
|
-
function onHydrate() {
|
|
215
|
-
console.log(
|
|
214
|
+
function onHydrate () {
|
|
215
|
+
console.log('Component has been hydrated!')
|
|
216
216
|
}
|
|
217
217
|
</script>
|
|
218
218
|
|
|
@@ -25,11 +25,11 @@ If you choose not to use `setup()` in your app, you can use the `asyncData()` me
|
|
|
25
25
|
```vue [app/pages/index.vue]
|
|
26
26
|
<script lang="ts">
|
|
27
27
|
export default defineNuxtComponent({
|
|
28
|
-
|
|
28
|
+
asyncData () {
|
|
29
29
|
return {
|
|
30
30
|
data: {
|
|
31
|
-
greetings: 'hello world!'
|
|
32
|
-
}
|
|
31
|
+
greetings: 'hello world!',
|
|
32
|
+
},
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
})
|
|
@@ -43,9 +43,9 @@ If you choose not to use `setup()` in your app, you can use the `head()` method
|
|
|
43
43
|
```vue [app/pages/index.vue]
|
|
44
44
|
<script lang="ts">
|
|
45
45
|
export default defineNuxtComponent({
|
|
46
|
-
head(nuxtApp) {
|
|
46
|
+
head (nuxtApp) {
|
|
47
47
|
return {
|
|
48
|
-
title: 'My site'
|
|
48
|
+
title: 'My site',
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
})
|
|
@@ -16,14 +16,14 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
16
16
|
})
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
:read-more{to="/docs/guide/directory-structure/app/plugins#creating-plugins"}
|
|
19
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/plugins#creating-plugins"}
|
|
20
20
|
|
|
21
21
|
## Type
|
|
22
22
|
|
|
23
|
-
```ts
|
|
24
|
-
defineNuxtPlugin<T extends Record<string, unknown>>(plugin: Plugin<T> | ObjectPlugin<T>): Plugin<T> & ObjectPlugin<T>
|
|
23
|
+
```ts [Signature]
|
|
24
|
+
export function defineNuxtPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPlugin<T>): Plugin<T> & ObjectPlugin<T>
|
|
25
25
|
|
|
26
|
-
type Plugin<T> = (nuxt:
|
|
26
|
+
type Plugin<T> = (nuxt: NuxtApp) => Promise<void> | Promise<{ provide?: T }> | void | { provide?: T }
|
|
27
27
|
|
|
28
28
|
interface ObjectPlugin<T> {
|
|
29
29
|
name?: string
|
|
@@ -32,7 +32,7 @@ interface ObjectPlugin<T> {
|
|
|
32
32
|
order?: number
|
|
33
33
|
parallel?: boolean
|
|
34
34
|
setup?: Plugin<T>
|
|
35
|
-
hooks?: Partial<
|
|
35
|
+
hooks?: Partial<RuntimeNuxtHooks>
|
|
36
36
|
env?: {
|
|
37
37
|
islands?: boolean
|
|
38
38
|
}
|
|
@@ -69,8 +69,8 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
69
69
|
// Add a global method
|
|
70
70
|
return {
|
|
71
71
|
provide: {
|
|
72
|
-
hello: (name: string) => `Hello ${name}
|
|
73
|
-
}
|
|
72
|
+
hello: (name: string) => `Hello ${name}!`,
|
|
73
|
+
},
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
76
|
```
|
|
@@ -86,17 +86,17 @@ export default defineNuxtPlugin({
|
|
|
86
86
|
async setup (nuxtApp) {
|
|
87
87
|
// Plugin setup logic
|
|
88
88
|
const data = await $fetch('/api/config')
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
return {
|
|
91
91
|
provide: {
|
|
92
|
-
config: data
|
|
93
|
-
}
|
|
92
|
+
config: data,
|
|
93
|
+
},
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
hooks: {
|
|
97
|
-
'app:created'() {
|
|
97
|
+
'app:created' () {
|
|
98
98
|
console.log('App created!')
|
|
99
|
-
}
|
|
99
|
+
},
|
|
100
100
|
},
|
|
101
101
|
})
|
|
102
102
|
```
|
|
@@ -12,8 +12,8 @@ Route middleware are stored in the [`app/middleware/`](/docs/4.x/guide/directory
|
|
|
12
12
|
|
|
13
13
|
## Type
|
|
14
14
|
|
|
15
|
-
```ts
|
|
16
|
-
defineNuxtRouteMiddleware(middleware: RouteMiddleware)
|
|
15
|
+
```ts [Signature]
|
|
16
|
+
export function defineNuxtRouteMiddleware (middleware: RouteMiddleware): RouteMiddleware
|
|
17
17
|
|
|
18
18
|
interface RouteMiddleware {
|
|
19
19
|
(to: RouteLocationNormalized, from: RouteLocationNormalized): ReturnType<NavigationGuard>
|
|
@@ -13,20 +13,20 @@ links:
|
|
|
13
13
|
```vue [app/pages/some-page.vue]
|
|
14
14
|
<script setup lang="ts">
|
|
15
15
|
definePageMeta({
|
|
16
|
-
layout: 'default'
|
|
16
|
+
layout: 'default',
|
|
17
17
|
})
|
|
18
18
|
</script>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
:read-more{to="/docs/guide/directory-structure/app/pages#page-metadata"}
|
|
21
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/pages#page-metadata"}
|
|
22
22
|
|
|
23
23
|
## Type
|
|
24
24
|
|
|
25
|
-
```ts
|
|
26
|
-
definePageMeta(meta: PageMeta)
|
|
25
|
+
```ts [Signature]
|
|
26
|
+
export function definePageMeta (meta: PageMeta): void
|
|
27
27
|
|
|
28
28
|
interface PageMeta {
|
|
29
|
-
validate?: (route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>
|
|
29
|
+
validate?: ((route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>)
|
|
30
30
|
redirect?: RouteRecordRedirectOption
|
|
31
31
|
name?: string
|
|
32
32
|
path?: string
|
|
@@ -62,7 +62,7 @@ interface PageMeta {
|
|
|
62
62
|
|
|
63
63
|
- **Type**: `string`
|
|
64
64
|
|
|
65
|
-
You may define a [custom regular expression](/docs/api/composables/use-nuxt-app#using-a-custom-regular-expression) if you have a more complex pattern than can be expressed with the file name.
|
|
65
|
+
You may define a [custom regular expression](/docs/4.x/api/composables/use-nuxt-app#using-a-custom-regular-expression) if you have a more complex pattern than can be expressed with the file name.
|
|
66
66
|
|
|
67
67
|
**`props`**
|
|
68
68
|
|
|
@@ -157,13 +157,13 @@ The example below demonstrates:
|
|
|
157
157
|
```vue [app/pages/some-page.vue]
|
|
158
158
|
<script setup lang="ts">
|
|
159
159
|
definePageMeta({
|
|
160
|
-
key:
|
|
160
|
+
key: route => route.fullPath,
|
|
161
161
|
|
|
162
162
|
keepalive: {
|
|
163
|
-
exclude: ['modal']
|
|
163
|
+
exclude: ['modal'],
|
|
164
164
|
},
|
|
165
165
|
|
|
166
|
-
pageType: 'Checkout'
|
|
166
|
+
pageType: 'Checkout',
|
|
167
167
|
})
|
|
168
168
|
</script>
|
|
169
169
|
```
|
|
@@ -181,20 +181,20 @@ definePageMeta({
|
|
|
181
181
|
const auth = useState('auth')
|
|
182
182
|
|
|
183
183
|
if (!auth.value.authenticated) {
|
|
184
|
-
|
|
184
|
+
return navigateTo('/login')
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
if (to.path !== '/checkout') {
|
|
188
188
|
return navigateTo('/checkout')
|
|
189
189
|
}
|
|
190
|
-
}
|
|
190
|
+
},
|
|
191
191
|
],
|
|
192
192
|
|
|
193
193
|
// ... or a string
|
|
194
|
-
middleware: 'auth'
|
|
194
|
+
middleware: 'auth',
|
|
195
195
|
|
|
196
196
|
// ... or multiple strings
|
|
197
|
-
middleware: ['auth', 'another-named-middleware']
|
|
197
|
+
middleware: ['auth', 'another-named-middleware'],
|
|
198
198
|
})
|
|
199
199
|
</script>
|
|
200
200
|
```
|
|
@@ -210,7 +210,7 @@ To make sure that we are only matching digits (`\d+`) for `postId` in the `[post
|
|
|
210
210
|
```vue [app/pages/[postId\\]-[postSlug\\].vue]
|
|
211
211
|
<script setup lang="ts">
|
|
212
212
|
definePageMeta({
|
|
213
|
-
path: '/:postId(\\d+)-:postSlug'
|
|
213
|
+
path: '/:postId(\\d+)-:postSlug',
|
|
214
214
|
})
|
|
215
215
|
</script>
|
|
216
216
|
```
|
|
@@ -225,10 +225,10 @@ You can define the layout that matches the layout's file name located (by defaul
|
|
|
225
225
|
<script setup lang="ts">
|
|
226
226
|
definePageMeta({
|
|
227
227
|
// set custom layout
|
|
228
|
-
layout: 'admin'
|
|
228
|
+
layout: 'admin',
|
|
229
229
|
|
|
230
230
|
// ... or disable a default layout
|
|
231
|
-
layout: false
|
|
231
|
+
layout: false,
|
|
232
232
|
})
|
|
233
233
|
</script>
|
|
234
234
|
```
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
::read-more{to="/docs/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
|
|
11
|
+
::read-more{to="/docs/4.x/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
|
|
12
12
|
This feature is experimental and in order to use it you must enable the `experimental.inlineRouteRules` option in your `nuxt.config`.
|
|
13
13
|
::
|
|
14
14
|
|
|
@@ -17,7 +17,7 @@ This feature is experimental and in order to use it you must enable the `experim
|
|
|
17
17
|
```vue [app/pages/index.vue]
|
|
18
18
|
<script setup lang="ts">
|
|
19
19
|
defineRouteRules({
|
|
20
|
-
prerender: true
|
|
20
|
+
prerender: true,
|
|
21
21
|
})
|
|
22
22
|
</script>
|
|
23
23
|
|
|
@@ -31,8 +31,8 @@ Will be translated to:
|
|
|
31
31
|
```ts [nuxt.config.ts]
|
|
32
32
|
export default defineNuxtConfig({
|
|
33
33
|
routeRules: {
|
|
34
|
-
'/': { prerender: true }
|
|
35
|
-
}
|
|
34
|
+
'/': { prerender: true },
|
|
35
|
+
},
|
|
36
36
|
})
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -47,6 +47,6 @@ When running [`nuxt build`](/docs/4.x/api/commands/build), the home page will be
|
|
|
47
47
|
|
|
48
48
|
For more control, such as if you are using a custom `path` or `alias` set in the page's [`definePageMeta`](/docs/4.x/api/utils/define-page-meta), you should set `routeRules` directly within your `nuxt.config`.
|
|
49
49
|
|
|
50
|
-
::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering" icon="i-lucide-medal"}
|
|
50
|
+
::read-more{to="/docs/4.x/guide/concepts/rendering#hybrid-rendering" icon="i-lucide-medal"}
|
|
51
51
|
Read more about the `routeRules`.
|
|
52
52
|
::
|
|
@@ -35,8 +35,8 @@ await navigateTo({
|
|
|
35
35
|
path: '/search',
|
|
36
36
|
query: {
|
|
37
37
|
page: 1,
|
|
38
|
-
sort: 'asc'
|
|
39
|
-
}
|
|
38
|
+
sort: 'asc',
|
|
39
|
+
},
|
|
40
40
|
})
|
|
41
41
|
</script>
|
|
42
42
|
```
|
|
@@ -68,7 +68,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
68
68
|
|
|
69
69
|
In this case, `navigateTo` will be executed but not returned, which may lead to unexpected behavior.
|
|
70
70
|
|
|
71
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
71
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
|
|
72
72
|
|
|
73
73
|
### Navigating to an External URL
|
|
74
74
|
|
|
@@ -92,7 +92,7 @@ await navigateTo('https://nuxt.com')
|
|
|
92
92
|
|
|
93
93
|
// will redirect successfully with the 'external' parameter set to 'true'
|
|
94
94
|
await navigateTo('https://nuxt.com', {
|
|
95
|
-
external: true
|
|
95
|
+
external: true,
|
|
96
96
|
})
|
|
97
97
|
</script>
|
|
98
98
|
```
|
|
@@ -107,20 +107,20 @@ await navigateTo('https://nuxt.com', {
|
|
|
107
107
|
target: '_blank',
|
|
108
108
|
windowFeatures: {
|
|
109
109
|
width: 500,
|
|
110
|
-
height: 500
|
|
111
|
-
}
|
|
112
|
-
}
|
|
110
|
+
height: 500,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
113
|
})
|
|
114
114
|
</script>
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
## Type
|
|
118
118
|
|
|
119
|
-
```ts
|
|
120
|
-
function navigateTo(
|
|
119
|
+
```ts [Signature]
|
|
120
|
+
export function navigateTo (
|
|
121
121
|
to: RouteLocationRaw | undefined | null,
|
|
122
122
|
options?: NavigateToOptions
|
|
123
|
-
)
|
|
123
|
+
): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw
|
|
124
124
|
|
|
125
125
|
interface NavigateToOptions {
|
|
126
126
|
replace?: boolean
|
|
@@ -12,7 +12,7 @@ Preloading components loads components that your page will need very soon, which
|
|
|
12
12
|
|
|
13
13
|
Use `preloadComponents` to manually preload individual components that have been registered globally in your Nuxt app. By default Nuxt registers these as async components. You must use the Pascal-cased version of the component name.
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```ts
|
|
16
16
|
await preloadComponents('MyGlobalComponent')
|
|
17
17
|
|
|
18
18
|
await preloadComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
|
|
@@ -14,7 +14,7 @@ Preloading routes loads the components of a given route that the user might navi
|
|
|
14
14
|
Nuxt already automatically preloads the necessary routes if you're using the `NuxtLink` component.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
|
-
:read-more{to="/docs/api/components/nuxt-link"}
|
|
17
|
+
:read-more{to="/docs/4.x/api/components/nuxt-link"}
|
|
18
18
|
|
|
19
19
|
## Example
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ const submit = async () => {
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
:read-more{to="/docs/api/utils/navigate-to"}
|
|
37
|
+
:read-more{to="/docs/4.x/api/utils/navigate-to"}
|
|
38
38
|
|
|
39
39
|
::note
|
|
40
40
|
On server, `preloadRouteComponents` will have no effect.
|
|
@@ -18,7 +18,7 @@ When prerendering, you can hint to Nitro to prerender additional paths, even if
|
|
|
18
18
|
`prerenderRoutes` has to be executed during prerendering. If the `prerenderRoutes` is used in dynamic pages/routes which are not prerendered, then it will not be executed.
|
|
19
19
|
::
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```ts
|
|
22
22
|
const route = useRoute()
|
|
23
23
|
|
|
24
24
|
prerenderRoutes('/')
|
|
@@ -31,7 +31,7 @@ In the browser, or if called outside prerendering, `prerenderRoutes` will have n
|
|
|
31
31
|
|
|
32
32
|
You can even prerender API routes which is particularly useful for full statically generated sites (SSG) because you can then `$fetch` data as if you have an available server!
|
|
33
33
|
|
|
34
|
-
```
|
|
34
|
+
```ts
|
|
35
35
|
prerenderRoutes('/api/content/article/name-of-article')
|
|
36
36
|
|
|
37
37
|
// Somewhere later in App
|
|
@@ -27,7 +27,7 @@ This is useful for updating the `useCookie` ref when we know the new cookie valu
|
|
|
27
27
|
const tokenCookie = useCookie('token')
|
|
28
28
|
|
|
29
29
|
const login = async (username, password) => {
|
|
30
|
-
const token = await $fetch('/api/token', { ... }) // Sets `token` cookie on response
|
|
30
|
+
const token = await $fetch('/api/token', { /** ... */ }) // Sets `token` cookie on response
|
|
31
31
|
refreshCookie('token')
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -35,12 +35,12 @@ const loggedIn = computed(() => !!tokenCookie.value)
|
|
|
35
35
|
</script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
::note{to="/docs/guide/going-further/experimental-features#cookiestore"}
|
|
38
|
+
::note{to="/docs/4.x/guide/going-further/experimental-features#cookiestore"}
|
|
39
39
|
You can enable experimental `cookieStore` option to automatically refresh `useCookie` value when cookie changes in the browser.
|
|
40
40
|
::
|
|
41
41
|
|
|
42
42
|
## Type
|
|
43
43
|
|
|
44
|
-
```ts
|
|
45
|
-
refreshCookie(name: string): void
|
|
44
|
+
```ts [Signature]
|
|
45
|
+
export function refreshCookie (name: string): void
|
|
46
46
|
```
|