@nuxt/docs 3.17.2 → 4.0.0-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 +1 -1
- package/1.getting-started/02.installation.md +8 -0
- package/1.getting-started/03.configuration.md +1 -1
- package/1.getting-started/04.views.md +3 -1
- package/1.getting-started/06.styling.md +3 -1
- package/1.getting-started/10.data-fetching.md +2 -2
- package/1.getting-started/15.prerendering.md +2 -2
- package/1.getting-started/16.deployment.md +2 -2
- package/1.getting-started/17.testing.md +1 -1
- package/1.getting-started/18.upgrade.md +5 -4
- package/2.guide/1.concepts/3.rendering.md +2 -2
- package/2.guide/1.concepts/4.server-engine.md +1 -1
- package/2.guide/2.directory-structure/1.pages.md +4 -0
- package/2.guide/2.directory-structure/1.server.md +6 -6
- package/2.guide/3.going-further/1.events.md +1 -1
- package/2.guide/3.going-further/1.experimental-features.md +1 -53
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -3
- package/2.guide/3.going-further/3.modules.md +2 -2
- package/2.guide/4.recipes/4.sessions-and-authentication.md +1 -1
- package/3.api/2.composables/use-async-data.md +1 -1
- package/3.api/2.composables/use-fetch.md +1 -1
- package/3.api/2.composables/use-nuxt-data.md +1 -1
- package/3.api/2.composables/use-request-url.md +2 -2
- package/3.api/3.utils/navigate-to.md +1 -1
- package/3.api/5.kit/11.nitro.md +2 -2
- package/3.api/5.kit/7.pages.md +2 -2
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/package.json +1 -1
|
@@ -48,7 +48,7 @@ disable SSR globally with the `ssr: false` option or leverage hybrid rendering b
|
|
|
48
48
|
|
|
49
49
|
### Server engine
|
|
50
50
|
|
|
51
|
-
The Nuxt server engine [Nitro](https://nitro.
|
|
51
|
+
The Nuxt server engine [Nitro](https://nitro.build/) unlocks new full-stack capabilities.
|
|
52
52
|
|
|
53
53
|
In development, it uses Rollup and Node.js workers for your server code and context isolation. It also generates your server API by reading files in `server/api/` and server middleware from `server/middleware/`.
|
|
54
54
|
|
|
@@ -54,6 +54,10 @@ pnpm create nuxt <project-name>
|
|
|
54
54
|
bun create nuxt <project-name>
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
```bash [deno]
|
|
58
|
+
deno -A npm:create-nuxt@latest <project-name>
|
|
59
|
+
```
|
|
60
|
+
|
|
57
61
|
::
|
|
58
62
|
|
|
59
63
|
::tip
|
|
@@ -96,6 +100,10 @@ bun run dev -o
|
|
|
96
100
|
# To use the Bun runtime during development
|
|
97
101
|
# bun --bun run dev -o
|
|
98
102
|
```
|
|
103
|
+
|
|
104
|
+
```bash [deno]
|
|
105
|
+
deno run dev -o
|
|
106
|
+
```
|
|
99
107
|
::
|
|
100
108
|
|
|
101
109
|
::tip{icon="i-lucide-circle-check"}
|
|
@@ -149,7 +149,7 @@ Nuxt uses [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file a
|
|
|
149
149
|
|
|
150
150
|
Name | Config File | How To Configure
|
|
151
151
|
---------------------------------------------|---------------------------|-------------------------
|
|
152
|
-
[Nitro](https://nitro.
|
|
152
|
+
[Nitro](https://nitro.build) | ~~`nitro.config.ts`~~ | Use [`nitro`](/docs/api/nuxt-config#nitro) key in `nuxt.config`
|
|
153
153
|
[PostCSS](https://postcss.org) | ~~`postcss.config.js`~~ | Use [`postcss`](/docs/api/nuxt-config#postcss) key in `nuxt.config`
|
|
154
154
|
[Vite](https://vite.dev) | ~~`vite.config.ts`~~ | Use [`vite`](/docs/api/nuxt-config#vite) key in `nuxt.config`
|
|
155
155
|
[webpack](https://webpack.js.org) | ~~`webpack.config.ts`~~ | Use [`webpack`](/docs/api/nuxt-config#webpack-1) key in `nuxt.config`
|
|
@@ -148,7 +148,9 @@ If you only need to modify the `<head>`, you can refer to the [SEO and meta sect
|
|
|
148
148
|
You can have full control over the HTML template by adding a Nitro plugin that registers a hook.
|
|
149
149
|
The callback function of the `render:html` hook allows you to mutate the HTML before it is sent to the client.
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
<!-- TODO: figure out how to use twoslash to inject types for a different context -->
|
|
152
|
+
|
|
153
|
+
```ts [server/plugins/extend-html.ts]
|
|
152
154
|
export default defineNitroPlugin((nitroApp) => {
|
|
153
155
|
nitroApp.hooks.hook('render:html', (html, { event }) => {
|
|
154
156
|
// This will be an object representation of the html template.
|
|
@@ -153,7 +153,9 @@ If you need more advanced control, you can intercept the rendered html with a ho
|
|
|
153
153
|
|
|
154
154
|
Create a plugin in `~/server/plugins/my-plugin.ts` like this:
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
<!-- TODO: figure out how to use twoslash to inject types for a different context -->
|
|
157
|
+
|
|
158
|
+
```ts [server/plugins/my-plugin.ts]
|
|
157
159
|
export default defineNitroPlugin((nitro) => {
|
|
158
160
|
nitro.hooks.hook('render:html', (html) => {
|
|
159
161
|
html.head.push('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">')
|
|
@@ -610,7 +610,7 @@ onMounted(() => console.log(document.cookie))
|
|
|
610
610
|
</script>
|
|
611
611
|
```
|
|
612
612
|
|
|
613
|
-
## Options API
|
|
613
|
+
## Options API Support
|
|
614
614
|
|
|
615
615
|
Nuxt provides a way to perform `asyncData` fetching within the Options API. You must wrap your component definition within `defineNuxtComponent` for this to work.
|
|
616
616
|
|
|
@@ -744,7 +744,7 @@ const { data } = await useFetch('/api/superjson', {
|
|
|
744
744
|
|
|
745
745
|
## Recipes
|
|
746
746
|
|
|
747
|
-
### Consuming SSE (Server
|
|
747
|
+
### Consuming SSE (Server-Sent Events) via POST request
|
|
748
748
|
|
|
749
749
|
::tip
|
|
750
750
|
If you're consuming SSE via GET request, you can use [`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) or VueUse composable [`useEventSource`](https://vueuse.org/core/useEventSource/).
|
|
@@ -79,7 +79,7 @@ export default defineNuxtConfig({
|
|
|
79
79
|
|
|
80
80
|
Setting `nitro.prerender` to `true` is similar to `nitro.prerender.crawlLinks` to `true`.
|
|
81
81
|
|
|
82
|
-
::read-more{to="https://nitro.
|
|
82
|
+
::read-more{to="https://nitro.build/config#prerender"}
|
|
83
83
|
Read more about pre-rendering in the Nitro documentation.
|
|
84
84
|
::
|
|
85
85
|
|
|
@@ -99,7 +99,7 @@ export default defineNuxtConfig({
|
|
|
99
99
|
});
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
::read-more{to="https://nitro.
|
|
102
|
+
::read-more{to="https://nitro.build/config/#routerules"}
|
|
103
103
|
Read more about Nitro's `routeRules` configuration.
|
|
104
104
|
::
|
|
105
105
|
|
|
@@ -62,7 +62,7 @@ By default, the workload gets distributed to the workers with the round robin st
|
|
|
62
62
|
|
|
63
63
|
### Learn More
|
|
64
64
|
|
|
65
|
-
:read-more{to="https://nitro.
|
|
65
|
+
:read-more{to="https://nitro.build/deploy/node" title="the Nitro documentation for node-server preset"}
|
|
66
66
|
|
|
67
67
|
:video-accordion{title="Watch Daniel Roe's short video on the topic" videoId="0x1H6K5yOfs"}
|
|
68
68
|
|
|
@@ -111,7 +111,7 @@ export default defineNuxtConfig({
|
|
|
111
111
|
NITRO_PRESET=node-server nuxt build
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
🔎 Check [the Nitro deployment](https://nitro.
|
|
114
|
+
🔎 Check [the Nitro deployment](https://nitro.build/deploy) for all possible deployment presets and providers.
|
|
115
115
|
|
|
116
116
|
## CDN Proxy
|
|
117
117
|
|
|
@@ -594,7 +594,7 @@ For local development or automated deploy pipelines, testing against a separate
|
|
|
594
594
|
|
|
595
595
|
To utilize a separate target host for end-to-end tests, simply provide the `host` property of the `setup` function with the desired URL.
|
|
596
596
|
|
|
597
|
-
```ts
|
|
597
|
+
```ts
|
|
598
598
|
import { setup, createPage } from '@nuxt/test-utils/e2e'
|
|
599
599
|
import { describe, it, expect } from 'vitest'
|
|
600
600
|
|
|
@@ -35,9 +35,7 @@ bun x nuxi upgrade
|
|
|
35
35
|
To use the latest Nuxt build and test features before their release, read about the [nightly release channel](/docs/guide/going-further/nightly-release-channel) guide.
|
|
36
36
|
|
|
37
37
|
::warning
|
|
38
|
-
The nightly release channel `latest` tag is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now
|
|
39
|
-
|
|
40
|
-
You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
38
|
+
The nightly release channel `latest` tag is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now — be careful! You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
41
39
|
::
|
|
42
40
|
|
|
43
41
|
## Testing Nuxt 4
|
|
@@ -623,6 +621,7 @@ You can automate this step by running `npx codemod@latest nuxt/4/default-data-er
|
|
|
623
621
|
If you encounter any issues you can revert back to the previous behavior with:
|
|
624
622
|
|
|
625
623
|
```ts twoslash [nuxt.config.ts]
|
|
624
|
+
// @errors: 2353
|
|
626
625
|
export default defineNuxtConfig({
|
|
627
626
|
experimental: {
|
|
628
627
|
defaults: {
|
|
@@ -646,6 +645,7 @@ Please report an issue if you are doing this, as we do not plan to keep this as
|
|
|
646
645
|
Previously it was possible to pass `dedupe: boolean` to `refresh`. These were aliases of `cancel` (`true`) and `defer` (`false`).
|
|
647
646
|
|
|
648
647
|
```ts twoslash [app.vue]
|
|
648
|
+
// @errors: 2322
|
|
649
649
|
const { refresh } = await useAsyncData(async () => ({ message: 'Hello, Nuxt!' }))
|
|
650
650
|
|
|
651
651
|
async function refreshData () {
|
|
@@ -659,7 +659,7 @@ These aliases were removed, for greater clarity.
|
|
|
659
659
|
|
|
660
660
|
The issue came up when adding `dedupe` as an option to `useAsyncData`, and we removed the boolean values as they ended up being _opposites_.
|
|
661
661
|
|
|
662
|
-
`refresh({ dedupe: false })` meant
|
|
662
|
+
`refresh({ dedupe: false })` meant **do not _cancel_ existing requests in favour of this new one**. But passing `dedupe: true` within the options of `useAsyncData` means **do not make any new requests if there is an existing pending request.** (See [PR](https://github.com/nuxt/nuxt/pull/24564#pullrequestreview-1764584361).)
|
|
663
663
|
|
|
664
664
|
#### Migration Steps
|
|
665
665
|
|
|
@@ -698,6 +698,7 @@ Often users set an appropriately empty value, such as an empty array, to avoid t
|
|
|
698
698
|
If you encounter any issues you can revert back to the previous behavior, for now, with:
|
|
699
699
|
|
|
700
700
|
```ts twoslash [nuxt.config.ts]
|
|
701
|
+
// @errors: 2353
|
|
701
702
|
export default defineNuxtConfig({
|
|
702
703
|
experimental: {
|
|
703
704
|
resetAsyncDataToUndefined: true,
|
|
@@ -152,7 +152,7 @@ Previously every route/page of a Nuxt application and server must use the same r
|
|
|
152
152
|
|
|
153
153
|
Nuxt includes route rules and hybrid rendering support. Using route rules you can define rules for a group of nuxt routes, change rendering mode or assign a cache strategy based on route!
|
|
154
154
|
|
|
155
|
-
Nuxt server will automatically register corresponding middleware and wrap routes with cache handlers using [Nitro caching layer](https://nitro.
|
|
155
|
+
Nuxt server will automatically register corresponding middleware and wrap routes with cache handlers using [Nitro caching layer](https://nitro.build/guide/cache).
|
|
156
156
|
|
|
157
157
|
```ts twoslash [nuxt.config.ts]
|
|
158
158
|
export default defineNuxtConfig({
|
|
@@ -219,7 +219,7 @@ With ESR, the rendering process is pushed to the 'edge' of the network - the CDN
|
|
|
219
219
|
|
|
220
220
|
When a request for a page is made, instead of going all the way to the original server, it's intercepted by the nearest edge server. This server generates the HTML for the page and sends it back to the user. This process minimizes the physical distance the data has to travel, **reducing latency and loading the page faster**.
|
|
221
221
|
|
|
222
|
-
Edge-side rendering is possible thanks to [Nitro](https://nitro.
|
|
222
|
+
Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
|
|
223
223
|
|
|
224
224
|
The current platforms where you can leverage ESR are:
|
|
225
225
|
- [Cloudflare Pages](https://pages.cloudflare.com) with zero configuration using the git integration and the `nuxt build` command
|
|
@@ -3,7 +3,7 @@ title: Server Engine
|
|
|
3
3
|
description: 'Nuxt is powered by a new server engine: Nitro.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
While building Nuxt, we created a new server engine: [Nitro](https://nitro.
|
|
6
|
+
While building Nuxt, we created a new server engine: [Nitro](https://nitro.build/).
|
|
7
7
|
|
|
8
8
|
It is shipped with many features:
|
|
9
9
|
|
|
@@ -335,6 +335,10 @@ You may define a name for this page's route.
|
|
|
335
335
|
|
|
336
336
|
You may define a path matcher, if you have a more complex pattern than can be expressed with the file name. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/route-matching-syntax.html#custom-regex-in-params) for more information.
|
|
337
337
|
|
|
338
|
+
#### `props`
|
|
339
|
+
|
|
340
|
+
Allows accessing the route `params` as props passed to the page component. See[the `vue-router` docs](https://router.vuejs.org/guide/essentials/passing-props) for more information.
|
|
341
|
+
|
|
338
342
|
### Typing Custom Metadata
|
|
339
343
|
|
|
340
344
|
If you add custom metadata for your pages, you may wish to do so in a type-safe way. It is possible to augment the type of the object accepted by `definePageMeta`:
|
|
@@ -97,7 +97,7 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
97
97
|
})
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
:read-more{to="https://nitro.
|
|
100
|
+
:read-more{to="https://nitro.build/guide/plugins" title="Nitro Plugins" target="_blank"}
|
|
101
101
|
|
|
102
102
|
## Server Utilities
|
|
103
103
|
|
|
@@ -160,7 +160,7 @@ export default defineEventHandler((event) => {
|
|
|
160
160
|
})
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
::tip{to="https://h3.
|
|
163
|
+
::tip{to="https://h3.dev/examples/validate-data#validate-params"}
|
|
164
164
|
Alternatively, use `getValidatedRouterParams` with a schema validator such as Zod for runtime and type safety.
|
|
165
165
|
::
|
|
166
166
|
|
|
@@ -389,7 +389,7 @@ export default eventHandler((event) => {
|
|
|
389
389
|
|
|
390
390
|
### Nitro Config
|
|
391
391
|
|
|
392
|
-
You can use `nitro` key in `nuxt.config` to directly set [Nitro configuration](https://nitro.
|
|
392
|
+
You can use `nitro` key in `nuxt.config` to directly set [Nitro configuration](https://nitro.build/config).
|
|
393
393
|
|
|
394
394
|
::warning
|
|
395
395
|
This is an advanced option. Custom config can affect production deployments, as the configuration interface might change over time when Nitro is upgraded in semver-minor versions of Nuxt.
|
|
@@ -397,7 +397,7 @@ This is an advanced option. Custom config can affect production deployments, as
|
|
|
397
397
|
|
|
398
398
|
```ts [nuxt.config.ts]
|
|
399
399
|
export default defineNuxtConfig({
|
|
400
|
-
// https://nitro.
|
|
400
|
+
// https://nitro.build/config
|
|
401
401
|
nitro: {}
|
|
402
402
|
})
|
|
403
403
|
```
|
|
@@ -464,7 +464,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
|
|
|
464
464
|
|
|
465
465
|
### Server Storage
|
|
466
466
|
|
|
467
|
-
Nitro provides a cross-platform [storage layer](https://nitro.
|
|
467
|
+
Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](#server-plugins).
|
|
468
468
|
|
|
469
469
|
**Example of adding a Redis storage:**
|
|
470
470
|
|
|
@@ -506,7 +506,7 @@ export default defineEventHandler(async (event) => {
|
|
|
506
506
|
})
|
|
507
507
|
```
|
|
508
508
|
|
|
509
|
-
::read-more{to="https://nitro.
|
|
509
|
+
::read-more{to="https://nitro.build/guide/storage" target="_blank"}
|
|
510
510
|
Read more about Nitro Storage Layer.
|
|
511
511
|
::
|
|
512
512
|
|
|
@@ -57,25 +57,11 @@ export default defineNuxtConfig({
|
|
|
57
57
|
This feature will likely be removed in a near future.
|
|
58
58
|
::
|
|
59
59
|
|
|
60
|
-
## treeshakeClientOnly
|
|
61
|
-
|
|
62
|
-
Tree shakes contents of client-only components from server bundle.
|
|
63
|
-
|
|
64
|
-
*Enabled by default.*
|
|
65
|
-
|
|
66
|
-
```ts twoslash [nuxt.config.ts]
|
|
67
|
-
export default defineNuxtConfig({
|
|
68
|
-
experimental: {
|
|
69
|
-
treeshakeClientOnly: true
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
60
|
## emitRouteChunkError
|
|
75
61
|
|
|
76
62
|
Emits `app:chunkError` hook when there is an error loading vite/webpack chunks. Default behavior is to perform a reload of the new route on navigation to a new route when a chunk fails to load.
|
|
77
63
|
|
|
78
|
-
If you set this to `'automatic-immediate'` Nuxt will reload the current route
|
|
64
|
+
If you set this to `'automatic-immediate'` Nuxt will reload the current route immediately, instead of waiting for a navigation. This is useful for chunk errors that are not triggered by navigation, e.g., when your Nuxt app fails to load a [lazy component](/docs/guide/directory-structure/components#dynamic-imports). A potential downside of this behavior is undesired reloads, e.g., when your app does not need the chunk that caused the error.
|
|
79
65
|
|
|
80
66
|
You can disable automatic handling by setting this to `false`, or handle chunk errors manually by setting it to `manual`.
|
|
81
67
|
|
|
@@ -240,44 +226,6 @@ export default defineNuxtConfig({
|
|
|
240
226
|
You can follow the server components roadmap on GitHub.
|
|
241
227
|
::
|
|
242
228
|
|
|
243
|
-
## configSchema
|
|
244
|
-
|
|
245
|
-
Enables config schema support.
|
|
246
|
-
|
|
247
|
-
*Enabled by default.*
|
|
248
|
-
|
|
249
|
-
```ts twoslash [nuxt.config.ts]
|
|
250
|
-
export default defineNuxtConfig({
|
|
251
|
-
experimental: {
|
|
252
|
-
configSchema: true
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## polyfillVueUseHead
|
|
258
|
-
|
|
259
|
-
Adds a compatibility layer for modules, plugins, or user code relying on the old `@vueuse/head` API.
|
|
260
|
-
|
|
261
|
-
```ts twoslash [nuxt.config.ts]
|
|
262
|
-
export default defineNuxtConfig({
|
|
263
|
-
experimental: {
|
|
264
|
-
polyfillVueUseHead: false
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## respectNoSSRHeader
|
|
270
|
-
|
|
271
|
-
Allow disabling Nuxt SSR responses by setting the `x-nuxt-no-ssr` header.
|
|
272
|
-
|
|
273
|
-
```ts twoslash [nuxt.config.ts]
|
|
274
|
-
export default defineNuxtConfig({
|
|
275
|
-
experimental: {
|
|
276
|
-
respectNoSSRHeader: false
|
|
277
|
-
}
|
|
278
|
-
})
|
|
279
|
-
```
|
|
280
|
-
|
|
281
229
|
## localLayerAliases
|
|
282
230
|
|
|
283
231
|
Resolve `~`, `~~`, `@` and `@@` aliases located within layers with respect to their layer source and root directories.
|
|
@@ -16,9 +16,7 @@ Features that are only available on the nightly release channel are marked with
|
|
|
16
16
|
::
|
|
17
17
|
|
|
18
18
|
::warning
|
|
19
|
-
The `latest` nightly release channel is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now
|
|
20
|
-
|
|
21
|
-
You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
19
|
+
The `latest` nightly release channel is currently tracking the Nuxt v4 branch, meaning that it is particularly likely to have breaking changes right now — be careful! You can opt in to the 3.x branch nightly releases with `"nuxt": "npm:nuxt-nightly@3x"`.
|
|
22
20
|
::
|
|
23
21
|
|
|
24
22
|
## Opting In
|
|
@@ -24,7 +24,7 @@ yarn create nuxt -t module my-module
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```bash [pnpm]
|
|
27
|
-
pnpm create nuxt
|
|
27
|
+
pnpm create nuxt -t module my-module
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
```bash [bun]
|
|
@@ -614,7 +614,7 @@ export default defineNuxtModule({
|
|
|
614
614
|
interface MyModuleNitroRules {
|
|
615
615
|
myModule?: { foo: 'bar' }
|
|
616
616
|
}
|
|
617
|
-
declare module '
|
|
617
|
+
declare module 'nitro/types' {
|
|
618
618
|
interface NitroRouteRules extends MyModuleNitroRules {}
|
|
619
619
|
interface NitroRouteConfig extends MyModuleNitroRules {}
|
|
620
620
|
}
|
|
@@ -162,7 +162,7 @@ export default defineNuxtRouteMiddleware(() => {
|
|
|
162
162
|
|
|
163
163
|
## Home Page
|
|
164
164
|
|
|
165
|
-
Now that we have our app middleware to protect our routes, we can use it on our home page that display our authenticated user
|
|
165
|
+
Now that we have our app middleware to protect our routes, we can use it on our home page that display our authenticated user information. If the user is not authenticated, they will be redirected to the login page.
|
|
166
166
|
|
|
167
167
|
We'll use [`definePageMeta`](/docs/api/utils/define-page-meta) to apply the middleware to the route that we want to protect.
|
|
168
168
|
|
|
@@ -98,7 +98,7 @@ The `handler` function should be **side-effect free** to ensure predictable beha
|
|
|
98
98
|
Which only caches data when `experimental.payloadExtraction` of `nuxt.config` is enabled.
|
|
99
99
|
- `pick`: only pick specified keys in this array from the `handler` function result
|
|
100
100
|
- `watch`: watch reactive sources to auto-refresh
|
|
101
|
-
- `deep`: return data in a deep ref object
|
|
101
|
+
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object for performance.
|
|
102
102
|
- `dedupe`: avoid fetching same key more than once at a time (defaults to `cancel`). Possible options:
|
|
103
103
|
- `cancel` - cancels existing requests when a new one is made
|
|
104
104
|
- `defer` - does not make new requests at all if there is a pending request
|
|
@@ -132,7 +132,7 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
|
|
132
132
|
Which only caches data when `experimental.payloadExtraction` of `nuxt.config` is enabled.
|
|
133
133
|
- `pick`: only pick specified keys in this array from the `handler` function result
|
|
134
134
|
- `watch`: watch an array of reactive sources and auto-refresh the fetch result when they change. Fetch options and URL are watched by default. You can completely ignore reactive sources by using `watch: false`. Together with `immediate: false`, this allows for a fully-manual `useFetch`. (You can [see an example here](/docs/getting-started/data-fetching#watch) of using `watch`.)
|
|
135
|
-
- `deep`: return data in a deep ref object
|
|
135
|
+
- `deep`: return data in a deep ref object. It is `false` by default to return data in a shallow ref object for performance.
|
|
136
136
|
- `dedupe`: avoid fetching same key more than once at a time (defaults to `cancel`). Possible options:
|
|
137
137
|
- `cancel` - cancels existing requests when a new one is made
|
|
138
138
|
- `defer` - does not make new requests at all if there is a pending request
|
|
@@ -11,9 +11,9 @@ 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.
|
|
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`).
|
|
15
15
|
|
|
16
|
-
You can define the [`cache.varies` option](https://nitro.
|
|
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
|
::
|
|
18
18
|
|
|
19
19
|
::code-group
|
|
@@ -17,7 +17,7 @@ Make sure to always use `await` or `return` on result of `navigateTo` when calli
|
|
|
17
17
|
::
|
|
18
18
|
|
|
19
19
|
::note
|
|
20
|
-
`navigateTo` cannot be used within Nitro routes. To perform a server-side redirect in Nitro routes, use [`sendRedirect`](https://h3.
|
|
20
|
+
`navigateTo` cannot be used within Nitro routes. To perform a server-side redirect in Nitro routes, use [`sendRedirect`](https://h3.dev/utils/response#sendredirectevent-location-code) instead.
|
|
21
21
|
::
|
|
22
22
|
|
|
23
23
|
### Within a Vue Component
|
package/3.api/5.kit/11.nitro.md
CHANGED
|
@@ -117,7 +117,7 @@ export default defineNuxtModule({
|
|
|
117
117
|
|
|
118
118
|
```ts twoslash
|
|
119
119
|
// @errors: 2391
|
|
120
|
-
import type { NitroDevEventHandler } from '
|
|
120
|
+
import type { NitroDevEventHandler } from 'nitro/types'
|
|
121
121
|
// ---cut---
|
|
122
122
|
function addDevServerHandler (handler: NitroDevEventHandler): void
|
|
123
123
|
```
|
|
@@ -194,7 +194,7 @@ function useNitro (): Nitro
|
|
|
194
194
|
Add plugin to extend Nitro's runtime behavior.
|
|
195
195
|
|
|
196
196
|
::tip
|
|
197
|
-
You can read more about Nitro plugins in the [Nitro documentation](https://nitro.
|
|
197
|
+
You can read more about Nitro plugins in the [Nitro documentation](https://nitro.build/guide/plugins).
|
|
198
198
|
::
|
|
199
199
|
|
|
200
200
|
### Usage
|
package/3.api/5.kit/7.pages.md
CHANGED
|
@@ -58,10 +58,10 @@ function extendPages(callback: (pages: NuxtPage[]) => void): void
|
|
|
58
58
|
|
|
59
59
|
## `extendRouteRules`
|
|
60
60
|
|
|
61
|
-
Nuxt is powered by the [Nitro](https://nitro.
|
|
61
|
+
Nuxt is powered by the [Nitro](https://nitro.build/) server engine. With Nitro, you can incorporate high-level logic directly into your configuration, which is useful for actions like redirects, proxying, caching, and appending headers to routes. This configuration works by associating route patterns with specific route settings.
|
|
62
62
|
|
|
63
63
|
::tip
|
|
64
|
-
You can read more about Nitro route rules in the [Nitro documentation](https://nitro.
|
|
64
|
+
You can read more about Nitro route rules in the [Nitro documentation](https://nitro.build/guide/routing#route-rules).
|
|
65
65
|
::
|
|
66
66
|
|
|
67
67
|
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/adding-route-rules-and-route-middlewares?friend=nuxt" target="_blank"}
|
|
@@ -90,7 +90,7 @@ Hook | Arguments | Description
|
|
|
90
90
|
|
|
91
91
|
## Nitro App Hooks (runtime, server-side)
|
|
92
92
|
|
|
93
|
-
See [Nitro](https://nitro.
|
|
93
|
+
See [Nitro](https://nitro.build/guide/plugins#available-hooks) for all available hooks.
|
|
94
94
|
|
|
95
95
|
Hook | Arguments | Description | Types
|
|
96
96
|
-----------------------|-----------------------|--------------------------------------|------------------
|