@nuxt/docs-nightly 4.1.1-29282072.39113ab4 → 4.1.1-29283054.32d56553
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +1 -1
- package/1.getting-started/03.configuration.md +2 -2
- package/1.getting-started/04.views.md +15 -15
- package/1.getting-started/05.assets.md +6 -6
- package/1.getting-started/06.styling.md +8 -8
- package/1.getting-started/07.routing.md +7 -7
- package/1.getting-started/08.seo-meta.md +9 -9
- package/1.getting-started/09.transitions.md +15 -15
- package/1.getting-started/10.data-fetching.md +9 -9
- package/1.getting-started/11.state-management.md +7 -7
- package/1.getting-started/12.error-handling.md +1 -1
- package/1.getting-started/14.layers.md +2 -2
- package/1.getting-started/15.prerendering.md +2 -2
- package/1.getting-started/17.testing.md +1 -1
- package/1.getting-started/18.upgrade.md +7 -7
- package/2.guide/1.concepts/1.auto-imports.md +6 -6
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +6 -6
- package/2.guide/1.concepts/2.vuejs-development.md +3 -3
- package/2.guide/1.concepts/3.rendering.md +2 -2
- package/2.guide/1.concepts/8.typescript.md +1 -1
- package/2.guide/2.directory-structure/1.app/1.components.md +18 -18
- package/2.guide/2.directory-structure/1.app/1.composables.md +11 -11
- package/2.guide/2.directory-structure/1.app/1.layouts.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.middleware.md +3 -3
- package/2.guide/2.directory-structure/1.app/1.pages.md +15 -15
- package/2.guide/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/2.directory-structure/1.app/3.app-config.md +2 -2
- package/2.guide/2.directory-structure/1.app/3.app.md +12 -12
- package/2.guide/2.directory-structure/1.content.md +2 -2
- package/2.guide/2.directory-structure/1.public.md +1 -1
- package/2.guide/2.directory-structure/1.server.md +3 -3
- package/2.guide/2.directory-structure/1.shared.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +5 -5
- package/2.guide/3.going-further/10.runtime-config.md +2 -2
- package/2.guide/3.going-further/2.hooks.md +1 -1
- package/2.guide/3.going-further/6.nuxt-app.md +2 -2
- package/2.guide/3.going-further/7.layers.md +7 -7
- package/2.guide/4.recipes/1.custom-routing.md +1 -1
- package/2.guide/4.recipes/2.vite-plugin.md +1 -1
- package/2.guide/4.recipes/3.custom-usefetch.md +4 -4
- package/2.guide/4.recipes/4.sessions-and-authentication.md +4 -4
- package/2.guide/5.best-practices/performance.md +2 -2
- package/3.api/1.components/1.client-only.md +2 -2
- package/3.api/1.components/1.dev-only.md +1 -1
- package/3.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +2 -2
- package/3.api/1.components/2.nuxt-page.md +8 -8
- package/3.api/1.components/3.nuxt-layout.md +13 -13
- package/3.api/1.components/4.nuxt-link.md +9 -9
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/7.nuxt-welcome.md +1 -1
- package/3.api/2.composables/on-prehydrate.md +1 -1
- package/3.api/2.composables/use-async-data.md +3 -3
- package/3.api/2.composables/use-cookie.md +1 -1
- package/3.api/2.composables/use-fetch.md +2 -2
- package/3.api/2.composables/use-lazy-async-data.md +1 -1
- package/3.api/2.composables/use-lazy-fetch.md +1 -1
- package/3.api/2.composables/use-nuxt-app.md +7 -7
- package/3.api/2.composables/use-nuxt-data.md +4 -4
- package/3.api/2.composables/use-preview-mode.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +1 -1
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +3 -3
- package/3.api/2.composables/use-route-announcer.md +1 -1
- package/3.api/2.composables/use-router.md +5 -5
- package/3.api/2.composables/use-runtime-config.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +3 -3
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/3.utils/$fetch.md +4 -4
- package/3.api/3.utils/abort-navigation.md +4 -4
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +2 -2
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-nuxt-component.md +2 -2
- package/3.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/3.api/3.utils/define-page-meta.md +12 -12
- package/3.api/3.utils/define-route-rules.md +1 -1
- package/3.api/3.utils/navigate-to.md +1 -1
- package/3.api/3.utils/on-nuxt-ready.md +1 -1
- package/3.api/3.utils/refresh-cookie.md +1 -1
- package/3.api/3.utils/refresh-nuxt-data.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/4.commands/add.md +7 -7
- package/3.api/5.kit/7.pages.md +1 -1
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +1 -1
- package/3.api/6.nuxt-config.md +12 -17
- package/6.bridge/4.plugins-and-middleware.md +3 -3
- package/6.bridge/6.meta.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/7.migration/3.auto-imports.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +2 -2
- package/7.migration/6.pages-and-layouts.md +8 -8
- package/7.migration/7.component-options.md +4 -4
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
|
@@ -16,9 +16,9 @@ This component is available in Nuxt v3.12+.
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`layouts/`](/docs/guide/directory-structure/layouts) to enhance accessibility by informing assistive technologies about page title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
19
|
+
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`app/layouts/`](/docs/guide/directory-structure/app/layouts) to enhance accessibility by informing assistive technologies about page title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
20
20
|
|
|
21
|
-
```vue [app.vue]
|
|
21
|
+
```vue [app/app.vue]
|
|
22
22
|
<template>
|
|
23
23
|
<NuxtRouteAnnouncer />
|
|
24
24
|
<NuxtLayout>
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`pages/`](/docs/guide/directory-structure/pages) directory.
|
|
11
|
+
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`app/pages/`](/docs/guide/directory-structure/app/pages) directory.
|
|
12
12
|
|
|
13
13
|
::note
|
|
14
14
|
`<NuxtPage>` is a wrapper around [`<RouterView>`](https://router.vuejs.org/api/interfaces/RouterViewProps.html#interface-routerviewprops) from Vue Router. It should be used instead of `<RouterView>` because the former takes additional care of internal states. Otherwise, `useRoute()` may return incorrect paths.
|
|
@@ -63,7 +63,7 @@ Nuxt automatically resolves the `name` and `route` by scanning and rendering all
|
|
|
63
63
|
|
|
64
64
|
For example, if you pass a key that never changes, the `<NuxtPage>` component will be rendered only once - when it is first mounted.
|
|
65
65
|
|
|
66
|
-
```vue [app.vue]
|
|
66
|
+
```vue [app/app.vue]
|
|
67
67
|
<template>
|
|
68
68
|
<NuxtPage page-key="static" />
|
|
69
69
|
</template>
|
|
@@ -81,7 +81,7 @@ Don't use `$route` object here as it can cause problems with how `<NuxtPage>` re
|
|
|
81
81
|
|
|
82
82
|
Alternatively, `pageKey` can be passed as a `key` value via [`definePageMeta`](/docs/api/utils/define-page-meta) from the `<script>` section of your Vue component in the `/pages` directory.
|
|
83
83
|
|
|
84
|
-
```vue [pages/my-page.vue]
|
|
84
|
+
```vue [app/pages/my-page.vue]
|
|
85
85
|
<script setup lang="ts">
|
|
86
86
|
definePageMeta({
|
|
87
87
|
key: route => route.fullPath
|
|
@@ -95,7 +95,7 @@ definePageMeta({
|
|
|
95
95
|
|
|
96
96
|
To get the `ref` of a page component, access it through `ref.value.pageRef`
|
|
97
97
|
|
|
98
|
-
````vue [app.vue]
|
|
98
|
+
````vue [app/app.vue]
|
|
99
99
|
<script setup lang="ts">
|
|
100
100
|
const page = ref()
|
|
101
101
|
|
|
@@ -127,7 +127,7 @@ defineExpose({
|
|
|
127
127
|
|
|
128
128
|
For example, in the below example, the value of `foobar` will be passed to the `NuxtPage` component and then to the page components.
|
|
129
129
|
|
|
130
|
-
```vue [app.vue]
|
|
130
|
+
```vue [app/app.vue]
|
|
131
131
|
<template>
|
|
132
132
|
<NuxtPage :foobar="123" />
|
|
133
133
|
</template>
|
|
@@ -135,7 +135,7 @@ For example, in the below example, the value of `foobar` will be passed to the `
|
|
|
135
135
|
|
|
136
136
|
We can access the `foobar` prop in the page component:
|
|
137
137
|
|
|
138
|
-
```vue [pages/page.vue]
|
|
138
|
+
```vue [app/pages/page.vue]
|
|
139
139
|
<script setup lang="ts">
|
|
140
140
|
const props = defineProps<{ foobar: number }>()
|
|
141
141
|
|
|
@@ -144,11 +144,11 @@ console.log(props.foobar) // Outputs: 123
|
|
|
144
144
|
|
|
145
145
|
If you have not defined the prop with `defineProps`, any props passed down to `NuxtPage` can still be accessed directly from the page `attrs`:
|
|
146
146
|
|
|
147
|
-
```vue [pages/page.vue]
|
|
147
|
+
```vue [app/pages/page.vue]
|
|
148
148
|
<script setup lang="ts">
|
|
149
149
|
const attrs = useAttrs()
|
|
150
150
|
console.log(attrs.foobar) // Outputs: 123
|
|
151
151
|
</script>
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
:read-more{to="/docs/guide/directory-structure/pages"}
|
|
154
|
+
:read-more{to="/docs/guide/directory-structure/app/pages"}
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
You can use `<NuxtLayout />` component to activate the `default` layout on `app.vue` or `error.vue`.
|
|
12
12
|
|
|
13
|
-
```vue [app.vue]
|
|
13
|
+
```vue [app/app.vue]
|
|
14
14
|
<template>
|
|
15
15
|
<NuxtLayout>
|
|
16
16
|
some page content
|
|
@@ -18,15 +18,15 @@ You can use `<NuxtLayout />` component to activate the `default` layout on `app.
|
|
|
18
18
|
</template>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
:read-more{to="/docs/guide/directory-structure/layouts"}
|
|
21
|
+
:read-more{to="/docs/guide/directory-structure/app/layouts"}
|
|
22
22
|
|
|
23
23
|
## Props
|
|
24
24
|
|
|
25
|
-
- `name`: Specify a layout name to be rendered, can be a string, reactive reference or a computed property. It **must** match the name of the corresponding layout file in the [`layouts/`](/docs/guide/directory-structure/layouts) directory.
|
|
25
|
+
- `name`: Specify a layout name to be rendered, can be a string, reactive reference or a computed property. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/guide/directory-structure/app/layouts) directory.
|
|
26
26
|
- **type**: `string`
|
|
27
27
|
- **default**: `default`
|
|
28
28
|
|
|
29
|
-
```vue [pages/index.vue]
|
|
29
|
+
```vue [app/pages/index.vue]
|
|
30
30
|
<script setup lang="ts">
|
|
31
31
|
// layouts/custom.vue
|
|
32
32
|
const layout = 'custom'
|
|
@@ -51,11 +51,11 @@ Please note the layout name is normalized to kebab-case, so if your layout file
|
|
|
51
51
|
</template>
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
::read-more{to="/docs/guide/directory-structure/layouts"}
|
|
54
|
+
::read-more{to="/docs/guide/directory-structure/app/layouts"}
|
|
55
55
|
Read more about dynamic layouts.
|
|
56
56
|
::
|
|
57
57
|
|
|
58
|
-
- `fallback`: If an invalid layout is passed to the `name` prop, no layout will be rendered. Specify a `fallback` layout to be rendered in this scenario. It **must** match the name of the corresponding layout file in the [`layouts/`](/docs/guide/directory-structure/layouts) directory.
|
|
58
|
+
- `fallback`: If an invalid layout is passed to the `name` prop, no layout will be rendered. Specify a `fallback` layout to be rendered in this scenario. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/guide/directory-structure/app/layouts) directory.
|
|
59
59
|
- **type**: `string`
|
|
60
60
|
- **default**: `null`
|
|
61
61
|
|
|
@@ -63,7 +63,7 @@ Read more about dynamic layouts.
|
|
|
63
63
|
|
|
64
64
|
`NuxtLayout` also accepts any additional props that you may need to pass to the layout. These custom props are then made accessible as attributes.
|
|
65
65
|
|
|
66
|
-
```vue [pages/some-page.vue]
|
|
66
|
+
```vue [app/pages/some-page.vue]
|
|
67
67
|
<template>
|
|
68
68
|
<div>
|
|
69
69
|
<NuxtLayout name="custom" title="I am a custom layout">
|
|
@@ -75,7 +75,7 @@ Read more about dynamic layouts.
|
|
|
75
75
|
|
|
76
76
|
In the above example, the value of `title` will be available using `$attrs.title` in the template or `useAttrs().title` in `<script setup>` at custom.vue.
|
|
77
77
|
|
|
78
|
-
```vue [layouts/custom.vue]
|
|
78
|
+
```vue [app/layouts/custom.vue]
|
|
79
79
|
<script setup lang="ts">
|
|
80
80
|
const layoutCustomProps = useAttrs()
|
|
81
81
|
|
|
@@ -89,7 +89,7 @@ console.log(layoutCustomProps.title) // I am a custom layout
|
|
|
89
89
|
|
|
90
90
|
::code-group
|
|
91
91
|
|
|
92
|
-
```vue [pages/index.vue]
|
|
92
|
+
```vue [app/pages/index.vue]
|
|
93
93
|
<template>
|
|
94
94
|
<div>
|
|
95
95
|
<NuxtLayout name="custom">
|
|
@@ -99,7 +99,7 @@ console.log(layoutCustomProps.title) // I am a custom layout
|
|
|
99
99
|
</template>
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
```vue [layouts/custom.vue]
|
|
102
|
+
```vue [app/layouts/custom.vue]
|
|
103
103
|
<template>
|
|
104
104
|
<div>
|
|
105
105
|
<!-- named slot -->
|
|
@@ -119,7 +119,7 @@ To get the ref of a layout component, access it through `ref.value.layoutRef`.
|
|
|
119
119
|
|
|
120
120
|
::code-group
|
|
121
121
|
|
|
122
|
-
```vue [app.vue]
|
|
122
|
+
```vue [app/app.vue]
|
|
123
123
|
<script setup lang="ts">
|
|
124
124
|
const layout = ref()
|
|
125
125
|
|
|
@@ -135,7 +135,7 @@ function logFoo () {
|
|
|
135
135
|
</template>
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
```vue [layouts/default.vue]
|
|
138
|
+
```vue [app/layouts/default.vue]
|
|
139
139
|
<script setup lang="ts">
|
|
140
140
|
const foo = () => console.log('foo')
|
|
141
141
|
defineExpose({
|
|
@@ -153,4 +153,4 @@ defineExpose({
|
|
|
153
153
|
|
|
154
154
|
::
|
|
155
155
|
|
|
156
|
-
:read-more{to="/docs/guide/directory-structure/layouts"}
|
|
156
|
+
:read-more{to="/docs/guide/directory-structure/app/layouts"}
|
|
@@ -17,7 +17,7 @@ links:
|
|
|
17
17
|
In this example, we use `<NuxtLink>` component to link to another page of the application.
|
|
18
18
|
|
|
19
19
|
::code-group
|
|
20
|
-
```vue [pages/index.vue]
|
|
20
|
+
```vue [app/pages/index.vue]
|
|
21
21
|
<template>
|
|
22
22
|
<NuxtLink to="/about">About page</NuxtLink>
|
|
23
23
|
</template>
|
|
@@ -34,7 +34,7 @@ In this example, we use `<NuxtLink>` component to link to another page of the ap
|
|
|
34
34
|
In this example, we pass the `id` param to link to the route `~/pages/posts/[id].vue`.
|
|
35
35
|
|
|
36
36
|
::code-group
|
|
37
|
-
```vue [pages/index.vue]
|
|
37
|
+
```vue [app/pages/index.vue]
|
|
38
38
|
<template>
|
|
39
39
|
<NuxtLink :to="{ name: 'posts-id', params: { id: 123 } }">
|
|
40
40
|
Post 123
|
|
@@ -65,7 +65,7 @@ The `external` prop explicitly indicates that the link is external. `<NuxtLink>`
|
|
|
65
65
|
|
|
66
66
|
For static files in the `/public` directory, such as PDFs or images, use the `external` prop to ensure the link resolves correctly.
|
|
67
67
|
|
|
68
|
-
```vue [pages/index.vue]
|
|
68
|
+
```vue [app/pages/index.vue]
|
|
69
69
|
<template>
|
|
70
70
|
<NuxtLink to="/example-report.pdf" external>
|
|
71
71
|
Download Report
|
|
@@ -77,7 +77,7 @@ For static files in the `/public` directory, such as PDFs or images, use the `ex
|
|
|
77
77
|
|
|
78
78
|
When pointing to a different application on the same domain, using the `external` prop ensures the correct behavior.
|
|
79
79
|
|
|
80
|
-
```vue [pages/index.vue]
|
|
80
|
+
```vue [app/pages/index.vue]
|
|
81
81
|
<template>
|
|
82
82
|
<NuxtLink to="/another-app" external>
|
|
83
83
|
Go to Another App
|
|
@@ -91,7 +91,7 @@ Using the `external` prop or relying on automatic handling ensures proper naviga
|
|
|
91
91
|
|
|
92
92
|
In this example, we use `<NuxtLink>` component to link to a website.
|
|
93
93
|
|
|
94
|
-
```vue [app.vue]
|
|
94
|
+
```vue [app/app.vue]
|
|
95
95
|
<template>
|
|
96
96
|
<NuxtLink to="https://nuxtjs.org">
|
|
97
97
|
Nuxt website
|
|
@@ -110,7 +110,7 @@ These defaults have no negative impact on SEO and are considered [best practice]
|
|
|
110
110
|
|
|
111
111
|
When you need to overwrite this behavior you can use the `rel` or `noRel` props.
|
|
112
112
|
|
|
113
|
-
```vue [app.vue]
|
|
113
|
+
```vue [app/app.vue]
|
|
114
114
|
<template>
|
|
115
115
|
<NuxtLink to="https://twitter.com/nuxt_js">
|
|
116
116
|
Nuxt Twitter
|
|
@@ -129,7 +129,7 @@ When you need to overwrite this behavior you can use the `rel` or `noRel` props.
|
|
|
129
129
|
|
|
130
130
|
A `noRel` prop can be used to prevent the default `rel` attribute from being added to the absolute links.
|
|
131
131
|
|
|
132
|
-
```vue [app.vue]
|
|
132
|
+
```vue [app/app.vue]
|
|
133
133
|
<template>
|
|
134
134
|
<NuxtLink to="https://github.com/nuxt" no-rel>
|
|
135
135
|
Nuxt GitHub
|
|
@@ -146,7 +146,7 @@ A `noRel` prop can be used to prevent the default `rel` attribute from being add
|
|
|
146
146
|
|
|
147
147
|
Nuxt automatically includes smart prefetching. That means it detects when a link is visible (by default), either in the viewport or when scrolling and prefetches the JavaScript for those pages so that they are ready when the user clicks the link. Nuxt only loads the resources when the browser isn't busy and skips prefetching if your connection is offline or if you only have 2g connection.
|
|
148
148
|
|
|
149
|
-
```vue [pages/index.vue]
|
|
149
|
+
```vue [app/pages/index.vue]
|
|
150
150
|
<NuxtLink to="/about" no-prefetch>About page not pre-fetched</NuxtLink>
|
|
151
151
|
<NuxtLink to="/about" :prefetch="false">About page not pre-fetched</NuxtLink>
|
|
152
152
|
```
|
|
@@ -286,7 +286,7 @@ export default defineNuxtConfig({
|
|
|
286
286
|
|
|
287
287
|
You can overwrite `<NuxtLink>` defaults by creating your own link component using `defineNuxtLink`.
|
|
288
288
|
|
|
289
|
-
```js [components/MyNuxtLink.ts]
|
|
289
|
+
```js [app/components/MyNuxtLink.ts]
|
|
290
290
|
export default defineNuxtLink({
|
|
291
291
|
componentName: 'MyNuxtLink',
|
|
292
292
|
/* see signature below for more */
|
|
@@ -10,9 +10,9 @@ links:
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`layouts/`](/docs/guide/directory-structure/layouts).
|
|
13
|
+
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`app/layouts/`](/docs/guide/directory-structure/app/layouts).
|
|
14
14
|
|
|
15
|
-
```vue [app.vue]
|
|
15
|
+
```vue [app/app.vue]
|
|
16
16
|
<template>
|
|
17
17
|
<NuxtLoadingIndicator />
|
|
18
18
|
<NuxtLayout>
|
|
@@ -16,7 +16,7 @@ Within your pages, components, and plugins you can use useAsyncData to get acces
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
```vue [pages/index.vue]
|
|
19
|
+
```vue [app/pages/index.vue]
|
|
20
20
|
<script setup lang="ts">
|
|
21
21
|
const { data, status, error, refresh, clear } = await useAsyncData(
|
|
22
22
|
'mountains',
|
|
@@ -37,7 +37,7 @@ If you're using a custom useAsyncData wrapper, do not await it in the composable
|
|
|
37
37
|
|
|
38
38
|
The built-in `watch` option allows automatically rerunning the fetcher function when any changes are detected.
|
|
39
39
|
|
|
40
|
-
```vue [pages/index.vue]
|
|
40
|
+
```vue [app/pages/index.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
42
42
|
const page = ref(1)
|
|
43
43
|
const { data: posts } = await useAsyncData(
|
|
@@ -57,7 +57,7 @@ const { data: posts } = await useAsyncData(
|
|
|
57
57
|
|
|
58
58
|
You can use a computed ref, plain ref or a getter function as the key, allowing for dynamic data fetching that automatically updates when the key changes:
|
|
59
59
|
|
|
60
|
-
```vue [pages/[id\\].vue]
|
|
60
|
+
```vue [app/pages/[id\\].vue]
|
|
61
61
|
<script setup lang="ts">
|
|
62
62
|
const route = useRoute()
|
|
63
63
|
const userId = computed(() => `user-${route.params.id}`)
|
|
@@ -80,7 +80,7 @@ Returns a Vue `Ref<T>` representing the cookie value. Updating the ref will upda
|
|
|
80
80
|
|
|
81
81
|
The example below creates a cookie called `counter`. If the cookie doesn't exist, it is initially set to a random value. Whenever we update the `counter` variable, the cookie will be updated accordingly.
|
|
82
82
|
|
|
83
|
-
```vue [app.vue]
|
|
83
|
+
```vue [app/app.vue]
|
|
84
84
|
<script setup lang="ts">
|
|
85
85
|
const counter = useCookie('counter')
|
|
86
86
|
|
|
@@ -17,7 +17,7 @@ It automatically generates a key based on URL and fetch options, provides type h
|
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
|
-
```vue [pages/modules.vue]
|
|
20
|
+
```vue [app/pages/modules.vue]
|
|
21
21
|
<script setup lang="ts">
|
|
22
22
|
const { data, status, error, refresh, clear } = await useFetch('/api/modules', {
|
|
23
23
|
pick: ['title']
|
|
@@ -70,7 +70,7 @@ const { data, status, error, refresh, clear } = await useFetch('/api/auth/login'
|
|
|
70
70
|
|
|
71
71
|
You can use a computed ref or a plain ref as the URL, allowing for dynamic data fetching that automatically updates when the URL changes:
|
|
72
72
|
|
|
73
|
-
```vue [pages/[id\\].vue]
|
|
73
|
+
```vue [app/pages/[id\\].vue]
|
|
74
74
|
<script setup lang="ts">
|
|
75
75
|
const route = useRoute()
|
|
76
76
|
const id = computed(() => route.params.id)
|
|
@@ -20,7 +20,7 @@ By default, [`useAsyncData`](/docs/api/composables/use-async-data) blocks naviga
|
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
|
-
```vue [pages/index.vue]
|
|
23
|
+
```vue [app/pages/index.vue]
|
|
24
24
|
<script setup lang="ts">
|
|
25
25
|
/* Navigation will occur before fetching is complete.
|
|
26
26
|
Handle 'pending' and 'error' states directly within your component's template
|
|
@@ -24,7 +24,7 @@ Awaiting `useLazyFetch` in this mode only ensures the call is initialized. On cl
|
|
|
24
24
|
|
|
25
25
|
## Example
|
|
26
26
|
|
|
27
|
-
```vue [pages/index.vue]
|
|
27
|
+
```vue [app/pages/index.vue]
|
|
28
28
|
<script setup lang="ts">
|
|
29
29
|
/* Navigation will occur before fetching is complete.
|
|
30
30
|
* Handle 'pending' and 'error' states directly within your component's template
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
`useNuxtApp` is a built-in composable that provides a way to access shared runtime context of Nuxt, also known as the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context), which is available on both client and server side (but not within Nitro routes). It helps you access the Vue app instance, runtime hooks, runtime config variables and internal states, such as `ssrContext` and `payload`.
|
|
12
12
|
|
|
13
|
-
```vue [app.vue]
|
|
13
|
+
```vue [app/app.vue]
|
|
14
14
|
<script setup lang="ts">
|
|
15
15
|
const nuxtApp = useNuxtApp()
|
|
16
16
|
</script>
|
|
@@ -52,7 +52,7 @@ Hooks available in `nuxtApp` allows you to customize the runtime aspects of your
|
|
|
52
52
|
|
|
53
53
|
See [Runtime Hooks](/docs/api/advanced/hooks#app-hooks-runtime) for available runtime hooks called by Nuxt.
|
|
54
54
|
|
|
55
|
-
```ts [plugins/test.ts]
|
|
55
|
+
```ts [app/plugins/test.ts]
|
|
56
56
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
57
57
|
nuxtApp.hook('page:start', () => {
|
|
58
58
|
/* your code goes here */
|
|
@@ -106,7 +106,7 @@ Nuxt exposes the following properties through `ssrContext`:
|
|
|
106
106
|
- `data` (object) - When you fetch the data from an API endpoint using either [`useFetch`](/docs/api/composables/use-fetch) or [`useAsyncData`](/docs/api/composables/use-async-data) , resulting payload can be accessed from the `payload.data`. This data is cached and helps you prevent fetching the same data in case an identical request is made more than once.
|
|
107
107
|
|
|
108
108
|
::code-group
|
|
109
|
-
```vue [app.vue]
|
|
109
|
+
```vue [app/app.vue]
|
|
110
110
|
<script setup lang="ts">
|
|
111
111
|
const { data } = await useAsyncData('count', () => $fetch('/api/count'))
|
|
112
112
|
</script>
|
|
@@ -124,7 +124,7 @@ Nuxt exposes the following properties through `ssrContext`:
|
|
|
124
124
|
|
|
125
125
|
- `state` (object) - When you use [`useState`](/docs/api/composables/use-state) composable in Nuxt to set shared state, this state data is accessed through `payload.state.[name-of-your-state]`.
|
|
126
126
|
|
|
127
|
-
```ts [plugins/my-plugin.ts]
|
|
127
|
+
```ts [app/plugins/my-plugin.ts]
|
|
128
128
|
export const useColor = () => useState<string>('color', () => 'pink')
|
|
129
129
|
|
|
130
130
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -142,7 +142,7 @@ Nuxt exposes the following properties through `ssrContext`:
|
|
|
142
142
|
|
|
143
143
|
In the example below, we define a reducer (or a serializer) and a reviver (or deserializer) for the [Luxon](https://moment.github.io/luxon/#/) DateTime class, using a payload plugin.
|
|
144
144
|
|
|
145
|
-
```ts [plugins/date-time-payload.ts]
|
|
145
|
+
```ts [app/plugins/date-time-payload.ts]
|
|
146
146
|
/**
|
|
147
147
|
* This kind of plugin runs very early in the Nuxt lifecycle, before we revive the payload.
|
|
148
148
|
* You will not have access to the router or other Nuxt-injected properties.
|
|
@@ -164,7 +164,7 @@ Nuxt exposes the following properties through `ssrContext`:
|
|
|
164
164
|
|
|
165
165
|
Use `nuxtApp.isHydrating` (boolean) to check if the Nuxt app is hydrating on the client side.
|
|
166
166
|
|
|
167
|
-
```ts [components/nuxt-error-boundary.ts]
|
|
167
|
+
```ts [app/components/nuxt-error-boundary.ts]
|
|
168
168
|
export default defineComponent({
|
|
169
169
|
setup (_props, { slots, emit }) {
|
|
170
170
|
const nuxtApp = useNuxtApp()
|
|
@@ -185,7 +185,7 @@ You are likely here because you got a "Nuxt instance unavailable" message. Pleas
|
|
|
185
185
|
|
|
186
186
|
The `runWithContext` method is meant to be used to call a function and give it an explicit Nuxt context. Typically, the Nuxt context is passed around implicitly and you do not need to worry about this. However, when working with complex `async`/`await` scenarios in middleware/plugins, you can run into instances where the current instance has been unset after an async call.
|
|
187
187
|
|
|
188
|
-
```ts [middleware/auth.ts]
|
|
188
|
+
```ts [app/middleware/auth.ts]
|
|
189
189
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
190
190
|
const nuxtApp = useNuxtApp()
|
|
191
191
|
let user
|
|
@@ -34,14 +34,14 @@ To use `useNuxtData`, ensure that the data-fetching composable (`useFetch`, `use
|
|
|
34
34
|
|
|
35
35
|
The example below shows how you can use cached data as a placeholder while the most recent data is being fetched from the server.
|
|
36
36
|
|
|
37
|
-
```vue [pages/posts.vue]
|
|
37
|
+
```vue [app/pages/posts.vue]
|
|
38
38
|
<script setup lang="ts">
|
|
39
39
|
// We can access same data later using 'posts' key
|
|
40
40
|
const { data } = await useFetch('/api/posts', { key: 'posts' })
|
|
41
41
|
</script>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
```vue [pages/posts/[id\\].vue]
|
|
44
|
+
```vue [app/pages/posts/[id\\].vue]
|
|
45
45
|
<script setup lang="ts">
|
|
46
46
|
// Access to the cached value of useFetch in posts.vue (parent route)
|
|
47
47
|
const { data: posts } = useNuxtData('posts')
|
|
@@ -64,14 +64,14 @@ The example below shows how implementing Optimistic Updates can be achieved usin
|
|
|
64
64
|
|
|
65
65
|
Optimistic Updates is a technique where the user interface is updated immediately, assuming a server operation will succeed. If the operation eventually fails, the UI is rolled back to its previous state.
|
|
66
66
|
|
|
67
|
-
```vue [pages/todos.vue]
|
|
67
|
+
```vue [app/pages/todos.vue]
|
|
68
68
|
<script setup lang="ts">
|
|
69
69
|
// We can access same data later using 'todos' key
|
|
70
70
|
const { data } = await useAsyncData('todos', () => $fetch('/api/todos'))
|
|
71
71
|
</script>
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
```vue [components/NewTodo.vue]
|
|
74
|
+
```vue [app/components/NewTodo.vue]
|
|
75
75
|
<script setup lang="ts">
|
|
76
76
|
const newTodo = ref('')
|
|
77
77
|
let previousTodos = []
|
|
@@ -75,7 +75,7 @@ const { enabled, state } = usePreviewMode({
|
|
|
75
75
|
|
|
76
76
|
The example below creates a page where part of a content is rendered only in preview mode.
|
|
77
77
|
|
|
78
|
-
```vue [pages/some-page.vue]
|
|
78
|
+
```vue [app/pages/some-page.vue]
|
|
79
79
|
<script setup>
|
|
80
80
|
const { enabled, state } = usePreviewMode()
|
|
81
81
|
|
|
@@ -24,7 +24,7 @@ The [`useFetch`](/docs/api/composables/use-fetch) composable uses `useRequestFet
|
|
|
24
24
|
|
|
25
25
|
::code-group
|
|
26
26
|
|
|
27
|
-
```vue [pages/index.vue]
|
|
27
|
+
```vue [app/pages/index.vue]
|
|
28
28
|
<script setup lang="ts">
|
|
29
29
|
// This will forward the user's headers to the `/api/cookies` event handler
|
|
30
30
|
// Result: { cookies: { foo: 'bar' } }
|
|
@@ -25,7 +25,7 @@ We can use `useRequestHeader` to easily figure out if a user is authorized or no
|
|
|
25
25
|
|
|
26
26
|
The example below reads the `authorization` request header to find out if a person can access a restricted resource.
|
|
27
27
|
|
|
28
|
-
```ts [middleware/authorized-only.ts]
|
|
28
|
+
```ts [app/middleware/authorized-only.ts]
|
|
29
29
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
30
30
|
if (!useRequestHeader('authorization')) {
|
|
31
31
|
return navigateTo('/not-authorized')
|
|
@@ -28,7 +28,7 @@ We can use `useRequestHeaders` to access and proxy the initial request's `author
|
|
|
28
28
|
|
|
29
29
|
The example below adds the `authorization` request header to an isomorphic `$fetch` call.
|
|
30
30
|
|
|
31
|
-
```vue [pages/some-page.vue]
|
|
31
|
+
```vue [app/pages/some-page.vue]
|
|
32
32
|
<script setup lang="ts">
|
|
33
33
|
const { data } = await useFetch('/api/confidential', {
|
|
34
34
|
headers: useRequestHeaders(['authorization'])
|
|
@@ -24,7 +24,7 @@ header.value = 'my-value';
|
|
|
24
24
|
|
|
25
25
|
We can use `useResponseHeader` to easily set a response header on a per-page basis.
|
|
26
26
|
|
|
27
|
-
```vue [pages/test.vue]
|
|
27
|
+
```vue [app/pages/test.vue]
|
|
28
28
|
<script setup>
|
|
29
29
|
// pages/test.vue
|
|
30
30
|
const header = useResponseHeader('X-My-Header');
|
|
@@ -37,9 +37,9 @@ header.value = 'my-value';
|
|
|
37
37
|
</template>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/guide/directory-structure/middleware) to set a response header for all pages.
|
|
40
|
+
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/guide/directory-structure/app/middleware) to set a response header for all pages.
|
|
41
41
|
|
|
42
|
-
```ts [middleware/my-header-middleware.ts]
|
|
42
|
+
```ts [app/middleware/my-header-middleware.ts]
|
|
43
43
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
44
44
|
const header = useResponseHeader('X-My-Always-Header');
|
|
45
45
|
header.value = `I'm Always here!`;
|
|
@@ -51,7 +51,7 @@ Sets the message with `politeness = "assertive"`
|
|
|
51
51
|
|
|
52
52
|
## Example
|
|
53
53
|
|
|
54
|
-
```vue [pages/index.vue]
|
|
54
|
+
```vue [app/pages/index.vue]
|
|
55
55
|
<script setup lang="ts">
|
|
56
56
|
const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
|
|
57
57
|
politeness: 'assertive'
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
```vue [pages/index.vue]
|
|
11
|
+
```vue [app/pages/index.vue]
|
|
12
12
|
<script setup lang="ts">
|
|
13
13
|
const router = useRouter()
|
|
14
14
|
</script>
|
|
@@ -16,13 +16,13 @@ const router = useRouter()
|
|
|
16
16
|
|
|
17
17
|
If you only need the router instance within your template, use `$router`:
|
|
18
18
|
|
|
19
|
-
```vue [pages/index.vue]
|
|
19
|
+
```vue [app/pages/index.vue]
|
|
20
20
|
<template>
|
|
21
21
|
<button @click="$router.back()">Back</button>
|
|
22
22
|
</template>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
If you have a `pages/` directory, `useRouter` is identical in behavior to the one provided by `vue-router`.
|
|
25
|
+
If you have a `app/pages/` directory, `useRouter` is identical in behavior to the one provided by `vue-router`.
|
|
26
26
|
|
|
27
27
|
::read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/interfaces/Router.html#Properties-currentRoute" target="_blank"}
|
|
28
28
|
Read `vue-router` documentation about the `Router` interface.
|
|
@@ -78,7 +78,7 @@ Read more about the browser's History API.
|
|
|
78
78
|
|
|
79
79
|
However, Nuxt has a concept of **route middleware** that simplifies the implementation of navigation guards and provides a better developer experience.
|
|
80
80
|
|
|
81
|
-
:read-more{to="/docs/guide/directory-structure/middleware"}
|
|
81
|
+
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
82
82
|
|
|
83
83
|
## Promise and Error Handling
|
|
84
84
|
|
|
@@ -89,4 +89,4 @@ However, Nuxt has a concept of **route middleware** that simplifies the implemen
|
|
|
89
89
|
|
|
90
90
|
## Universal Router Instance
|
|
91
91
|
|
|
92
|
-
If you do not have a `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`.
|
|
92
|
+
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`.
|
|
@@ -18,7 +18,7 @@ This is the recommended way to add meta tags to your site as it is XSS safe and
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
```vue [app.vue]
|
|
21
|
+
```vue [app/app.vue]
|
|
22
22
|
<script setup lang="ts">
|
|
23
23
|
useSeoMeta({
|
|
24
24
|
title: 'My Amazing Site',
|
|
@@ -33,7 +33,7 @@ useSeoMeta({
|
|
|
33
33
|
|
|
34
34
|
When inserting tags that are reactive, you should use the computed getter syntax (`() => value`):
|
|
35
35
|
|
|
36
|
-
```vue [app.vue]
|
|
36
|
+
```vue [app/app.vue]
|
|
37
37
|
<script setup lang="ts">
|
|
38
38
|
const title = ref('My title')
|
|
39
39
|
|
|
@@ -56,7 +56,7 @@ In most instances, SEO meta tags don't need to be reactive as search engine robo
|
|
|
56
56
|
|
|
57
57
|
For better performance, you can wrap your `useSeoMeta` calls in a server-only condition when the meta tags don't need to be reactive:
|
|
58
58
|
|
|
59
|
-
```vue [app.vue]
|
|
59
|
+
```vue [app/app.vue]
|
|
60
60
|
<script setup lang="ts">
|
|
61
61
|
if (import.meta.server) {
|
|
62
62
|
// These meta tags will only be added during server-side rendering
|
|
@@ -14,7 +14,7 @@ Just like [`useSeoMeta`](/docs/api/composables/use-seo-meta), `useServerSeoMeta`
|
|
|
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/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
|
-
```vue [app.vue]
|
|
17
|
+
```vue [app/app.vue]
|
|
18
18
|
<script setup lang="ts">
|
|
19
19
|
useServerSeoMeta({
|
|
20
20
|
robots: 'index, follow'
|