@nuxt/docs 3.19.1 → 3.19.3
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 +2 -2
- package/1.getting-started/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- 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/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +45 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- 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.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- 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 +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- 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 +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- 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 +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- 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 +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- 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 +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- 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 +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- 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 +2 -1
- 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 +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- 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 +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +7 -8
- 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.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +21 -20
- 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/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
title: 'content'
|
|
3
3
|
head.title: 'content/'
|
|
4
4
|
description: Use the content/ directory to create a file-based CMS for your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-log
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
[Nuxt Content](https://content.nuxt.com) reads the [`content/` directory](/docs/guide/directory-structure/content) in your project and parses `.md`, `.yml`, `.csv` and `.json` files to create a file-based CMS for your application.
|
|
8
|
+
[Nuxt Content](https://content.nuxt.com) reads the [`content/` directory](/docs/3.x/guide/directory-structure/content) in your project and parses `.md`, `.yml`, `.csv` and `.json` files to create a file-based CMS for your application.
|
|
9
9
|
|
|
10
10
|
- Render your content with built-in components.
|
|
11
11
|
- Query your content with a MongoDB-like API.
|
|
@@ -36,7 +36,7 @@ The module automatically loads and parses them.
|
|
|
36
36
|
|
|
37
37
|
## Render Content
|
|
38
38
|
|
|
39
|
-
To render content pages, add a [catch-all route](/docs/guide/directory-structure/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
39
|
+
To render content pages, add a [catch-all route](/docs/3.x/guide/directory-structure/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
40
40
|
|
|
41
41
|
```vue [pages/[...slug\\].vue]
|
|
42
42
|
<script lang="ts" setup>
|
|
@@ -50,7 +50,10 @@ const { data: page } = await useAsyncData(route.path, () => {
|
|
|
50
50
|
<div>
|
|
51
51
|
<header><!-- ... --></header>
|
|
52
52
|
|
|
53
|
-
<ContentRenderer
|
|
53
|
+
<ContentRenderer
|
|
54
|
+
v-if="page"
|
|
55
|
+
:value="page"
|
|
56
|
+
/>
|
|
54
57
|
|
|
55
58
|
<footer><!-- ... --></footer>
|
|
56
59
|
</div>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "layouts"
|
|
3
3
|
head.title: "layouts/"
|
|
4
4
|
description: "Nuxt provides a layouts framework to extract common UI patterns into reusable layouts."
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-view
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::tip{icon="i-lucide-rocket" }
|
|
@@ -11,7 +11,7 @@ For best performance, components placed in this directory will be automatically
|
|
|
11
11
|
|
|
12
12
|
## Enable Layouts
|
|
13
13
|
|
|
14
|
-
Layouts are enabled by adding [`<NuxtLayout>`](/docs/api/components/nuxt-layout) to your [`app.vue`](/docs/guide/directory-structure/app):
|
|
14
|
+
Layouts are enabled by adding [`<NuxtLayout>`](/docs/3.x/api/components/nuxt-layout) to your [`app.vue`](/docs/3.x/guide/directory-structure/app):
|
|
15
15
|
|
|
16
16
|
```vue [app.vue]
|
|
17
17
|
<template>
|
|
@@ -22,7 +22,7 @@ Layouts are enabled by adding [`<NuxtLayout>`](/docs/api/components/nuxt-layout)
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
To use a layout:
|
|
25
|
-
- Set a `layout` property in your page with [definePageMeta](/docs/api/utils/define-page-meta).
|
|
25
|
+
- Set a `layout` property in your page with [definePageMeta](/docs/3.x/api/utils/define-page-meta).
|
|
26
26
|
- Set the `name` prop of `<NuxtLayout>`.
|
|
27
27
|
|
|
28
28
|
::note
|
|
@@ -34,7 +34,7 @@ If no layout is specified, `layouts/default.vue` will be used.
|
|
|
34
34
|
::
|
|
35
35
|
|
|
36
36
|
::important
|
|
37
|
-
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/guide/directory-structure/app) instead.
|
|
37
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/3.x/guide/directory-structure/app) instead.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
::important
|
|
@@ -69,7 +69,7 @@ Then you can use the `custom` layout in your page:
|
|
|
69
69
|
```vue twoslash [pages/about.vue]
|
|
70
70
|
<script setup lang="ts">
|
|
71
71
|
definePageMeta({
|
|
72
|
-
layout: 'custom'
|
|
72
|
+
layout: 'custom',
|
|
73
73
|
})
|
|
74
74
|
</script>
|
|
75
75
|
```
|
|
@@ -78,12 +78,12 @@ definePageMeta({
|
|
|
78
78
|
Learn more about `definePageMeta`.
|
|
79
79
|
::
|
|
80
80
|
|
|
81
|
-
You can directly override the default layout for all pages using the `name` property of [`<NuxtLayout>`](/docs/api/components/nuxt-layout):
|
|
81
|
+
You can directly override the default layout for all pages using the `name` property of [`<NuxtLayout>`](/docs/3.x/api/components/nuxt-layout):
|
|
82
82
|
|
|
83
83
|
```vue [app.vue]
|
|
84
84
|
<script setup lang="ts">
|
|
85
85
|
// You might choose this based on an API call or logged-in status
|
|
86
|
-
const layout =
|
|
86
|
+
const layout = 'custom'
|
|
87
87
|
</script>
|
|
88
88
|
|
|
89
89
|
<template>
|
|
@@ -113,7 +113,7 @@ File | Layout Name
|
|
|
113
113
|
|
|
114
114
|
## Changing the Layout Dynamically
|
|
115
115
|
|
|
116
|
-
You can also use the [`setPageLayout`](/docs/api/utils/set-page-layout) helper to change the layout dynamically:
|
|
116
|
+
You can also use the [`setPageLayout`](/docs/3.x/api/utils/set-page-layout) helper to change the layout dynamically:
|
|
117
117
|
|
|
118
118
|
```vue twoslash
|
|
119
119
|
<script setup lang="ts">
|
|
@@ -122,12 +122,14 @@ function enableCustomLayout () {
|
|
|
122
122
|
}
|
|
123
123
|
definePageMeta({
|
|
124
124
|
layout: false,
|
|
125
|
-
})
|
|
125
|
+
})
|
|
126
126
|
</script>
|
|
127
127
|
|
|
128
128
|
<template>
|
|
129
129
|
<div>
|
|
130
|
-
<button @click="enableCustomLayout">
|
|
130
|
+
<button @click="enableCustomLayout">
|
|
131
|
+
Update layout
|
|
132
|
+
</button>
|
|
131
133
|
</div>
|
|
132
134
|
</template>
|
|
133
135
|
```
|
|
@@ -150,7 +152,9 @@ definePageMeta({
|
|
|
150
152
|
<template>
|
|
151
153
|
<div>
|
|
152
154
|
<NuxtLayout name="custom">
|
|
153
|
-
<template #header>
|
|
155
|
+
<template #header>
|
|
156
|
+
Some header template content.
|
|
157
|
+
</template>
|
|
154
158
|
|
|
155
159
|
The rest of the page
|
|
156
160
|
</NuxtLayout>
|
|
@@ -176,5 +180,5 @@ definePageMeta({
|
|
|
176
180
|
::
|
|
177
181
|
|
|
178
182
|
::important
|
|
179
|
-
If you use `<NuxtLayout>` within your pages, make sure it is not the root element (or [disable layout/page transitions](/docs/getting-started/transitions#disable-transitions)).
|
|
183
|
+
If you use `<NuxtLayout>` within your pages, make sure it is not the root element (or [disable layout/page transitions](/docs/3.x/getting-started/transitions#disable-transitions)).
|
|
180
184
|
::
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "middleware"
|
|
3
3
|
description: "Nuxt provides middleware to run code before navigating to a particular route."
|
|
4
4
|
head.title: "middleware/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-middleware
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Nuxt provides a customizable **route middleware** framework you can use throughout your application, ideal for extracting code that you want to run before navigating to a particular route.
|
|
@@ -13,14 +13,14 @@ There are three kinds of route middleware:
|
|
|
13
13
|
2. Named route middleware, placed in the `middleware/` and automatically loaded via asynchronous import when used on a page.
|
|
14
14
|
3. Global route middleware, placed in the `middleware/` with a `.global` suffix and is run on every route change.
|
|
15
15
|
|
|
16
|
-
The first two kinds of route middleware can be defined in [`definePageMeta`](/docs/api/utils/define-page-meta).
|
|
16
|
+
The first two kinds of route middleware can be defined in [`definePageMeta`](/docs/3.x/api/utils/define-page-meta).
|
|
17
17
|
|
|
18
18
|
::note
|
|
19
19
|
Name of middleware are normalized to kebab-case: `myMiddleware` becomes `my-middleware`.
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from [server middleware](/docs/guide/directory-structure/server#server-middleware), which are run in the Nitro server part of your app.
|
|
23
|
+
Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from [server middleware](/docs/3.x/guide/directory-structure/server#server-middleware), which are run in the Nitro server part of your app.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
:video-accordion{title="Watch a video from Vue School on all 3 kinds of middleware" videoId="761471577" platform="vimeo"}
|
|
@@ -45,8 +45,8 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
45
45
|
|
|
46
46
|
Nuxt provides two globally available helpers that can be returned directly from the middleware.
|
|
47
47
|
|
|
48
|
-
1. [`navigateTo`](/docs/api/utils/navigate-to) - Redirects to the given route
|
|
49
|
-
2. [`abortNavigation`](/docs/api/utils/abort-navigation) - Aborts the navigation, with an optional error message.
|
|
48
|
+
1. [`navigateTo`](/docs/3.x/api/utils/navigate-to) - Redirects to the given route
|
|
49
|
+
2. [`abortNavigation`](/docs/3.x/api/utils/abort-navigation) - Aborts the navigation, with an optional error message.
|
|
50
50
|
|
|
51
51
|
Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards) from `vue-router`, a third `next()` argument is not passed, and **redirect or route cancellation is handled by returning a value from the middleware**.
|
|
52
52
|
|
|
@@ -90,7 +90,7 @@ definePageMeta({
|
|
|
90
90
|
},
|
|
91
91
|
'auth',
|
|
92
92
|
],
|
|
93
|
-
})
|
|
93
|
+
})
|
|
94
94
|
</script>
|
|
95
95
|
```
|
|
96
96
|
|
|
@@ -125,26 +125,32 @@ If your site is server-rendered or generated, middleware for the initial page wi
|
|
|
125
125
|
However, if you want to avoid this behaviour you can do so:
|
|
126
126
|
|
|
127
127
|
```ts twoslash [middleware/example.ts]
|
|
128
|
-
export default defineNuxtRouteMiddleware(to => {
|
|
128
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
129
129
|
// skip middleware on server
|
|
130
|
-
if (import.meta.server)
|
|
130
|
+
if (import.meta.server) {
|
|
131
|
+
return
|
|
132
|
+
}
|
|
131
133
|
// skip middleware on client side entirely
|
|
132
|
-
if (import.meta.client)
|
|
134
|
+
if (import.meta.client) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
133
137
|
// or only skip middleware on initial client load
|
|
134
138
|
const nuxtApp = useNuxtApp()
|
|
135
|
-
if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered)
|
|
139
|
+
if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) {
|
|
140
|
+
return
|
|
141
|
+
}
|
|
136
142
|
})
|
|
137
143
|
```
|
|
138
144
|
|
|
139
145
|
This is true even if you throw an error in your middleware on the server, and an error page is rendered. The middleware will still run again in the browser.
|
|
140
146
|
|
|
141
147
|
::note
|
|
142
|
-
Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
|
|
148
|
+
Rendering an error page is an entirely separate page load, meaning any registered middleware will run again. You can use [`useError`](/docs/3.x/getting-started/error-handling#useerror) in middleware to check if an error is being handled.
|
|
143
149
|
::
|
|
144
150
|
|
|
145
151
|
## Accessing Route in Middleware
|
|
146
152
|
|
|
147
|
-
Always use the `to` and `from` parameters in your middleware to access the next and previous routes. Avoid using the [`useRoute()`](/docs/api/composables/use-route) composable in this context altogether.
|
|
153
|
+
Always use the `to` and `from` parameters in your middleware to access the next and previous routes. Avoid using the [`useRoute()`](/docs/3.x/api/composables/use-route) composable in this context altogether.
|
|
148
154
|
There is **no concept of a "current route" in middleware**, as middleware can abort a navigation or redirect to a different route. The `useRoute()` composable will always be inaccurate in this context.
|
|
149
155
|
|
|
150
156
|
::warning
|
|
@@ -155,10 +161,10 @@ This leads to the **same issue as above**, so you should structure your function
|
|
|
155
161
|
::code-group
|
|
156
162
|
```ts twoslash [middleware/access-route.ts]
|
|
157
163
|
// @errors: 2304
|
|
158
|
-
export default defineNuxtRouteMiddleware(to => {
|
|
164
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
159
165
|
// passing the route to the function to avoid calling `useRoute()` in middleware
|
|
160
166
|
doSomethingWithRoute(to)
|
|
161
|
-
|
|
167
|
+
|
|
162
168
|
// ❌ this will output a warning and is NOT recommended
|
|
163
169
|
callsRouteInternally()
|
|
164
170
|
})
|
|
@@ -166,14 +172,14 @@ export default defineNuxtRouteMiddleware(to => {
|
|
|
166
172
|
|
|
167
173
|
```ts twoslash [utils/handle-route.ts]
|
|
168
174
|
// providing the route as an argument so that it can be used in middleware correctly
|
|
169
|
-
export function doSomethingWithRoute(route = useRoute()) {
|
|
175
|
+
export function doSomethingWithRoute (route = useRoute()) {
|
|
170
176
|
// ...
|
|
171
177
|
}
|
|
172
178
|
```
|
|
173
179
|
```ts twoslash [utils/dont-do-this.ts]
|
|
174
180
|
// ❌ this function is not suitable for use in middleware
|
|
175
|
-
export function callsRouteInternally() {
|
|
176
|
-
|
|
181
|
+
export function callsRouteInternally () {
|
|
182
|
+
const route = useRoute()
|
|
177
183
|
// ...
|
|
178
184
|
}
|
|
179
185
|
```
|
|
@@ -182,7 +188,7 @@ export function callsRouteInternally() {
|
|
|
182
188
|
|
|
183
189
|
## Adding Middleware Dynamically
|
|
184
190
|
|
|
185
|
-
It is possible to add global or named route middleware manually using the [`addRouteMiddleware()`](/docs/api/utils/add-route-middleware) helper function, such as from within a plugin.
|
|
191
|
+
It is possible to add global or named route middleware manually using the [`addRouteMiddleware()`](/docs/3.x/api/utils/add-route-middleware) helper function, such as from within a plugin.
|
|
186
192
|
|
|
187
193
|
```ts twoslash
|
|
188
194
|
export default defineNuxtPlugin(() => {
|
|
@@ -208,7 +214,7 @@ In your page file, you can reference this route middleware:
|
|
|
208
214
|
```vue twoslash
|
|
209
215
|
<script setup lang="ts">
|
|
210
216
|
definePageMeta({
|
|
211
|
-
middleware: [
|
|
217
|
+
middleware: ['auth'],
|
|
212
218
|
// or middleware: 'auth'
|
|
213
219
|
})
|
|
214
220
|
</script>
|
|
@@ -230,7 +236,7 @@ export default defineNuxtConfig({
|
|
|
230
236
|
'pages:extend' (pages) {
|
|
231
237
|
function setMiddleware (pages: NuxtPage[]) {
|
|
232
238
|
for (const page of pages) {
|
|
233
|
-
if (/* some condition */
|
|
239
|
+
if (/* some condition */ Math.random() > 0.5) {
|
|
234
240
|
page.meta ||= {}
|
|
235
241
|
// Note that this will override any middleware set in `definePageMeta` in the page
|
|
236
242
|
page.meta.middleware = ['named']
|
|
@@ -241,7 +247,7 @@ export default defineNuxtConfig({
|
|
|
241
247
|
}
|
|
242
248
|
}
|
|
243
249
|
setMiddleware(pages)
|
|
244
|
-
}
|
|
245
|
-
}
|
|
250
|
+
},
|
|
251
|
+
},
|
|
246
252
|
})
|
|
247
253
|
```
|
|
@@ -11,18 +11,18 @@ The auto-registered files patterns are:
|
|
|
11
11
|
- `modules/*/index.ts`
|
|
12
12
|
- `modules/*.ts`
|
|
13
13
|
|
|
14
|
-
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) separately.
|
|
14
|
+
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/3.x/guide/directory-structure/nuxt-config) separately.
|
|
15
15
|
|
|
16
16
|
::code-group
|
|
17
17
|
|
|
18
18
|
```ts twoslash [modules/hello/index.ts]
|
|
19
19
|
// `nuxt/kit` is a helper subpath import you can use when defining local modules
|
|
20
20
|
// that means you do not need to add `@nuxt/kit` to your project's dependencies
|
|
21
|
-
import { createResolver, defineNuxtModule
|
|
21
|
+
import { addServerHandler, createResolver, defineNuxtModule } from 'nuxt/kit'
|
|
22
22
|
|
|
23
23
|
export default defineNuxtModule({
|
|
24
24
|
meta: {
|
|
25
|
-
name: 'hello'
|
|
25
|
+
name: 'hello',
|
|
26
26
|
},
|
|
27
27
|
setup () {
|
|
28
28
|
const resolver = createResolver(import.meta.url)
|
|
@@ -30,9 +30,9 @@ export default defineNuxtModule({
|
|
|
30
30
|
// Add an API route
|
|
31
31
|
addServerHandler({
|
|
32
32
|
route: '/api/hello',
|
|
33
|
-
handler: resolver.resolve('./runtime/api-route')
|
|
33
|
+
handler: resolver.resolve('./runtime/api-route'),
|
|
34
34
|
})
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
36
|
})
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -47,7 +47,7 @@ export default defineEventHandler(() => {
|
|
|
47
47
|
When starting Nuxt, the `hello` module will be registered and the `/api/hello` route will be available.
|
|
48
48
|
|
|
49
49
|
Modules are executed in the following sequence:
|
|
50
|
-
- First, the modules defined in [`nuxt.config.ts`](/docs/api/nuxt-config#modules-1) are loaded.
|
|
50
|
+
- First, the modules defined in [`nuxt.config.ts`](/docs/3.x/api/nuxt-config#modules-1) are loaded.
|
|
51
51
|
- Then, modules found in the `modules/` directory are executed, and they load in alphabetical order.
|
|
52
52
|
|
|
53
53
|
You can change the order of local module by adding a number to the front of each directory name:
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
title: "node_modules"
|
|
3
3
|
description: "The package manager stores the dependencies of your project in the node_modules/ directory."
|
|
4
4
|
head.title: "node_modules/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-node
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.sh/package-manager)) creates this directory to store the dependencies of your project.
|
|
9
9
|
|
|
10
10
|
::important
|
|
11
|
-
This directory should be added to your [`.gitignore`](/docs/guide/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
11
|
+
This directory should be added to your [`.gitignore`](/docs/3.x/guide/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
12
12
|
::
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
title: "pages"
|
|
3
3
|
description: "Nuxt provides file-based routing to create routes within your web application."
|
|
4
4
|
head.title: "pages/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-view
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::note
|
|
9
|
-
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`app/router.options.ts`](/docs/guide/recipes/custom-routing#using-approuteroptions).
|
|
9
|
+
To reduce your application's bundle size, this directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [`app.vue`](/docs/3.x/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`app/router.options.ts`](/docs/3.x/guide/recipes/custom-routing#using-approuteroptions).
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
Pages are Vue components and can have any [valid extension](/docs/api/configuration/nuxt-config#extensions) that Nuxt supports (by default `.vue`, `.js`, `.jsx`, `.mjs`, `.ts` or `.tsx`).
|
|
14
|
+
Pages are Vue components and can have any [valid extension](/docs/3.x/api/configuration/nuxt-config#extensions) that Nuxt supports (by default `.vue`, `.js`, `.jsx`, `.mjs`, `.ts` or `.tsx`).
|
|
15
15
|
|
|
16
16
|
Nuxt will automatically create a route for every page in your `~/pages/` directory.
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@ Nuxt will automatically create a route for every page in your `~/pages/` directo
|
|
|
28
28
|
export default defineComponent({
|
|
29
29
|
render () {
|
|
30
30
|
return h('h1', 'Index page')
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
32
|
})
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -38,7 +38,7 @@ export default defineComponent({
|
|
|
38
38
|
export default defineComponent({
|
|
39
39
|
render () {
|
|
40
40
|
return <h1>Index page</h1>
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
42
|
})
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -46,7 +46,7 @@ export default defineComponent({
|
|
|
46
46
|
|
|
47
47
|
The `pages/index.vue` file will be mapped to the `/` route of your application.
|
|
48
48
|
|
|
49
|
-
If you are using [`app.vue`](/docs/guide/directory-structure/app), make sure to use the [`<NuxtPage/>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
49
|
+
If you are using [`app.vue`](/docs/3.x/guide/directory-structure/app), make sure to use the [`<NuxtPage/>`](/docs/3.x/api/components/nuxt-page) component to display the current page:
|
|
50
50
|
|
|
51
51
|
```vue [app.vue]
|
|
52
52
|
<template>
|
|
@@ -57,7 +57,7 @@ If you are using [`app.vue`](/docs/guide/directory-structure/app), make sure to
|
|
|
57
57
|
</template>
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
Pages **must have a single root element** to allow [route transitions](/docs/getting-started/transitions) between pages. HTML comments are considered elements as well.
|
|
60
|
+
Pages **must have a single root element** to allow [route transitions](/docs/3.x/getting-started/transitions) between pages. HTML comments are considered elements as well.
|
|
61
61
|
|
|
62
62
|
This means that when the route is server-rendered, or statically generated, you will be able to see its contents correctly, but when you navigate towards that route during client-side navigation the transition between routes will fail and you'll see that the route will not be rendered.
|
|
63
63
|
|
|
@@ -118,7 +118,7 @@ Navigating to `/users-admins/123` would render:
|
|
|
118
118
|
<p>admins - 123</p>
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
If you want to access the route using Composition API, there is a global [`useRoute`](/docs/api/composables/use-route) function that will allow you to access the route just like `this.$route` in the Options API.
|
|
121
|
+
If you want to access the route using Composition API, there is a global [`useRoute`](/docs/3.x/api/composables/use-route) function that will allow you to access the route just like `this.$route` in the Options API.
|
|
122
122
|
|
|
123
123
|
```vue twoslash
|
|
124
124
|
<script setup lang="ts">
|
|
@@ -177,10 +177,10 @@ This file tree will generate these routes:
|
|
|
177
177
|
{
|
|
178
178
|
path: 'child',
|
|
179
179
|
component: '~/pages/parent/child.vue',
|
|
180
|
-
name: 'parent-child'
|
|
181
|
-
}
|
|
182
|
-
]
|
|
183
|
-
}
|
|
180
|
+
name: 'parent-child',
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
184
|
]
|
|
185
185
|
```
|
|
186
186
|
|
|
@@ -197,7 +197,9 @@ To display the `child.vue` component, you have to insert the `<NuxtPage>` compon
|
|
|
197
197
|
|
|
198
198
|
```vue {}[pages/parent/child.vue]
|
|
199
199
|
<script setup lang="ts">
|
|
200
|
-
const props = defineProps(
|
|
200
|
+
const props = defineProps({
|
|
201
|
+
foobar: String,
|
|
202
|
+
})
|
|
201
203
|
|
|
202
204
|
console.log(props.foobar)
|
|
203
205
|
</script>
|
|
@@ -221,7 +223,7 @@ Or alternatively:
|
|
|
221
223
|
```vue twoslash {}[pages/parent/child.vue]
|
|
222
224
|
<script setup lang="ts">
|
|
223
225
|
definePageMeta({
|
|
224
|
-
key: route => route.fullPath
|
|
226
|
+
key: route => route.fullPath,
|
|
225
227
|
})
|
|
226
228
|
</script>
|
|
227
229
|
```
|
|
@@ -251,7 +253,7 @@ You might want to define metadata for each route in your app. You can do this us
|
|
|
251
253
|
```vue twoslash
|
|
252
254
|
<script setup lang="ts">
|
|
253
255
|
definePageMeta({
|
|
254
|
-
title: 'My home page'
|
|
256
|
+
title: 'My home page',
|
|
255
257
|
})
|
|
256
258
|
</script>
|
|
257
259
|
```
|
|
@@ -279,8 +281,8 @@ Make sure not to reference any reactive data or functions that cause side effect
|
|
|
279
281
|
<script setup lang="ts">
|
|
280
282
|
import { someData } from '~/utils/example'
|
|
281
283
|
|
|
282
|
-
function validateIdParam(route) {
|
|
283
|
-
return route.params.id && !isNaN(Number(route.params.id))
|
|
284
|
+
function validateIdParam (route) {
|
|
285
|
+
return route.params.id && !Number.isNaN(Number(route.params.id))
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
const title = ref('')
|
|
@@ -288,7 +290,7 @@ const title = ref('')
|
|
|
288
290
|
definePageMeta({
|
|
289
291
|
validate: validateIdParam,
|
|
290
292
|
someData,
|
|
291
|
-
title,
|
|
293
|
+
title, // do not do this, the ref will be hoisted out of the component
|
|
292
294
|
})
|
|
293
295
|
</script>
|
|
294
296
|
```
|
|
@@ -307,7 +309,7 @@ Nuxt will automatically wrap your page in [the Vue `<KeepAlive>` component](http
|
|
|
307
309
|
|
|
308
310
|
When your goal is to preserve state for parent routes use this syntax: `<NuxtPage keepalive />`. You can also set props to be passed to `<KeepAlive>` (see [a full list](https://vuejs.org/api/built-in-components.html#keepalive)).
|
|
309
311
|
|
|
310
|
-
You can set a default value for this property [in your `nuxt.config`](/docs/api/nuxt-config#keepalive).
|
|
312
|
+
You can set a default value for this property [in your `nuxt.config`](/docs/3.x/api/nuxt-config#keepalive).
|
|
311
313
|
|
|
312
314
|
#### `key`
|
|
313
315
|
|
|
@@ -315,17 +317,17 @@ You can set a default value for this property [in your `nuxt.config`](/docs/api/
|
|
|
315
317
|
|
|
316
318
|
#### `layout`
|
|
317
319
|
|
|
318
|
-
You can define the layout used to render the route. This can be either false (to disable any layout), a string or a ref/computed, if you want to make it reactive in some way. [More about layouts](/docs/guide/directory-structure/layouts).
|
|
320
|
+
You can define the layout used to render the route. This can be either false (to disable any layout), a string or a ref/computed, if you want to make it reactive in some way. [More about layouts](/docs/3.x/guide/directory-structure/layouts).
|
|
319
321
|
|
|
320
322
|
#### `layoutTransition` and `pageTransition`
|
|
321
323
|
|
|
322
324
|
You can define transition properties for the `<transition>` component that wraps your pages and layouts, or pass `false` to disable the `<transition>` wrapper for that route. You can see [a list of options that can be passed](https://vuejs.org/api/built-in-components.html#transition) or read [more about how transitions work](https://vuejs.org/guide/built-ins/transition.html#transition).
|
|
323
325
|
|
|
324
|
-
You can set default values for these properties [in your `nuxt.config`](/docs/api/nuxt-config#layouttransition).
|
|
326
|
+
You can set default values for these properties [in your `nuxt.config`](/docs/3.x/api/nuxt-config#layouttransition).
|
|
325
327
|
|
|
326
328
|
#### `middleware`
|
|
327
329
|
|
|
328
|
-
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards)), or an array of strings/functions. [More about named middleware](/docs/guide/directory-structure/middleware).
|
|
330
|
+
You can define middleware to apply before loading this page. It will be merged with all the other middleware used in any matching parent/child routes. It can be a string, a function (an anonymous/inlined middleware function following [the global before guard pattern](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards)), or an array of strings/functions. [More about named middleware](/docs/3.x/guide/directory-structure/middleware).
|
|
329
331
|
|
|
330
332
|
#### `name`
|
|
331
333
|
|
|
@@ -356,7 +358,7 @@ export {}
|
|
|
356
358
|
|
|
357
359
|
## Navigation
|
|
358
360
|
|
|
359
|
-
To navigate between pages of your app, you should use the [`<NuxtLink>`](/docs/api/components/nuxt-link) component.
|
|
361
|
+
To navigate between pages of your app, you should use the [`<NuxtLink>`](/docs/3.x/api/components/nuxt-link) component.
|
|
360
362
|
|
|
361
363
|
This component is included with Nuxt and therefore you don't have to import it as you do with other components.
|
|
362
364
|
|
|
@@ -382,16 +384,16 @@ Make sure to always `await` on `navigateTo` or chain its result by returning fro
|
|
|
382
384
|
|
|
383
385
|
```vue twoslash
|
|
384
386
|
<script setup lang="ts">
|
|
385
|
-
const name = ref('')
|
|
386
|
-
const type = ref(1)
|
|
387
|
+
const name = ref('')
|
|
388
|
+
const type = ref(1)
|
|
387
389
|
|
|
388
|
-
function navigate(){
|
|
390
|
+
function navigate () {
|
|
389
391
|
return navigateTo({
|
|
390
392
|
path: '/search',
|
|
391
393
|
query: {
|
|
392
394
|
name: name.value,
|
|
393
|
-
type: type.value
|
|
394
|
-
}
|
|
395
|
+
type: type.value,
|
|
396
|
+
},
|
|
395
397
|
})
|
|
396
398
|
}
|
|
397
399
|
</script>
|
|
@@ -399,11 +401,11 @@ function navigate(){
|
|
|
399
401
|
|
|
400
402
|
## Client-Only Pages
|
|
401
403
|
|
|
402
|
-
You can define a page as [client only](/docs/guide/directory-structure/components#client-components) by giving it a `.client.vue` suffix. None of the content of this page will be rendered on the server.
|
|
404
|
+
You can define a page as [client only](/docs/3.x/guide/directory-structure/components#client-components) by giving it a `.client.vue` suffix. None of the content of this page will be rendered on the server.
|
|
403
405
|
|
|
404
406
|
## Server-Only Pages
|
|
405
407
|
|
|
406
|
-
You can define a page as [server only](/docs/guide/directory-structure/components#server-components) by giving it a `.server.vue` suffix. While you will be able to navigate to the page using client-side navigation, controlled by `vue-router`, it will be rendered with a server component automatically, meaning the code required to render the page will not be in your client-side bundle.
|
|
408
|
+
You can define a page as [server only](/docs/3.x/guide/directory-structure/components#server-components) by giving it a `.server.vue` suffix. While you will be able to navigate to the page using client-side navigation, controlled by `vue-router`, it will be rendered with a server component automatically, meaning the code required to render the page will not be in your client-side bundle.
|
|
407
409
|
|
|
408
410
|
::warning
|
|
409
411
|
Server-only pages must have a single root element. (HTML comments are considered elements as well.)
|
|
@@ -419,7 +421,7 @@ As your app gets bigger and more complex, your routing might require more flexib
|
|
|
419
421
|
|
|
420
422
|
By default, all your pages should be in one `pages` directory at the root of your project.
|
|
421
423
|
|
|
422
|
-
However, you can use [Nuxt Layers](/docs/getting-started/layers) to create groupings of your app's pages:
|
|
424
|
+
However, you can use [Nuxt Layers](/docs/3.x/getting-started/layers) to create groupings of your app's pages:
|
|
423
425
|
|
|
424
426
|
```bash [Directory Structure]
|
|
425
427
|
-| some-app/
|