@nuxt/docs 4.1.1 → 4.1.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 +6 -6
- package/1.getting-started/02.installation.md +2 -1
- package/1.getting-started/03.configuration.md +37 -37
- 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 +27 -20
- 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 +53 -71
- 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 +49 -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 +17 -15
- 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 +246 -85
- package/2.guide/3.going-further/1.features.md +44 -9
- 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 +96 -94
- 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 +62 -53
- 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 +4 -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 +44 -17
- 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 +20 -20
- 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 +58 -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 +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 +14 -14
- 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 +5 -4
- package/3.api/6.advanced/1.hooks.md +3 -3
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +300 -865
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- 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 +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 +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/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
|
@@ -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 [`router.options.ts`](/docs/guide/recipes/custom-routing#using-
|
|
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/4.x/guide/directory-structure/app). To force the pages system, set `pages: true` in `nuxt.config` or have a [`router.options.ts`](/docs/4.x/guide/recipes/custom-routing#using-routeroptions).
|
|
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/4.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,17 +28,17 @@ 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
|
|
|
35
35
|
```tsx twoslash [pages/index.tsx]
|
|
36
|
-
// https://nuxt.com/docs/examples/advanced/jsx
|
|
36
|
+
// https://nuxt.com/docs/4.x/examples/advanced/jsx
|
|
37
37
|
// https://vuejs.org/guide/extras/render-function.html#jsx-tsx
|
|
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 `app/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/4.x/guide/directory-structure/app), make sure to use the [`<NuxtPage/>`](/docs/4.x/api/components/nuxt-page) component to display the current page:
|
|
50
50
|
|
|
51
51
|
```vue [app/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/4.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/4.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,12 +223,12 @@ 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
|
```
|
|
228
230
|
|
|
229
|
-
:link-example{to="/docs/examples/routing/pages"}
|
|
231
|
+
:link-example{to="/docs/4.x/examples/routing/pages"}
|
|
230
232
|
|
|
231
233
|
## Route Groups
|
|
232
234
|
|
|
@@ -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,25 +309,25 @@ 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/4.x/api/nuxt-config#keepalive).
|
|
311
313
|
|
|
312
314
|
#### `key`
|
|
313
315
|
|
|
314
|
-
[See above](#child-route-keys).
|
|
316
|
+
[See above](/docs/4.x/guide/directory-structure/app/pages#child-route-keys).
|
|
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/app/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/4.x/guide/directory-structure/app/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/4.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/app/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/4.x/guide/directory-structure/app/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/4.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
|
|
|
@@ -368,7 +370,7 @@ A simple link to the `index.vue` page in your `app/pages` folder:
|
|
|
368
370
|
</template>
|
|
369
371
|
```
|
|
370
372
|
|
|
371
|
-
::read-more{to="/docs/api/components/nuxt-link"}
|
|
373
|
+
::read-more{to="/docs/4.x/api/components/nuxt-link"}
|
|
372
374
|
Learn more about `<NuxtLink>` usage.
|
|
373
375
|
::
|
|
374
376
|
|
|
@@ -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/app/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/4.x/guide/directory-structure/app/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/app/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/4.x/guide/directory-structure/app/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.)
|
|
@@ -413,13 +415,13 @@ Server-only pages must have a single root element. (HTML comments are considered
|
|
|
413
415
|
|
|
414
416
|
As your app gets bigger and more complex, your routing might require more flexibility. For this reason, Nuxt directly exposes the router, routes and router options for customization in different ways.
|
|
415
417
|
|
|
416
|
-
:read-more{to="/docs/guide/recipes/custom-routing"}
|
|
418
|
+
:read-more{to="/docs/4.x/guide/recipes/custom-routing"}
|
|
417
419
|
|
|
418
420
|
## Multiple Pages Directories
|
|
419
421
|
|
|
420
422
|
By default, all your pages should be in one `app/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/4.x/getting-started/layers) to create groupings of your app's pages:
|
|
423
425
|
|
|
424
426
|
```bash [Directory Structure]
|
|
425
427
|
-| some-app/
|
|
@@ -441,4 +443,4 @@ export default defineNuxtConfig({
|
|
|
441
443
|
})
|
|
442
444
|
```
|
|
443
445
|
|
|
444
|
-
:read-more{to="/docs/guide/going-further/layers"}
|
|
446
|
+
:read-more{to="/docs/4.x/guide/going-further/layers"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "plugins"
|
|
3
3
|
description: "Nuxt has a plugins system to use Vue plugins and more at the creation of your Vue application."
|
|
4
4
|
head.title: "plugins/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-plugin
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Nuxt automatically reads the files in the `app/plugins/` directory and loads them at the creation of the Vue application.
|
|
@@ -30,23 +30,23 @@ Only files at the top level of the directory (or index files within any subdirec
|
|
|
30
30
|
|
|
31
31
|
Only `foo.ts` and `bar/index.ts` would be registered.
|
|
32
32
|
|
|
33
|
-
To add plugins in subdirectories, you can use the [`app/plugins`](/docs/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
|
|
33
|
+
To add plugins in subdirectories, you can use the [`app/plugins`](/docs/4.x/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
|
|
34
34
|
|
|
35
35
|
```ts twoslash [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
37
37
|
plugins: [
|
|
38
38
|
'~/plugins/bar/baz',
|
|
39
|
-
'~/plugins/bar/foz'
|
|
40
|
-
]
|
|
39
|
+
'~/plugins/bar/foz',
|
|
40
|
+
],
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Creating Plugins
|
|
45
45
|
|
|
46
|
-
The only argument passed to a plugin is [`nuxtApp`](/docs/api/composables/use-nuxt-app).
|
|
46
|
+
The only argument passed to a plugin is [`nuxtApp`](/docs/4.x/api/composables/use-nuxt-app).
|
|
47
47
|
|
|
48
48
|
```ts twoslash [plugins/hello.ts]
|
|
49
|
-
export default defineNuxtPlugin(nuxtApp => {
|
|
49
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
50
50
|
// Doing something with nuxtApp
|
|
51
51
|
})
|
|
52
52
|
```
|
|
@@ -64,15 +64,15 @@ export default defineNuxtPlugin({
|
|
|
64
64
|
},
|
|
65
65
|
hooks: {
|
|
66
66
|
// You can directly register Nuxt app runtime hooks here
|
|
67
|
-
'app:created'() {
|
|
67
|
+
'app:created' () {
|
|
68
68
|
const nuxtApp = useNuxtApp()
|
|
69
69
|
// do something in the hook
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
},
|
|
72
72
|
env: {
|
|
73
73
|
// Set this value to `false` if you don't want the plugin to run when rendering server-only or island components.
|
|
74
|
-
islands: true
|
|
75
|
-
}
|
|
74
|
+
islands: true,
|
|
75
|
+
},
|
|
76
76
|
})
|
|
77
77
|
```
|
|
78
78
|
|
|
@@ -114,7 +114,7 @@ export default defineNuxtPlugin({
|
|
|
114
114
|
parallel: true,
|
|
115
115
|
async setup (nuxtApp) {
|
|
116
116
|
// the next plugin will be executed immediately
|
|
117
|
-
}
|
|
117
|
+
},
|
|
118
118
|
})
|
|
119
119
|
```
|
|
120
120
|
|
|
@@ -128,13 +128,13 @@ export default defineNuxtPlugin({
|
|
|
128
128
|
dependsOn: ['my-plugin'],
|
|
129
129
|
async setup (nuxtApp) {
|
|
130
130
|
// this plugin will wait for the end of `my-plugin`'s execution before it runs
|
|
131
|
-
}
|
|
131
|
+
},
|
|
132
132
|
})
|
|
133
133
|
```
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/guide/directory-structure/app/composables) as well as [utils](/docs/guide/directory-structure/app/utils) within Nuxt plugins:
|
|
137
|
+
You can use [composables](/docs/4.x/guide/directory-structure/app/composables) as well as [utils](/docs/4.x/guide/directory-structure/app/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
139
|
```ts [app/plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -153,20 +153,20 @@ Plugins are called in order sequentially and before everything else. You might u
|
|
|
153
153
|
::important
|
|
154
154
|
**If a composable depends on the Vue.js lifecycle, it won't work.** :br
|
|
155
155
|
|
|
156
|
-
Normally, Vue.js composables are bound to the current component instance while plugins are only bound to [`nuxtApp`](/docs/api/composables/use-nuxt-app) instance.
|
|
156
|
+
Normally, Vue.js composables are bound to the current component instance while plugins are only bound to [`nuxtApp`](/docs/4.x/api/composables/use-nuxt-app) instance.
|
|
157
157
|
::
|
|
158
158
|
|
|
159
159
|
## Providing Helpers
|
|
160
160
|
|
|
161
|
-
If you would like to provide a helper on the [`NuxtApp`](/docs/api/composables/use-nuxt-app) instance, return it from the plugin under a `provide` key.
|
|
161
|
+
If you would like to provide a helper on the [`NuxtApp`](/docs/4.x/api/composables/use-nuxt-app) instance, return it from the plugin under a `provide` key.
|
|
162
162
|
|
|
163
163
|
::code-group
|
|
164
164
|
```ts twoslash [plugins/hello.ts]
|
|
165
165
|
export default defineNuxtPlugin(() => {
|
|
166
166
|
return {
|
|
167
167
|
provide: {
|
|
168
|
-
hello: (msg: string) => `Hello ${msg}
|
|
169
|
-
}
|
|
168
|
+
hello: (msg: string) => `Hello ${msg}!`,
|
|
169
|
+
},
|
|
170
170
|
}
|
|
171
171
|
})
|
|
172
172
|
```
|
|
@@ -176,10 +176,10 @@ export default defineNuxtPlugin({
|
|
|
176
176
|
setup () {
|
|
177
177
|
return {
|
|
178
178
|
provide: {
|
|
179
|
-
hello: (msg: string) => `Hello ${msg}
|
|
180
|
-
}
|
|
179
|
+
hello: (msg: string) => `Hello ${msg}!`,
|
|
180
|
+
},
|
|
181
181
|
}
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
183
|
})
|
|
184
184
|
```
|
|
185
185
|
::
|
|
@@ -200,7 +200,7 @@ const { $hello } = useNuxtApp()
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
::important
|
|
203
|
-
Note that we highly recommend using [`composables`](/docs/guide/directory-structure/app/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
|
|
203
|
+
Note that we highly recommend using [`composables`](/docs/4.x/guide/directory-structure/app/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
|
|
204
204
|
::
|
|
205
205
|
|
|
206
206
|
::warning
|
|
@@ -213,7 +213,7 @@ This is due to how Vue works with refs that aren't top-level to the template. Yo
|
|
|
213
213
|
If you return your helpers from the plugin, they will be typed automatically; you'll find them typed for the return of `useNuxtApp()` and within your templates.
|
|
214
214
|
|
|
215
215
|
::note
|
|
216
|
-
If you need to use a provided helper _within_ another plugin, you can call [`useNuxtApp()`](/docs/api/composables/use-nuxt-app) to get the typed version. But in general, this should be avoided unless you are certain of the plugins' order.
|
|
216
|
+
If you need to use a provided helper _within_ another plugin, you can call [`useNuxtApp()`](/docs/4.x/api/composables/use-nuxt-app) to get the typed version. But in general, this should be avoided unless you are certain of the plugins' order.
|
|
217
217
|
::
|
|
218
218
|
|
|
219
219
|
For advanced use-cases, you can declare the type of injected properties like this:
|
|
@@ -267,8 +267,8 @@ import VueGtag, { trackRouter } from 'vue-gtag-next'
|
|
|
267
267
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
268
268
|
nuxtApp.vueApp.use(VueGtag, {
|
|
269
269
|
property: {
|
|
270
|
-
id: 'GA_MEASUREMENT_ID'
|
|
271
|
-
}
|
|
270
|
+
id: 'GA_MEASUREMENT_ID',
|
|
271
|
+
},
|
|
272
272
|
})
|
|
273
273
|
trackRouter(useRouter())
|
|
274
274
|
})
|
|
@@ -287,7 +287,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
287
287
|
getSSRProps (binding, vnode) {
|
|
288
288
|
// you can provide SSR-specific props here
|
|
289
289
|
return {}
|
|
290
|
-
}
|
|
290
|
+
},
|
|
291
291
|
})
|
|
292
292
|
})
|
|
293
293
|
```
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
title: 'utils'
|
|
3
3
|
head.title: 'utils/'
|
|
4
4
|
description: Use the utils/ directory to auto-import your utility functions throughout your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-tools
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The main purpose of the [`app/utils/` directory](/docs/guide/directory-structure/app/utils) is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
|
|
8
|
+
The main purpose of the [`app/utils/` directory](/docs/4.x/guide/directory-structure/app/utils) is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ The main purpose of the [`app/utils/` directory](/docs/guide/directory-structure
|
|
|
14
14
|
```ts twoslash [utils/index.ts]
|
|
15
15
|
export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
|
|
16
16
|
notation: 'compact',
|
|
17
|
-
maximumFractionDigits: 1
|
|
17
|
+
maximumFractionDigits: 1,
|
|
18
18
|
})
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -35,15 +35,15 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
|
35
35
|
</template>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
38
|
+
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
39
39
|
|
|
40
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
40
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
41
41
|
|
|
42
42
|
::tip
|
|
43
|
-
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/guide/directory-structure/app/composables) directory.
|
|
43
|
+
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) directory.
|
|
44
44
|
::
|
|
45
45
|
|
|
46
46
|
::important
|
|
47
47
|
These utils are only available within the Vue part of your app. :br
|
|
48
|
-
Only `server/utils` are auto-imported in the [`server/`](/docs/guide/directory-structure/server#server-utilities) directory.
|
|
48
|
+
Only `server/utils` are auto-imported in the [`server/`](/docs/4.x/guide/directory-structure/server#server-utilities) directory.
|
|
49
49
|
::
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
title: app.config.ts
|
|
3
3
|
head.title: 'app.config.ts'
|
|
4
4
|
description: Expose reactive configuration within your application with the App Config file.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-light-config
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt provides an `app.config` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
8
|
+
Nuxt provides an `app/app.config.ts` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
9
9
|
|
|
10
10
|
You can easily provide runtime app configuration using `app.config.ts` file. It can have either of `.ts`, `.js`, or `.mjs` extensions.
|
|
11
11
|
|
|
12
|
-
```ts twoslash [app.config.ts]
|
|
12
|
+
```ts twoslash [app/app.config.ts]
|
|
13
13
|
export default defineAppConfig({
|
|
14
|
-
foo: 'bar'
|
|
14
|
+
foo: 'bar',
|
|
15
15
|
})
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -20,22 +20,22 @@ Do not put any secret values inside `app.config` file. It is exposed to the user
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
When configuring a custom [`srcDir`](/docs/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
23
|
+
When configuring a custom [`srcDir`](/docs/4.x/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
## Usage
|
|
27
27
|
|
|
28
28
|
To expose config and environment variables to the rest of your app, you will need to define configuration in `app.config` file.
|
|
29
29
|
|
|
30
|
-
```ts twoslash [app.config.ts]
|
|
30
|
+
```ts twoslash [app/app.config.ts]
|
|
31
31
|
export default defineAppConfig({
|
|
32
32
|
theme: {
|
|
33
|
-
primaryColor: '#ababab'
|
|
34
|
-
}
|
|
33
|
+
primaryColor: '#ababab',
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
38
|
+
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/4.x/api/composables/use-app-config) composable.
|
|
39
39
|
|
|
40
40
|
```vue [app/pages/index.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
@@ -45,7 +45,7 @@ console.log(appConfig.theme)
|
|
|
45
45
|
</script>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
The [`updateAppConfig`](/docs/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
48
|
+
The [`updateAppConfig`](/docs/4.x/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
49
49
|
|
|
50
50
|
```vue [app/pages/index.vue]
|
|
51
51
|
<script setup>
|
|
@@ -59,7 +59,7 @@ console.log(appConfig) // { foo: 'baz' }
|
|
|
59
59
|
</script>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
::read-more{to="/docs/api/utils/update-app-config"}
|
|
62
|
+
::read-more{to="/docs/4.x/api/utils/update-app-config"}
|
|
63
63
|
Read more about the `updateAppConfig` utility.
|
|
64
64
|
::
|
|
65
65
|
|
|
@@ -90,7 +90,7 @@ export {}
|
|
|
90
90
|
|
|
91
91
|
### App Config Output
|
|
92
92
|
|
|
93
|
-
If you want to type the result of calling [`useAppConfig()`](/docs/api/composables/use-app-config), then you will want to extend `AppConfig`.
|
|
93
|
+
If you want to type the result of calling [`useAppConfig()`](/docs/4.x/api/composables/use-app-config), then you will want to extend `AppConfig`.
|
|
94
94
|
|
|
95
95
|
::warning
|
|
96
96
|
Be careful when typing `AppConfig` as you will overwrite the types Nuxt infers from your actually defined app config.
|
|
@@ -114,7 +114,7 @@ export {}
|
|
|
114
114
|
|
|
115
115
|
## Merging Strategy
|
|
116
116
|
|
|
117
|
-
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/getting-started/layers) of your application.
|
|
117
|
+
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/4.x/getting-started/layers) of your application.
|
|
118
118
|
|
|
119
119
|
This strategy is implemented using a [Function Merger](https://github.com/unjs/defu#function-merger), which allows defining a custom merging strategy for every key in `app.config` that has an array as value.
|
|
120
120
|
|
|
@@ -126,14 +126,14 @@ Here's an example of how you can use:
|
|
|
126
126
|
|
|
127
127
|
::code-group
|
|
128
128
|
|
|
129
|
-
```ts twoslash [layer/app.config.ts]
|
|
129
|
+
```ts twoslash [layer/app/app.config.ts]
|
|
130
130
|
export default defineAppConfig({
|
|
131
131
|
// Default array value
|
|
132
132
|
array: ['hello'],
|
|
133
133
|
})
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
```ts twoslash [app.config.ts]
|
|
136
|
+
```ts twoslash [app/app.config.ts]
|
|
137
137
|
export default defineAppConfig({
|
|
138
138
|
// Overwrite default array value by using a merger function
|
|
139
139
|
array: () => ['bonjour'],
|
|
@@ -157,9 +157,9 @@ While it's possible to use Vite plugins in the Nitro config as a workaround, thi
|
|
|
157
157
|
export default defineNuxtConfig({
|
|
158
158
|
nitro: {
|
|
159
159
|
vite: {
|
|
160
|
-
plugins: [vue()]
|
|
161
|
-
}
|
|
162
|
-
}
|
|
160
|
+
plugins: [vue()],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
163
|
})
|
|
164
164
|
```
|
|
165
165
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "app.vue"
|
|
3
3
|
description: "The app.vue file is the main component of your Nuxt application."
|
|
4
4
|
head.title: "app.vue"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-vue
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::tip
|
|
@@ -13,7 +13,7 @@ If you have a `app/pages/` directory, the `app.vue` file is optional. Nuxt will
|
|
|
13
13
|
|
|
14
14
|
### Minimal Usage
|
|
15
15
|
|
|
16
|
-
With Nuxt, the [`app/pages/`](/docs/guide/directory-structure/app/pages) directory is optional. If it is not present, Nuxt will not include the [vue-router](https://router.vuejs.org) dependency. This is useful when building a landing page or an application that does not require routing.
|
|
16
|
+
With Nuxt, the [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory is optional. If it is not present, Nuxt will not include the [vue-router](https://router.vuejs.org) dependency. This is useful when building a landing page or an application that does not require routing.
|
|
17
17
|
|
|
18
18
|
```vue [app/app.vue]
|
|
19
19
|
<template>
|
|
@@ -21,11 +21,11 @@ With Nuxt, the [`app/pages/`](/docs/guide/directory-structure/app/pages) directo
|
|
|
21
21
|
</template>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
:link-example{to="/docs/examples/hello-world"}
|
|
24
|
+
:link-example{to="/docs/4.x/examples/hello-world"}
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`app/pages/`](/docs/guide/directory-structure/app/pages) directory, you need to use the [`<NuxtPage>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
28
|
+
When you have a [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory, you need to use the [`<NuxtPage>`](/docs/4.x/api/components/nuxt-page) component to display the current page:
|
|
29
29
|
|
|
30
30
|
```vue [app/app.vue]
|
|
31
31
|
<template>
|
|
@@ -51,13 +51,13 @@ You can also define the common structure of your application directly in `app.vu
|
|
|
51
51
|
Remember that `app.vue` acts as the main component of your Nuxt application. Anything you add to it (JS and CSS) will be global and included in every page.
|
|
52
52
|
::
|
|
53
53
|
|
|
54
|
-
::read-more{to="/docs/guide/directory-structure/app/pages"}
|
|
54
|
+
::read-more{to="/docs/4.x/guide/directory-structure/app/pages"}
|
|
55
55
|
Learn more about how to structure your pages using the `app/pages/` directory.
|
|
56
56
|
::
|
|
57
57
|
|
|
58
58
|
### Usage with Layouts
|
|
59
59
|
|
|
60
|
-
When your application requires different layouts for different pages, you can use the `app/layouts/` directory with the [`<NuxtLayout>`](/docs/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
60
|
+
When your application requires different layouts for different pages, you can use the `app/layouts/` directory with the [`<NuxtLayout>`](/docs/4.x/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
61
61
|
|
|
62
62
|
```vue [app/app.vue]
|
|
63
63
|
<template>
|
|
@@ -67,6 +67,6 @@ When your application requires different layouts for different pages, you can us
|
|
|
67
67
|
</template>
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
::read-more{to="/docs/guide/directory-structure/app/layouts"}
|
|
70
|
+
::read-more{to="/docs/4.x/guide/directory-structure/app/layouts"}
|
|
71
71
|
Learn more about how to structure your layouts using the `app/layouts/` directory.
|
|
72
72
|
::
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "error.vue"
|
|
3
3
|
description: "The error.vue file is the error page in your Nuxt application."
|
|
4
4
|
head.title: "error.vue"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-vue
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
During the lifespan of your application, some errors may appear unexpectedly at runtime. In such case, we can use the `error.vue` file to override the default error files and display the error nicely.
|
|
@@ -12,7 +12,7 @@ During the lifespan of your application, some errors may appear unexpectedly at
|
|
|
12
12
|
import type { NuxtError } from '#app'
|
|
13
13
|
|
|
14
14
|
const props = defineProps({
|
|
15
|
-
error: Object as () => NuxtError
|
|
15
|
+
error: Object as () => NuxtError,
|
|
16
16
|
})
|
|
17
17
|
</script>
|
|
18
18
|
|
|
@@ -25,14 +25,14 @@ const props = defineProps({
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
::note
|
|
28
|
-
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
28
|
+
Although it is called an 'error page' it's not a route and shouldn't be placed in your `~/pages` directory. For the same reason, you shouldn't use `definePageMeta` within this page. That being said, you can still use layouts in the error file, by utilizing the [`NuxtLayout`](/docs/4.x/api/components/nuxt-layout) component and specifying the name of the layout.
|
|
29
29
|
::
|
|
30
30
|
|
|
31
31
|
The error page has a single prop - `error` which contains an error for you to handle.
|
|
32
32
|
|
|
33
33
|
The `error` object provides the following fields:
|
|
34
34
|
```ts
|
|
35
|
-
{
|
|
35
|
+
interface NuxtError {
|
|
36
36
|
statusCode: number
|
|
37
37
|
fatal: boolean
|
|
38
38
|
unhandled: boolean
|
|
@@ -49,7 +49,7 @@ throw createError({
|
|
|
49
49
|
statusCode: 404,
|
|
50
50
|
statusMessage: 'Page Not Found',
|
|
51
51
|
data: {
|
|
52
|
-
myCustomField: true
|
|
53
|
-
}
|
|
52
|
+
myCustomField: true,
|
|
53
|
+
},
|
|
54
54
|
})
|
|
55
55
|
```
|