@nuxt/docs 4.1.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +6 -6
- package/1.getting-started/02.installation.md +3 -2
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +241 -110
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +334 -85
- package/2.guide/3.going-further/1.features.md +58 -11
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +126 -108
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +76 -59
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +45 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +49 -18
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +26 -22
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +62 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +123 -37
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +66 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +61 -4
- package/3.api/5.kit/15.examples.md +5 -7
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +8 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.head.md +132 -0
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +365 -859
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +3 -3
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +2 -2
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -12,9 +12,9 @@ links:
|
|
|
12
12
|
|
|
13
13
|
Preview mode allows you to see how your changes would be displayed on a live site without revealing them to users.
|
|
14
14
|
|
|
15
|
-
You can use the built-in `usePreviewMode` composable to access and control preview state in Nuxt. If the composable detects preview mode it will automatically force any updates necessary for [`useAsyncData`](/docs/api/composables/use-async-data) and [`useFetch`](/docs/api/composables/use-fetch) to rerender preview content.
|
|
15
|
+
You can use the built-in `usePreviewMode` composable to access and control preview state in Nuxt. If the composable detects preview mode it will automatically force any updates necessary for [`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`useFetch`](/docs/4.x/api/composables/use-fetch) to rerender preview content.
|
|
16
16
|
|
|
17
|
-
```
|
|
17
|
+
```ts
|
|
18
18
|
const { enabled, state } = usePreviewMode()
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -24,27 +24,28 @@ const { enabled, state } = usePreviewMode()
|
|
|
24
24
|
|
|
25
25
|
You can specify a custom way to enable preview mode. By default the `usePreviewMode` composable will enable preview mode if there is a `preview` param in url that is equal to `true` (for example, `http://localhost:3000?preview=true`). You can wrap the `usePreviewMode` into custom composable, to keep options consistent across usages and prevent any errors.
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```ts
|
|
28
28
|
export function useMyPreviewMode () {
|
|
29
|
+
const route = useRoute()
|
|
29
30
|
return usePreviewMode({
|
|
30
31
|
shouldEnable: () => {
|
|
31
32
|
return !!route.query.customPreview
|
|
32
|
-
}
|
|
33
|
-
})
|
|
33
|
+
},
|
|
34
|
+
})
|
|
34
35
|
}
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
### Modify default state
|
|
38
39
|
|
|
39
|
-
`usePreviewMode` will try to store the value of a `token` param from url in state. You can modify this state and it will be available for all [`usePreviewMode`](/docs/api/composables/use-preview-mode) calls.
|
|
40
|
+
`usePreviewMode` will try to store the value of a `token` param from url in state. You can modify this state and it will be available for all [`usePreviewMode`](/docs/4.x/api/composables/use-preview-mode) calls.
|
|
40
41
|
|
|
41
|
-
```
|
|
42
|
+
```ts
|
|
42
43
|
const data1 = ref('data1')
|
|
43
44
|
|
|
44
45
|
const { enabled, state } = usePreviewMode({
|
|
45
46
|
getState: (currentState) => {
|
|
46
47
|
return { data1, data2: 'data2' }
|
|
47
|
-
}
|
|
48
|
+
},
|
|
48
49
|
})
|
|
49
50
|
```
|
|
50
51
|
|
|
@@ -60,14 +61,14 @@ When preview mode is disabled, the composable will attach a callback to call `re
|
|
|
60
61
|
|
|
61
62
|
You can specify custom callbacks to be triggered by providing your own functions for the `onEnable` and `onDisable` options.
|
|
62
63
|
|
|
63
|
-
```
|
|
64
|
+
```ts
|
|
64
65
|
const { enabled, state } = usePreviewMode({
|
|
65
66
|
onEnable: () => {
|
|
66
67
|
console.log('preview mode has been enabled')
|
|
67
68
|
},
|
|
68
69
|
onDisable: () => {
|
|
69
70
|
console.log('preview mode has been disabled')
|
|
70
|
-
}
|
|
71
|
+
},
|
|
71
72
|
})
|
|
72
73
|
```
|
|
73
74
|
|
|
@@ -81,8 +82,8 @@ const { enabled, state } = usePreviewMode()
|
|
|
81
82
|
|
|
82
83
|
const { data } = await useFetch('/api/preview', {
|
|
83
84
|
query: {
|
|
84
|
-
apiKey: state.token
|
|
85
|
-
}
|
|
85
|
+
apiKey: state.token,
|
|
86
|
+
},
|
|
86
87
|
})
|
|
87
88
|
</script>
|
|
88
89
|
|
|
@@ -107,12 +108,8 @@ npx nuxt generate
|
|
|
107
108
|
npx nuxt preview
|
|
108
109
|
```
|
|
109
110
|
|
|
110
|
-
Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once:
|
|
111
|
-
|
|
112
|
-
```js
|
|
113
|
-
?preview=true
|
|
114
|
-
```
|
|
111
|
+
Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once, for example `http://localhost:3000/?preview=true`.
|
|
115
112
|
|
|
116
113
|
::note
|
|
117
|
-
`usePreviewMode` should be tested locally with `nuxt generate` and then `nuxt preview` rather than `nuxt dev`. (The [preview command](/docs/api/commands/preview) is not related to preview mode.)
|
|
114
|
+
`usePreviewMode` should be tested locally with `nuxt generate` and then `nuxt preview` rather than `nuxt dev`. (The [preview command](/docs/4.x/api/commands/preview) is not related to preview mode.)
|
|
118
115
|
::
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) you can use `useRequestEvent` to access the incoming request.
|
|
11
|
+
Within the [Nuxt context](/docs/4.x/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
|
|
@@ -19,7 +19,7 @@ Headers that are **not meant to be forwarded** will **not be included** in the r
|
|
|
19
19
|
::
|
|
20
20
|
|
|
21
21
|
::tip
|
|
22
|
-
The [`useFetch`](/docs/api/composables/use-fetch) composable uses `useRequestFetch` under the hood to automatically forward the request context and headers.
|
|
22
|
+
The [`useFetch`](/docs/4.x/api/composables/use-fetch) composable uses `useRequestFetch` under the hood to automatically forward the request context and headers.
|
|
23
23
|
::
|
|
24
24
|
|
|
25
25
|
::code-group
|
|
@@ -33,7 +33,7 @@ const { data: forwarded } = await useAsyncData(() => requestFetch('/api/cookies'
|
|
|
33
33
|
|
|
34
34
|
// This will NOT forward anything
|
|
35
35
|
// Result: { cookies: {} }
|
|
36
|
-
const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
|
|
36
|
+
const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
|
|
37
37
|
</script>
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -48,5 +48,5 @@ export default defineEventHandler((event) => {
|
|
|
48
48
|
::
|
|
49
49
|
|
|
50
50
|
::tip
|
|
51
|
-
In the browser during client-side navigation, `useRequestFetch` will behave just like regular [`$fetch`](/docs/api/utils/dollarfetch).
|
|
51
|
+
In the browser during client-side navigation, `useRequestFetch` will behave just like regular [`$fetch`](/docs/4.x/api/utils/dollarfetch).
|
|
52
52
|
::
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
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.
|
|
11
|
+
You can use the built-in [`useRequestHeader`](/docs/4.x/api/composables/use-request-header) composable to access any incoming request header within your pages, components, and plugins.
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
// Get the authorization request header
|
|
@@ -8,14 +8,14 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
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.
|
|
11
|
+
You can use built-in [`useRequestHeaders`](/docs/4.x/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
|
|
15
15
|
const headers = useRequestHeaders()
|
|
16
16
|
|
|
17
17
|
// Get only cookie request header
|
|
18
|
-
const
|
|
18
|
+
const { cookie } = useRequestHeaders(['cookie'])
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
::tip
|
|
@@ -31,7 +31,7 @@ The example below adds the `authorization` request header to an isomorphic `$fet
|
|
|
31
31
|
```vue [app/pages/some-page.vue]
|
|
32
32
|
<script setup lang="ts">
|
|
33
33
|
const { data } = await useFetch('/api/confidential', {
|
|
34
|
-
headers: useRequestHeaders(['authorization'])
|
|
34
|
+
headers: useRequestHeaders(['authorization']),
|
|
35
35
|
})
|
|
36
36
|
</script>
|
|
37
37
|
```
|
|
@@ -11,7 +11,7 @@ links:
|
|
|
11
11
|
`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.
|
|
12
12
|
|
|
13
13
|
::important
|
|
14
|
-
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`).
|
|
14
|
+
When utilizing [Hybrid Rendering](/docs/4.x/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`).
|
|
15
15
|
|
|
16
16
|
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.
|
|
17
17
|
::
|
|
@@ -12,12 +12,12 @@ links:
|
|
|
12
12
|
This composable is available in Nuxt v3.14+.
|
|
13
13
|
::
|
|
14
14
|
|
|
15
|
-
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.
|
|
15
|
+
You can use the built-in [`useResponseHeader`](/docs/4.x/api/composables/use-response-header) composable to set any server response header within your pages, components, and plugins.
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
// Set a custom response header
|
|
19
|
-
const header = useResponseHeader('X-My-Header')
|
|
20
|
-
header.value = 'my-value'
|
|
19
|
+
const header = useResponseHeader('X-My-Header')
|
|
20
|
+
header.value = 'my-value'
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Example
|
|
@@ -27,8 +27,8 @@ We can use `useResponseHeader` to easily set a response header on a per-page bas
|
|
|
27
27
|
```vue [app/pages/test.vue]
|
|
28
28
|
<script setup>
|
|
29
29
|
// pages/test.vue
|
|
30
|
-
const header = useResponseHeader('X-My-Header')
|
|
31
|
-
header.value = 'my-value'
|
|
30
|
+
const header = useResponseHeader('X-My-Header')
|
|
31
|
+
header.value = 'my-value'
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
34
|
<template>
|
|
@@ -37,12 +37,11 @@ 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/app/middleware) to set a response header for all pages.
|
|
40
|
+
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/4.x/guide/directory-structure/app/middleware) to set a response header for all pages.
|
|
41
41
|
|
|
42
42
|
```ts [app/middleware/my-header-middleware.ts]
|
|
43
43
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
44
|
-
const header = useResponseHeader('X-My-Always-Header')
|
|
45
|
-
header.value = `I'm Always here
|
|
46
|
-
})
|
|
47
|
-
|
|
44
|
+
const header = useResponseHeader('X-My-Always-Header')
|
|
45
|
+
header.value = `I'm Always here!`
|
|
46
|
+
})
|
|
48
47
|
```
|
|
@@ -16,7 +16,7 @@ This composable is available in Nuxt v3.12+.
|
|
|
16
16
|
|
|
17
17
|
## Description
|
|
18
18
|
|
|
19
|
-
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
|
+
A composable which observes the page title changes and updates the announcer message accordingly. Used by [`<NuxtRouteAnnouncer>`](/docs/4.x/api/components/nuxt-route-announcer) and controllable.
|
|
20
20
|
It hooks into Unhead's [`dom:rendered`](https://unhead.unjs.io/docs/typescript/head/api/hooks/dom-rendered) to read the page's title and set it as the announcer message.
|
|
21
21
|
|
|
22
22
|
## Parameters
|
|
@@ -53,8 +53,8 @@ Sets the message with `politeness = "assertive"`
|
|
|
53
53
|
|
|
54
54
|
```vue [app/pages/index.vue]
|
|
55
55
|
<script setup lang="ts">
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
|
|
57
|
+
politeness: 'assertive',
|
|
58
|
+
})
|
|
59
59
|
</script>
|
|
60
60
|
```
|
|
@@ -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/api/composables/use-fetch) using a dynamic page parameter - `slug` - as part of the URL.
|
|
23
|
+
In the following example, we call an API via [`useFetch`](/docs/4.x/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">
|
|
@@ -18,7 +18,9 @@ If you only need the router instance within your template, use `$router`:
|
|
|
18
18
|
|
|
19
19
|
```vue [app/pages/index.vue]
|
|
20
20
|
<template>
|
|
21
|
-
<button @click="$router.back()">
|
|
21
|
+
<button @click="$router.back()">
|
|
22
|
+
Back
|
|
23
|
+
</button>
|
|
22
24
|
</template>
|
|
23
25
|
```
|
|
24
26
|
|
|
@@ -47,7 +49,7 @@ router.resolve({ name: 'home' })
|
|
|
47
49
|
```
|
|
48
50
|
|
|
49
51
|
::note
|
|
50
|
-
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/guide/directory-structure/plugins) while `router.push()` on the other hand, triggers a new navigation immediately and it is useful in pages, Vue components and composable.
|
|
52
|
+
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/4.x/guide/directory-structure/plugins) while `router.push()` on the other hand, triggers a new navigation immediately and it is useful in pages, Vue components and composable.
|
|
51
53
|
::
|
|
52
54
|
|
|
53
55
|
## Based on History API
|
|
@@ -55,8 +57,8 @@ router.resolve({ name: 'home' })
|
|
|
55
57
|
- [`back()`](https://router.vuejs.org/api/interfaces/Router.html#back): Go back in history if possible, same as `router.go(-1)`.
|
|
56
58
|
- [`forward()`](https://router.vuejs.org/api/interfaces/Router.html#forward): Go forward in history if possible, same as `router.go(1)`.
|
|
57
59
|
- [`go()`](https://router.vuejs.org/api/interfaces/Router.html#go): Move forward or backward through the history without the hierarchical restrictions enforced in `router.back()` and `router.forward()`.
|
|
58
|
-
- [`push()`](https://router.vuejs.org/api/interfaces/Router.html#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.**
|
|
59
|
-
- [`replace()`](https://router.vuejs.org/api/interfaces/Router.html#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.**
|
|
60
|
+
- [`push()`](https://router.vuejs.org/api/interfaces/Router.html#push): Programmatically navigate to a new URL by pushing an entry in the history stack. **It is recommended to use [`navigateTo`](/docs/4.x/api/utils/navigate-to) instead.**
|
|
61
|
+
- [`replace()`](https://router.vuejs.org/api/interfaces/Router.html#replace): Programmatically navigate to a new URL by replacing the current entry in the routes history stack. **It is recommended to use [`navigateTo`](/docs/4.x/api/utils/navigate-to) instead.**
|
|
60
62
|
|
|
61
63
|
```ts [Example]
|
|
62
64
|
const router = useRouter()
|
|
@@ -64,8 +66,8 @@ const router = useRouter()
|
|
|
64
66
|
router.back()
|
|
65
67
|
router.forward()
|
|
66
68
|
router.go(3)
|
|
67
|
-
router.push({ path:
|
|
68
|
-
router.replace({ hash:
|
|
69
|
+
router.push({ path: '/home' })
|
|
70
|
+
router.replace({ hash: '#bio' })
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/History" target="_blank"}
|
|
@@ -78,7 +80,7 @@ Read more about the browser's History API.
|
|
|
78
80
|
|
|
79
81
|
However, Nuxt has a concept of **route middleware** that simplifies the implementation of navigation guards and provides a better developer experience.
|
|
80
82
|
|
|
81
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
83
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
|
|
82
84
|
|
|
83
85
|
## Promise and Error Handling
|
|
84
86
|
|
|
@@ -89,4 +91,4 @@ However, Nuxt has a concept of **route middleware** that simplifies the implemen
|
|
|
89
91
|
|
|
90
92
|
## Universal Router Instance
|
|
91
93
|
|
|
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`.
|
|
94
|
+
If you do not have a `app/pages/` folder, then [`useRouter`](/docs/4.x/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/guide/going-further/runtime-config"}
|
|
25
|
+
:read-more{to="/docs/4.x/guide/going-further/runtime-config"}
|
|
26
26
|
|
|
27
27
|
## Define Runtime Config
|
|
28
28
|
|
|
@@ -38,9 +38,9 @@ export default defineNuxtConfig({
|
|
|
38
38
|
|
|
39
39
|
// Public keys that are exposed to the client
|
|
40
40
|
public: {
|
|
41
|
-
apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api'
|
|
42
|
-
}
|
|
43
|
-
}
|
|
41
|
+
apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
44
|
})
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -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/guide/going-further/runtime-config"}
|
|
51
|
+
:read-more{to="/docs/4.x/guide/going-further/runtime-config"}
|
|
52
52
|
|
|
53
53
|
## Access Runtime Config
|
|
54
54
|
|
|
@@ -63,11 +63,11 @@ export default defineEventHandler(async (event) => {
|
|
|
63
63
|
baseURL: config.public.apiBase,
|
|
64
64
|
headers: {
|
|
65
65
|
// Access a private variable (only available on the server)
|
|
66
|
-
Authorization: `Bearer ${config.apiSecret}
|
|
67
|
-
}
|
|
66
|
+
Authorization: `Bearer ${config.apiSecret}`,
|
|
67
|
+
},
|
|
68
68
|
})
|
|
69
69
|
return result
|
|
70
|
-
}
|
|
70
|
+
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
In this example, since `apiBase` is defined within the `public` namespace, it is universally accessible on both server and client-side, while `apiSecret` **is only accessible on the server-side**.
|
|
@@ -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/guide/going-further/runtime-config"}
|
|
79
|
+
:read-more{to="/docs/4.x/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/guide/directory-structure/env"}
|
|
98
|
+
:read-more{to="/docs/4.x/guide/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/guide/going-further/runtime-config"}
|
|
142
|
+
:read-more{to="/docs/4.x/guide/going-further/runtime-config"}
|
|
@@ -13,7 +13,7 @@ This composable is available in Nuxt v3.14+.
|
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
```ts [signature]
|
|
16
|
-
function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(
|
|
16
|
+
function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> (
|
|
17
17
|
name: THookName,
|
|
18
18
|
fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never
|
|
19
19
|
): void
|
|
@@ -23,7 +23,7 @@ function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(
|
|
|
23
23
|
|
|
24
24
|
### Parameters
|
|
25
25
|
|
|
26
|
-
- `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).
|
|
26
|
+
- `name`: The name of the runtime hook to register. You can see the full list of [runtime Nuxt hooks here](/docs/4.x/api/advanced/hooks#app-hooks-runtime).
|
|
27
27
|
- `fn`: The callback function to execute when the hook is triggered. The function signature varies based on the hook name.
|
|
28
28
|
|
|
29
29
|
### Returns
|
|
@@ -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/getting-started/seo-meta"}
|
|
17
|
+
:read-more{to="/docs/4.x/getting-started/seo-meta"}
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ const title = ref('My title')
|
|
|
39
39
|
|
|
40
40
|
useSeoMeta({
|
|
41
41
|
title,
|
|
42
|
-
description: () => `This is a description for the ${title.value} page
|
|
42
|
+
description: () => `This is a description for the ${title.value} page`,
|
|
43
43
|
})
|
|
44
44
|
</script>
|
|
45
45
|
```
|
|
@@ -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/getting-started/seo-meta"}
|
|
51
|
+
:read-more{to="/docs/4.x/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/api/composables/use-server-seo-meta) composable, but it has been deprecated in favor of this approach.
|
|
80
|
+
This previously used the [`useServerSeoMeta`](/docs/4.x/api/composables/use-server-seo-meta) composable, but it has been deprecated in favor of this approach.
|
|
@@ -8,20 +8,20 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Just like [`useSeoMeta`](/docs/api/composables/use-seo-meta), `useServerSeoMeta` composable lets you define your site's SEO meta tags as a flat object with full TypeScript support.
|
|
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
|
-
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.
|
|
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
|
-
Parameters are exactly the same as with [`useSeoMeta`](/docs/api/composables/use-seo-meta)
|
|
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,11 +38,11 @@ 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
|
-
- `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.
|
|
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.
|
|
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
|
package/3.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/guide/directory-structure/server) will directly call the relevant function (emulating the request), **saving an additional API call**.
|
|
14
|
+
During server-side rendering, calling `$fetch` to fetch your internal [API routes](/docs/4.x/guide/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/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.
|
|
18
|
+
Using `$fetch` in components without wrapping it with [`useAsyncData`](/docs/4.x/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/api/composables/use-fetch) or [`useAsyncData`](/docs/api/composables/use-async-data) + `$fetch` to prevent double data fetching when fetching the component data.
|
|
23
|
+
We recommend using [`useFetch`](/docs/4.x/api/composables/use-fetch) or [`useAsyncData`](/docs/4.x/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,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
|
|
|
@@ -95,4 +97,4 @@ const { data } = await useAsyncData(() => requestFetch('/api/cookies'))
|
|
|
95
97
|
</script>
|
|
96
98
|
```
|
|
97
99
|
|
|
98
|
-
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`).
|
|
100
|
+
However, when calling `useFetch` with a relative URL on the server, Nuxt will use [`useRequestFetch`](/docs/4.x/api/composables/use-request-fetch) to proxy headers and cookies (with the exception of headers not meant to be forwarded, like `host`).
|
|
@@ -9,13 +9,13 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::warning
|
|
12
|
-
`abortNavigation` is only usable inside a [route middleware handler](/docs/guide/directory-structure/app/middleware).
|
|
12
|
+
`abortNavigation` is only usable inside a [route middleware handler](/docs/4.x/guide/directory-structure/app/middleware).
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
## Type
|
|
16
16
|
|
|
17
|
-
```ts
|
|
18
|
-
abortNavigation(err?: Error | string): false
|
|
17
|
+
```ts [Signature]
|
|
18
|
+
export function abortNavigation (err?: Error | string): false
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Parameters
|
|
@@ -9,7 +9,7 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::note
|
|
12
|
-
Route middleware are navigation guards stored in the [`app/middleware/`](/docs/guide/directory-structure/app/middleware) directory of your Nuxt application (unless [set otherwise](/docs/api/nuxt-config#middleware)).
|
|
12
|
+
Route middleware are navigation guards stored in the [`app/middleware/`](/docs/4.x/guide/directory-structure/app/middleware) directory of your Nuxt application (unless [set otherwise](/docs/4.x/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/api/composables/use-route).
|
|
34
|
+
Learn more about available properties of [route objects](/docs/4.x/api/composables/use-route).
|
|
35
35
|
|
|
36
36
|
### `middleware`
|
|
37
37
|
|
|
@@ -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,14 +54,14 @@ 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
|
-
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
|
+
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.
|
|
65
65
|
::
|
|
66
66
|
|
|
67
67
|
::note
|
|
@@ -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
|
|
|
@@ -24,6 +24,6 @@ clearError()
|
|
|
24
24
|
clearError({ redirect: '/homepage' })
|
|
25
25
|
```
|
|
26
26
|
|
|
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.
|
|
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"}
|