@nuxt/docs 4.0.3 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +1 -1
- package/1.getting-started/03.configuration.md +2 -2
- package/1.getting-started/04.views.md +15 -15
- package/1.getting-started/05.assets.md +6 -6
- package/1.getting-started/06.styling.md +8 -8
- package/1.getting-started/07.routing.md +7 -7
- package/1.getting-started/08.seo-meta.md +9 -9
- package/1.getting-started/09.transitions.md +15 -15
- package/1.getting-started/10.data-fetching.md +9 -9
- package/1.getting-started/11.state-management.md +9 -9
- package/1.getting-started/12.error-handling.md +1 -1
- package/1.getting-started/14.layers.md +23 -2
- package/1.getting-started/15.prerendering.md +2 -2
- package/1.getting-started/17.testing.md +72 -19
- package/1.getting-started/18.upgrade.md +7 -7
- package/2.guide/1.concepts/1.auto-imports.md +6 -6
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +6 -6
- package/2.guide/1.concepts/2.vuejs-development.md +3 -3
- package/2.guide/1.concepts/3.rendering.md +2 -2
- package/2.guide/1.concepts/8.typescript.md +1 -1
- package/2.guide/2.directory-structure/1.app/1.components.md +18 -18
- package/2.guide/2.directory-structure/1.app/1.composables.md +11 -11
- package/2.guide/2.directory-structure/1.app/1.layouts.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.middleware.md +41 -3
- package/2.guide/2.directory-structure/1.app/1.pages.md +16 -16
- package/2.guide/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/2.directory-structure/1.app/3.app-config.md +2 -2
- package/2.guide/2.directory-structure/1.app/3.app.md +12 -12
- package/2.guide/2.directory-structure/1.content.md +2 -2
- package/2.guide/2.directory-structure/1.public.md +1 -1
- package/2.guide/2.directory-structure/1.server.md +3 -3
- package/2.guide/2.directory-structure/1.shared.md +3 -3
- package/2.guide/2.directory-structure/2.nuxtrc.md +4 -0
- package/2.guide/3.going-further/1.experimental-features.md +38 -5
- package/2.guide/3.going-further/10.runtime-config.md +2 -2
- package/2.guide/3.going-further/2.hooks.md +1 -1
- package/2.guide/3.going-further/3.modules.md +50 -1
- package/2.guide/3.going-further/6.nuxt-app.md +2 -2
- package/2.guide/3.going-further/7.layers.md +34 -10
- package/2.guide/3.going-further/9.debugging.md +2 -1
- package/2.guide/4.recipes/1.custom-routing.md +1 -1
- package/2.guide/4.recipes/2.vite-plugin.md +1 -1
- package/2.guide/4.recipes/3.custom-usefetch.md +4 -4
- package/2.guide/4.recipes/4.sessions-and-authentication.md +4 -4
- package/2.guide/5.best-practices/performance.md +2 -2
- package/3.api/1.components/1.client-only.md +2 -2
- package/3.api/1.components/1.dev-only.md +1 -1
- package/3.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +2 -2
- package/3.api/1.components/2.nuxt-page.md +8 -8
- package/3.api/1.components/3.nuxt-layout.md +13 -13
- package/3.api/1.components/4.nuxt-link.md +9 -9
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/7.nuxt-welcome.md +1 -1
- package/3.api/2.composables/on-prehydrate.md +1 -1
- package/3.api/2.composables/use-async-data.md +3 -3
- package/3.api/2.composables/use-cookie.md +1 -1
- package/3.api/2.composables/use-fetch.md +2 -2
- package/3.api/2.composables/use-lazy-async-data.md +1 -1
- package/3.api/2.composables/use-lazy-fetch.md +1 -1
- package/3.api/2.composables/use-nuxt-app.md +7 -7
- package/3.api/2.composables/use-nuxt-data.md +4 -4
- package/3.api/2.composables/use-preview-mode.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +1 -1
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +3 -3
- package/3.api/2.composables/use-route-announcer.md +1 -1
- package/3.api/2.composables/use-route.md +37 -2
- package/3.api/2.composables/use-router.md +5 -5
- package/3.api/2.composables/use-runtime-config.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +3 -3
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/3.utils/$fetch.md +4 -4
- package/3.api/3.utils/abort-navigation.md +4 -4
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +2 -2
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-nuxt-component.md +2 -2
- package/3.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/3.api/3.utils/define-page-meta.md +12 -12
- package/3.api/3.utils/define-route-rules.md +1 -1
- package/3.api/3.utils/navigate-to.md +1 -1
- package/3.api/3.utils/on-nuxt-ready.md +1 -1
- package/3.api/3.utils/refresh-cookie.md +1 -1
- package/3.api/3.utils/refresh-nuxt-data.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/4.commands/add.md +7 -7
- package/3.api/4.commands/init.md +2 -1
- package/3.api/5.kit/1.modules.md +68 -0
- package/3.api/5.kit/16.layers.md +220 -0
- package/3.api/5.kit/7.pages.md +1 -1
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +1 -1
- package/3.api/6.nuxt-config.md +22 -19
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +3 -3
- package/6.bridge/6.meta.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/7.migration/3.auto-imports.md +1 -1
- package/7.migration/5.plugins-and-middleware.md +2 -2
- package/7.migration/6.pages-and-layouts.md +8 -8
- package/7.migration/7.component-options.md +4 -4
- package/7.migration/8.runtime-config.md +1 -1
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ You can now migrate to the Nuxt 3 plugins API, which is slightly different in fo
|
|
|
9
9
|
|
|
10
10
|
Plugins now take only one argument (`nuxtApp`). You can find out more in [the docs](/docs/guide/directory-structure/plugins).
|
|
11
11
|
|
|
12
|
-
```js [plugins/hello.ts]
|
|
12
|
+
```js [app/plugins/hello.ts]
|
|
13
13
|
export default defineNuxtPlugin(nuxtApp => {
|
|
14
14
|
nuxtApp.provide('injected', () => 'my injected function')
|
|
15
15
|
// now available on `nuxtApp.$injected`
|
|
@@ -28,7 +28,7 @@ Although a compatibility interface is provided via `nuxtApp.vueApp` you should a
|
|
|
28
28
|
|
|
29
29
|
You can now migrate to the Nuxt 3 middleware API, which is slightly different in format from Nuxt 2.
|
|
30
30
|
|
|
31
|
-
Middleware now take only two argument (`to`, `from`). You can find out more in [the docs](/docs/guide/directory-structure/middleware).
|
|
31
|
+
Middleware now take only two argument (`to`, `from`). You can find out more in [the docs](/docs/guide/directory-structure/app/middleware).
|
|
32
32
|
|
|
33
33
|
```ts twoslash
|
|
34
34
|
export default defineNuxtRouteMiddleware((to) => {
|
|
@@ -39,7 +39,7 @@ export default defineNuxtRouteMiddleware((to) => {
|
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
::important
|
|
42
|
-
Use of `defineNuxtRouteMiddleware` is not supported outside of the middleware directory.
|
|
42
|
+
Use of `defineNuxtRouteMiddleware` is not supported outside of the `app/middleware` directory.
|
|
43
43
|
::
|
|
44
44
|
|
|
45
45
|
## definePageMeta
|
package/6.bridge/6.meta.md
CHANGED
|
@@ -106,7 +106,7 @@ Possible breaking change: `head` receives the nuxt app but cannot access the com
|
|
|
106
106
|
|
|
107
107
|
If you want to use a function (for full control), then this cannot be set in your nuxt.config, and it is recommended instead to set it within your `/layouts` directory.
|
|
108
108
|
|
|
109
|
-
```vue [layouts/default.vue]
|
|
109
|
+
```vue [app/layouts/default.vue]
|
|
110
110
|
<script setup lang="ts">
|
|
111
111
|
useHead({
|
|
112
112
|
titleTemplate: (titleChunk) => {
|
|
@@ -227,7 +227,7 @@ export const useMainStore = defineStore('main', {
|
|
|
227
227
|
|
|
228
228
|
Create a [plugin](/docs/guide/directory-structure/plugins) file to globalize your store:
|
|
229
229
|
|
|
230
|
-
```ts [plugins/pinia.ts]
|
|
230
|
+
```ts [app/plugins/pinia.ts]
|
|
231
231
|
import { useMainStore } from '~/store'
|
|
232
232
|
|
|
233
233
|
export default defineNuxtPlugin(({ $pinia }) => {
|
|
@@ -243,7 +243,7 @@ If you want to keep using Vuex, you can manually migrate to Vuex 4 following [th
|
|
|
243
243
|
|
|
244
244
|
Once it's done you will need to add the following plugin to your Nuxt app:
|
|
245
245
|
|
|
246
|
-
```ts [plugins/vuex.ts]
|
|
246
|
+
```ts [app/plugins/vuex.ts]
|
|
247
247
|
import store from '~/store'
|
|
248
248
|
|
|
249
249
|
export default defineNuxtPlugin(nuxtApp => {
|
|
@@ -11,7 +11,7 @@ In the rest of the migration documentation, you will notice that key Nuxt and Vu
|
|
|
11
11
|
|
|
12
12
|
## Migration
|
|
13
13
|
|
|
14
|
-
1. If you have been using `@nuxt/components` in Nuxt 2, you can remove `components: true` in your `nuxt.config`. If you had a more complex setup, then note that the component options have changed somewhat. See the [components documentation](/docs/guide/directory-structure/components) for more information.
|
|
14
|
+
1. If you have been using `@nuxt/components` in Nuxt 2, you can remove `components: true` in your `nuxt.config`. If you had a more complex setup, then note that the component options have changed somewhat. See the [components documentation](/docs/guide/directory-structure/app/components) for more information.
|
|
15
15
|
|
|
16
16
|
::tip
|
|
17
17
|
You can look at `.nuxt/types/components.d.ts` and `.nuxt/types/imports.d.ts` to see how Nuxt has resolved your components and composable auto-imports.
|
|
@@ -40,7 +40,7 @@ Read more about the format of `nuxtApp`.
|
|
|
40
40
|
### Migration
|
|
41
41
|
|
|
42
42
|
1. Migrate your plugins to use the `defineNuxtPlugin` helper function.
|
|
43
|
-
2. Remove any entries in your `nuxt.config` plugins array that are located in your `plugins/` folder. All files in this directory at the top level (and any index files in any subdirectories) will be automatically registered. Instead of setting `mode` to `client` or `server`, you can indicate this in the file name. For example, `~/plugins/my-plugin.client.ts` will only be loaded on client-side.
|
|
43
|
+
2. Remove any entries in your `nuxt.config` plugins array that are located in your `app/plugins/` folder. All files in this directory at the top level (and any index files in any subdirectories) will be automatically registered. Instead of setting `mode` to `client` or `server`, you can indicate this in the file name. For example, `~/plugins/my-plugin.client.ts` will only be loaded on client-side.
|
|
44
44
|
|
|
45
45
|
## Route Middleware
|
|
46
46
|
|
|
@@ -72,7 +72,7 @@ Much like Nuxt 2, route middleware placed in your `~/middleware` folder is autom
|
|
|
72
72
|
|
|
73
73
|
`navigateTo` is one of a number of route helper functions.
|
|
74
74
|
|
|
75
|
-
:read-more{to="/docs/guide/directory-structure/middleware"}
|
|
75
|
+
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
76
76
|
|
|
77
77
|
### Migration
|
|
78
78
|
|
|
@@ -25,14 +25,14 @@ Consider creating an `app.vue` file and including any logic that needs to run on
|
|
|
25
25
|
|
|
26
26
|
If you are using layouts in your app for multiple pages, there is only a slight change required.
|
|
27
27
|
|
|
28
|
-
In Nuxt 2, the `<Nuxt>` component is used within a layout to render the current page. In Nuxt 3, layouts use slots instead, so you will have to replace that component with a `<slot />`. This also allows advanced use cases with named and scoped slots. [Read more about layouts](/docs/guide/directory-structure/layouts).
|
|
28
|
+
In Nuxt 2, the `<Nuxt>` component is used within a layout to render the current page. In Nuxt 3, layouts use slots instead, so you will have to replace that component with a `<slot />`. This also allows advanced use cases with named and scoped slots. [Read more about layouts](/docs/guide/directory-structure/app/layouts).
|
|
29
29
|
|
|
30
|
-
You will also need to change how you define the layout used by a page using the `definePageMeta` compiler macro. Layouts will be kebab-cased. So `layouts/customLayout.vue` becomes `custom-layout` when referenced in your page.
|
|
30
|
+
You will also need to change how you define the layout used by a page using the `definePageMeta` compiler macro. Layouts will be kebab-cased. So `app/layouts/customLayout.vue` becomes `custom-layout` when referenced in your page.
|
|
31
31
|
|
|
32
32
|
### Migration
|
|
33
33
|
|
|
34
34
|
1. Replace `<Nuxt />` with `<slot />`
|
|
35
|
-
```diff [layouts/custom.vue]
|
|
35
|
+
```diff [app/layouts/custom.vue]
|
|
36
36
|
<template>
|
|
37
37
|
<div id="app-layout">
|
|
38
38
|
<main>
|
|
@@ -43,7 +43,7 @@ You will also need to change how you define the layout used by a page using the
|
|
|
43
43
|
</template>
|
|
44
44
|
```
|
|
45
45
|
2. Use [`definePageMeta`](/docs/api/utils/define-page-meta) to select the layout used by your page.
|
|
46
|
-
```diff [pages/index.vue]
|
|
46
|
+
```diff [app/pages/index.vue]
|
|
47
47
|
+ <script setup>
|
|
48
48
|
+ definePageMeta({
|
|
49
49
|
+ layout: 'custom'
|
|
@@ -54,7 +54,7 @@ You will also need to change how you define the layout used by a page using the
|
|
|
54
54
|
- }
|
|
55
55
|
</script>
|
|
56
56
|
```
|
|
57
|
-
3. Move `~/layouts/_error.vue` to `~/error.vue`. See [the error handling docs](/docs/getting-started/error-handling). If you want to ensure that this page uses a layout, you can use [`<NuxtLayout>`](/docs/guide/directory-structure/layouts) directly within `error.vue`:
|
|
57
|
+
3. Move `~/layouts/_error.vue` to `~/error.vue`. See [the error handling docs](/docs/getting-started/error-handling). If you want to ensure that this page uses a layout, you can use [`<NuxtLayout>`](/docs/guide/directory-structure/app/layouts) directly within `error.vue`:
|
|
58
58
|
```vue [error.vue]
|
|
59
59
|
<template>
|
|
60
60
|
<div>
|
|
@@ -67,11 +67,11 @@ You will also need to change how you define the layout used by a page using the
|
|
|
67
67
|
|
|
68
68
|
## Pages
|
|
69
69
|
|
|
70
|
-
Nuxt 3 ships with an optional `vue-router` integration triggered by the existence of a [`pages/`](/docs/guide/directory-structure/pages) directory in your source directory. If you only have a single page, you may consider instead moving it to `app.vue` for a lighter build.
|
|
70
|
+
Nuxt 3 ships with an optional `vue-router` integration triggered by the existence of a [`app/pages/`](/docs/guide/directory-structure/app/pages) directory in your source directory. If you only have a single page, you may consider instead moving it to `app.vue` for a lighter build.
|
|
71
71
|
|
|
72
72
|
### Dynamic Routes
|
|
73
73
|
|
|
74
|
-
The format for defining dynamic routes in Nuxt 3 is slightly different from Nuxt 2, so you may need to rename some of the files within `pages/`.
|
|
74
|
+
The format for defining dynamic routes in Nuxt 3 is slightly different from Nuxt 2, so you may need to rename some of the files within `app/pages/`.
|
|
75
75
|
|
|
76
76
|
1. Where you previously used `_id` to define a dynamic route parameter you now use `[id]`.
|
|
77
77
|
2. Where you previously used `_.vue` to define a catch-all route, you now use `[...slug].vue`.
|
|
@@ -84,7 +84,7 @@ In Nuxt 2, you will have defined any nested routes (with parent and child compon
|
|
|
84
84
|
|
|
85
85
|
If you were passing a custom page key or keep-alive props to `<Nuxt>`, you will now use `definePageMeta` to set these options.
|
|
86
86
|
|
|
87
|
-
:read-more{to="/docs/guide/directory-structure/pages#special-metadata"}
|
|
87
|
+
:read-more{to="/docs/guide/directory-structure/app/pages#special-metadata"}
|
|
88
88
|
|
|
89
89
|
### Page and Layout Transitions
|
|
90
90
|
|
|
@@ -73,7 +73,7 @@ Despite the names, [`useFetch`](/docs/api/composables/use-fetch) is not a direct
|
|
|
73
73
|
|
|
74
74
|
You can now define a key within the [`definePageMeta`](/docs/api/utils/define-page-meta) compiler macro.
|
|
75
75
|
|
|
76
|
-
```diff [pages/index.vue]
|
|
76
|
+
```diff [app/pages/index.vue]
|
|
77
77
|
- <script>
|
|
78
78
|
- export default {
|
|
79
79
|
- key: 'index'
|
|
@@ -106,7 +106,7 @@ This feature is not yet supported in Nuxt 3.
|
|
|
106
106
|
This feature is not yet supported in Nuxt 3. If you want to overwrite the default scroll behavior of `vue-router`, you can do so in an `~/router.options.ts` (see [docs](/docs/guide/recipes/custom-routing#router-options)) for more info.
|
|
107
107
|
Similar to `key`, specify it within the [`definePageMeta`](/docs/api/utils/define-page-meta) compiler macro.
|
|
108
108
|
|
|
109
|
-
```diff [pages/index.vue]
|
|
109
|
+
```diff [app/pages/index.vue]
|
|
110
110
|
- <script>
|
|
111
111
|
- export default {
|
|
112
112
|
- scrollToTop: false
|
|
@@ -126,7 +126,7 @@ Similar to `key`, specify it within the [`definePageMeta`](/docs/api/utils/defin
|
|
|
126
126
|
|
|
127
127
|
The validate hook in Nuxt 3 only accepts a single argument, the `route`. Just as in Nuxt 2, you can return a boolean value. If you return false and another match can't be found, this will mean a 404. You can also directly return an object with `statusCode`/`statusMessage` to respond immediately with an error (other matches will not be checked).
|
|
128
128
|
|
|
129
|
-
```diff [pages/users/[id\\].vue]
|
|
129
|
+
```diff [app/pages/users/[id\\].vue]
|
|
130
130
|
- <script>
|
|
131
131
|
- export default {
|
|
132
132
|
- async validate({ params }) {
|
|
@@ -147,7 +147,7 @@ The validate hook in Nuxt 3 only accepts a single argument, the `route`. Just as
|
|
|
147
147
|
|
|
148
148
|
This is not supported in Nuxt 3. Instead, you can directly use a watcher to trigger refetching data.
|
|
149
149
|
|
|
150
|
-
```vue [pages/users/[id\\].vue]
|
|
150
|
+
```vue [app/pages/users/[id\\].vue]
|
|
151
151
|
<script setup lang="ts">
|
|
152
152
|
const route = useRoute()
|
|
153
153
|
const { data, refresh } = await useFetch('/api/user')
|