@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
|
@@ -13,7 +13,7 @@ For best performance, components placed in this directory will be automatically
|
|
|
13
13
|
|
|
14
14
|
Layouts are enabled by adding [`<NuxtLayout>`](/docs/api/components/nuxt-layout) to your [`app.vue`](/docs/guide/directory-structure/app):
|
|
15
15
|
|
|
16
|
-
```vue [app.vue]
|
|
16
|
+
```vue [app/app.vue]
|
|
17
17
|
<template>
|
|
18
18
|
<NuxtLayout>
|
|
19
19
|
<NuxtPage />
|
|
@@ -30,7 +30,7 @@ The layout name is normalized to kebab-case, so `someLayout` becomes `some-layou
|
|
|
30
30
|
::
|
|
31
31
|
|
|
32
32
|
::note
|
|
33
|
-
If no layout is specified, `layouts/default.vue` will be used.
|
|
33
|
+
If no layout is specified, `app/layouts/default.vue` will be used.
|
|
34
34
|
::
|
|
35
35
|
|
|
36
36
|
::important
|
|
@@ -45,7 +45,7 @@ Unlike other components, your layouts must have a single root element to allow N
|
|
|
45
45
|
|
|
46
46
|
Add a `~/layouts/default.vue`:
|
|
47
47
|
|
|
48
|
-
```vue [layouts/default.vue]
|
|
48
|
+
```vue [app/layouts/default.vue]
|
|
49
49
|
<template>
|
|
50
50
|
<div>
|
|
51
51
|
<p>Some default layout content shared across all pages</p>
|
|
@@ -74,13 +74,13 @@ definePageMeta({
|
|
|
74
74
|
</script>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
::read-more{to="/docs/guide/directory-structure/pages#page-metadata"}
|
|
77
|
+
::read-more{to="/docs/guide/directory-structure/app/pages#page-metadata"}
|
|
78
78
|
Learn more about `definePageMeta`.
|
|
79
79
|
::
|
|
80
80
|
|
|
81
81
|
You can directly override the default layout for all pages using the `name` property of [`<NuxtLayout>`](/docs/api/components/nuxt-layout):
|
|
82
82
|
|
|
83
|
-
```vue [app.vue]
|
|
83
|
+
```vue [app/app.vue]
|
|
84
84
|
<script setup lang="ts">
|
|
85
85
|
// You might choose this based on an API call or logged-in status
|
|
86
86
|
const layout = "custom";
|
|
@@ -140,7 +140,7 @@ If you are using pages, you can take full control by setting `layout: false` and
|
|
|
140
140
|
|
|
141
141
|
::code-group
|
|
142
142
|
|
|
143
|
-
```vue [pages/index.vue]
|
|
143
|
+
```vue [app/pages/index.vue]
|
|
144
144
|
<script setup lang="ts">
|
|
145
145
|
definePageMeta({
|
|
146
146
|
layout: false,
|
|
@@ -158,7 +158,7 @@ definePageMeta({
|
|
|
158
158
|
</template>
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
```vue [layouts/custom.vue]
|
|
161
|
+
```vue [app/layouts/custom.vue]
|
|
162
162
|
<template>
|
|
163
163
|
<div>
|
|
164
164
|
<header>
|
|
@@ -10,8 +10,8 @@ Nuxt provides a customizable **route middleware** framework you can use througho
|
|
|
10
10
|
There are three kinds of route middleware:
|
|
11
11
|
|
|
12
12
|
1. Anonymous (or inline) route middleware are defined directly within the page.
|
|
13
|
-
2. Named route middleware, placed in the `middleware/` and automatically loaded via asynchronous import when used on a page.
|
|
14
|
-
3. Global route middleware, placed in the `middleware/` with a `.global` suffix and is run on every route change.
|
|
13
|
+
2. Named route middleware, placed in the `app/middleware/` and automatically loaded via asynchronous import when used on a page.
|
|
14
|
+
3. Global route middleware, placed in the `app/middleware/` with a `.global` suffix and is run on every route change.
|
|
15
15
|
|
|
16
16
|
The first two kinds of route middleware can be defined in [`definePageMeta`](/docs/api/utils/define-page-meta).
|
|
17
17
|
|
|
@@ -74,7 +74,7 @@ Middleware runs in the following order:
|
|
|
74
74
|
|
|
75
75
|
For example, assuming you have the following middleware and component:
|
|
76
76
|
|
|
77
|
-
```bash [middleware/ directory]
|
|
77
|
+
```bash [app/middleware/ directory]
|
|
78
78
|
-| middleware/
|
|
79
79
|
---| analytics.global.ts
|
|
80
80
|
---| setup.global.ts
|
|
@@ -142,6 +142,44 @@ This is true even if you throw an error in your middleware on the server, and an
|
|
|
142
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.
|
|
143
143
|
::
|
|
144
144
|
|
|
145
|
+
## Accessing Route in Middleware
|
|
146
|
+
|
|
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.
|
|
148
|
+
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
|
+
|
|
150
|
+
::warning
|
|
151
|
+
Sometimes, you might call a composable that uses `useRoute()` internally, which can trigger this warning even if there is no direct call in your middleware.
|
|
152
|
+
This leads to the **same issue as above**, so you should structure your functions to accept the route as an argument instead when they are used in middleware.
|
|
153
|
+
::
|
|
154
|
+
|
|
155
|
+
::code-group
|
|
156
|
+
```ts twoslash [middleware/access-route.ts]
|
|
157
|
+
// @errors: 2304
|
|
158
|
+
export default defineNuxtRouteMiddleware(to => {
|
|
159
|
+
// passing the route to the function to avoid calling `useRoute()` in middleware
|
|
160
|
+
doSomethingWithRoute(to)
|
|
161
|
+
|
|
162
|
+
// ❌ this will output a warning and is NOT recommended
|
|
163
|
+
callsRouteInternally()
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```ts twoslash [utils/handle-route.ts]
|
|
168
|
+
// providing the route as an argument so that it can be used in middleware correctly
|
|
169
|
+
export function doSomethingWithRoute(route = useRoute()) {
|
|
170
|
+
// ...
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
```ts twoslash [utils/dont-do-this.ts]
|
|
174
|
+
// ❌ this function is not suitable for use in middleware
|
|
175
|
+
export function callsRouteInternally() {
|
|
176
|
+
const route = useRoute()
|
|
177
|
+
// ...
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
::
|
|
182
|
+
|
|
145
183
|
## Adding Middleware Dynamically
|
|
146
184
|
|
|
147
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.
|
|
@@ -17,7 +17,7 @@ Nuxt will automatically create a route for every page in your `~/pages/` directo
|
|
|
17
17
|
|
|
18
18
|
::code-group
|
|
19
19
|
|
|
20
|
-
```vue [pages/index.vue]
|
|
20
|
+
```vue [app/pages/index.vue]
|
|
21
21
|
<template>
|
|
22
22
|
<h1>Index page</h1>
|
|
23
23
|
</template>
|
|
@@ -44,11 +44,11 @@ export default defineComponent({
|
|
|
44
44
|
|
|
45
45
|
::
|
|
46
46
|
|
|
47
|
-
The `pages/index.vue` file will be mapped to the `/` route of your application.
|
|
47
|
+
The `app/pages/index.vue` file will be mapped to the `/` route of your application.
|
|
48
48
|
|
|
49
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:
|
|
50
50
|
|
|
51
|
-
```vue [app.vue]
|
|
51
|
+
```vue [app/app.vue]
|
|
52
52
|
<template>
|
|
53
53
|
<div>
|
|
54
54
|
<!-- Markup shared across all pages, ex: NavBar -->
|
|
@@ -65,7 +65,7 @@ Here are some examples to illustrate what a page with a single root element look
|
|
|
65
65
|
|
|
66
66
|
::code-group
|
|
67
67
|
|
|
68
|
-
```vue [pages/working.vue]
|
|
68
|
+
```vue [app/pages/working.vue]
|
|
69
69
|
<template>
|
|
70
70
|
<div>
|
|
71
71
|
<!-- This page correctly has only one single root element -->
|
|
@@ -74,14 +74,14 @@ Here are some examples to illustrate what a page with a single root element look
|
|
|
74
74
|
</template>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
```vue [pages/bad-1.vue]
|
|
77
|
+
```vue [app/pages/bad-1.vue]
|
|
78
78
|
<template>
|
|
79
79
|
<!-- This page will not render when route changes during client side navigation, because of this comment -->
|
|
80
80
|
<div>Page content</div>
|
|
81
81
|
</template>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
```vue [pages/bad-2.vue]
|
|
84
|
+
```vue [app/pages/bad-2.vue]
|
|
85
85
|
<template>
|
|
86
86
|
<div>This page</div>
|
|
87
87
|
<div>Has more than one root element</div>
|
|
@@ -106,7 +106,7 @@ If you want a parameter to be _optional_, you must enclose it in double square b
|
|
|
106
106
|
|
|
107
107
|
Given the example above, you can access group/id within your component via the `$route` object:
|
|
108
108
|
|
|
109
|
-
```vue [pages/users-[group\\]/[id\\].vue]
|
|
109
|
+
```vue [app/pages/users-[group\\]/[id\\].vue]
|
|
110
110
|
<template>
|
|
111
111
|
<p>{{ $route.params.group }} - {{ $route.params.id }}</p>
|
|
112
112
|
</template>
|
|
@@ -140,7 +140,7 @@ Named parent routes will take priority over nested dynamic routes. For the `/foo
|
|
|
140
140
|
|
|
141
141
|
If you need a catch-all route, you create it by using a file named like `[...slug].vue`. This will match _all_ routes under that path.
|
|
142
142
|
|
|
143
|
-
```vue [pages/[...slug\\].vue]
|
|
143
|
+
```vue [app/pages/[...slug\\].vue]
|
|
144
144
|
<template>
|
|
145
145
|
<p>{{ $route.params.slug }}</p>
|
|
146
146
|
</template>
|
|
@@ -184,7 +184,7 @@ This file tree will generate these routes:
|
|
|
184
184
|
]
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
To display the `child.vue` component, you have to insert the `<NuxtPage>` component inside `pages/parent.vue`:
|
|
187
|
+
To display the `child.vue` component, you have to insert the `<NuxtPage>` component inside `app/pages/parent.vue`:
|
|
188
188
|
|
|
189
189
|
```vue {}[pages/parent.vue]
|
|
190
190
|
<template>
|
|
@@ -315,7 +315,7 @@ You can set a default value for this property [in your `nuxt.config`](/docs/api/
|
|
|
315
315
|
|
|
316
316
|
#### `layout`
|
|
317
317
|
|
|
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).
|
|
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).
|
|
319
319
|
|
|
320
320
|
#### `layoutTransition` and `pageTransition`
|
|
321
321
|
|
|
@@ -325,7 +325,7 @@ You can set default values for these properties [in your `nuxt.config`](/docs/ap
|
|
|
325
325
|
|
|
326
326
|
#### `middleware`
|
|
327
327
|
|
|
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).
|
|
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).
|
|
329
329
|
|
|
330
330
|
#### `name`
|
|
331
331
|
|
|
@@ -337,7 +337,7 @@ You may define a path matcher, if you have a more complex pattern than can be ex
|
|
|
337
337
|
|
|
338
338
|
#### `props`
|
|
339
339
|
|
|
340
|
-
Allows accessing the route `params` as props passed to the page component. See[the `vue-router` docs](https://router.vuejs.org/guide/essentials/passing-props) for more information.
|
|
340
|
+
Allows accessing the route `params` as props passed to the page component. See [the `vue-router` docs](https://router.vuejs.org/guide/essentials/passing-props) for more information.
|
|
341
341
|
|
|
342
342
|
### Typing Custom Metadata
|
|
343
343
|
|
|
@@ -360,7 +360,7 @@ To navigate between pages of your app, you should use the [`<NuxtLink>`](/docs/a
|
|
|
360
360
|
|
|
361
361
|
This component is included with Nuxt and therefore you don't have to import it as you do with other components.
|
|
362
362
|
|
|
363
|
-
A simple link to the `index.vue` page in your `pages` folder:
|
|
363
|
+
A simple link to the `index.vue` page in your `app/pages` folder:
|
|
364
364
|
|
|
365
365
|
```vue
|
|
366
366
|
<template>
|
|
@@ -399,11 +399,11 @@ function navigate(){
|
|
|
399
399
|
|
|
400
400
|
## Client-Only Pages
|
|
401
401
|
|
|
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.
|
|
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.
|
|
403
403
|
|
|
404
404
|
## Server-Only Pages
|
|
405
405
|
|
|
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.
|
|
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.
|
|
407
407
|
|
|
408
408
|
::warning
|
|
409
409
|
Server-only pages must have a single root element. (HTML comments are considered elements as well.)
|
|
@@ -417,7 +417,7 @@ As your app gets bigger and more complex, your routing might require more flexib
|
|
|
417
417
|
|
|
418
418
|
## Multiple Pages Directories
|
|
419
419
|
|
|
420
|
-
By default, all your pages should be in one `pages` directory at the root of your project.
|
|
420
|
+
By default, all your pages should be in one `app/pages` directory at the root of your project.
|
|
421
421
|
|
|
422
422
|
However, you can use [Nuxt Layers](/docs/getting-started/layers) to create groupings of your app's pages:
|
|
423
423
|
|
|
@@ -5,7 +5,7 @@ head.title: "plugins/"
|
|
|
5
5
|
navigation.icon: i-lucide-folder
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Nuxt automatically reads the files in the `plugins/` directory and loads them at the creation of the Vue application.
|
|
8
|
+
Nuxt automatically reads the files in the `app/plugins/` directory and loads them at the creation of the Vue application.
|
|
9
9
|
|
|
10
10
|
::note
|
|
11
11
|
All plugins inside are auto-registered, you don't need to add them to your `nuxt.config` separately.
|
|
@@ -30,7 +30,7 @@ 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 [`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/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
|
|
34
34
|
|
|
35
35
|
```ts twoslash [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
@@ -134,9 +134,9 @@ export default defineNuxtPlugin({
|
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/guide/directory-structure/composables) as well as [utils](/docs/guide/directory-structure/utils) within Nuxt plugins:
|
|
137
|
+
You can use [composables](/docs/guide/directory-structure/app/composables) as well as [utils](/docs/guide/directory-structure/app/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
|
-
```ts [plugins/hello.ts]
|
|
139
|
+
```ts [app/plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
141
141
|
const foo = useFoo()
|
|
142
142
|
})
|
|
@@ -186,7 +186,7 @@ export default defineNuxtPlugin({
|
|
|
186
186
|
|
|
187
187
|
You can then use the helper in your components:
|
|
188
188
|
|
|
189
|
-
```vue [components/Hello.vue]
|
|
189
|
+
```vue [app/components/Hello.vue]
|
|
190
190
|
<script setup lang="ts">
|
|
191
191
|
// alternatively, you can also use it here
|
|
192
192
|
const { $hello } = useNuxtApp()
|
|
@@ -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/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/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
|
|
@@ -261,7 +261,7 @@ bun add -D vue-gtag-next
|
|
|
261
261
|
|
|
262
262
|
Then create a plugin file:
|
|
263
263
|
|
|
264
|
-
```ts [plugins/vue-gtag.client.ts]
|
|
264
|
+
```ts [app/plugins/vue-gtag.client.ts]
|
|
265
265
|
import VueGtag, { trackRouter } from 'vue-gtag-next'
|
|
266
266
|
|
|
267
267
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -5,7 +5,7 @@ description: Use the utils/ directory to auto-import your utility functions thro
|
|
|
5
5
|
navigation.icon: i-lucide-folder
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The main purpose of the [`utils/` directory](/docs/guide/directory-structure/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/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
|
|
|
@@ -29,7 +29,7 @@ export default function (arr: Array<any>) {
|
|
|
29
29
|
|
|
30
30
|
You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
31
31
|
|
|
32
|
-
```vue [app.vue]
|
|
32
|
+
```vue [app/app.vue]
|
|
33
33
|
<template>
|
|
34
34
|
<p>{{ formatNumber(1234) }}</p>
|
|
35
35
|
</template>
|
|
@@ -40,7 +40,7 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
|
40
40
|
:link-example{to="/docs/examples/features/auto-imports"}
|
|
41
41
|
|
|
42
42
|
::tip
|
|
43
|
-
The way `utils/` auto-imports work and are scanned is identical to the [`composables/`](/docs/guide/directory-structure/composables) directory.
|
|
43
|
+
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/guide/directory-structure/app/composables) directory.
|
|
44
44
|
::
|
|
45
45
|
|
|
46
46
|
::important
|
|
@@ -37,7 +37,7 @@ export default defineAppConfig({
|
|
|
37
37
|
|
|
38
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.
|
|
39
39
|
|
|
40
|
-
```vue [pages/index.vue]
|
|
40
|
+
```vue [app/pages/index.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
42
42
|
const appConfig = useAppConfig()
|
|
43
43
|
|
|
@@ -47,7 +47,7 @@ console.log(appConfig.theme)
|
|
|
47
47
|
|
|
48
48
|
The [`updateAppConfig`](/docs/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
49
49
|
|
|
50
|
-
```vue [pages/index.vue]
|
|
50
|
+
```vue [app/pages/index.vue]
|
|
51
51
|
<script setup>
|
|
52
52
|
const appConfig = useAppConfig() // { foo: 'bar' }
|
|
53
53
|
|
|
@@ -6,16 +6,16 @@ navigation.icon: i-lucide-file
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::tip
|
|
9
|
-
If you have a `pages/` directory, the `app.vue` file is optional. Nuxt will automatically include a default `app.vue`, but you can still add your own to customize the structure and content as needed.
|
|
9
|
+
If you have a `app/pages/` directory, the `app.vue` file is optional. Nuxt will automatically include a default `app.vue`, but you can still add your own to customize the structure and content as needed.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
14
|
### Minimal Usage
|
|
15
15
|
|
|
16
|
-
With Nuxt, the [`pages/`](/docs/guide/directory-structure/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/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
|
-
```vue [app.vue]
|
|
18
|
+
```vue [app/app.vue]
|
|
19
19
|
<template>
|
|
20
20
|
<h1>Hello World!</h1>
|
|
21
21
|
</template>
|
|
@@ -25,9 +25,9 @@ With Nuxt, the [`pages/`](/docs/guide/directory-structure/pages) directory is op
|
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`pages/`](/docs/guide/directory-structure/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/guide/directory-structure/app/pages) directory, you need to use the [`<NuxtPage>`](/docs/api/components/nuxt-page) component to display the current page:
|
|
29
29
|
|
|
30
|
-
```vue [app.vue]
|
|
30
|
+
```vue [app/app.vue]
|
|
31
31
|
<template>
|
|
32
32
|
<NuxtPage />
|
|
33
33
|
</template>
|
|
@@ -35,7 +35,7 @@ When you have a [`pages/`](/docs/guide/directory-structure/pages) directory, you
|
|
|
35
35
|
|
|
36
36
|
You can also define the common structure of your application directly in `app.vue`. This is useful when you want to include global elements such as a header or footer:
|
|
37
37
|
|
|
38
|
-
```vue [app.vue]
|
|
38
|
+
```vue [app/app.vue]
|
|
39
39
|
<template>
|
|
40
40
|
<header>
|
|
41
41
|
Header content
|
|
@@ -51,15 +51,15 @@ 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/pages"}
|
|
55
|
-
Learn more about how to structure your pages using the `pages/` directory.
|
|
54
|
+
::read-more{to="/docs/guide/directory-structure/app/pages"}
|
|
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 `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/api/components/nuxt-layout) component. This allows you to define multiple layouts and apply them per page.
|
|
61
61
|
|
|
62
|
-
```vue [app.vue]
|
|
62
|
+
```vue [app/app.vue]
|
|
63
63
|
<template>
|
|
64
64
|
<NuxtLayout>
|
|
65
65
|
<NuxtPage />
|
|
@@ -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/layouts"}
|
|
71
|
-
Learn more about how to structure your layouts using the `layouts/` directory.
|
|
70
|
+
::read-more{to="/docs/guide/directory-structure/app/layouts"}
|
|
71
|
+
Learn more about how to structure your layouts using the `app/layouts/` directory.
|
|
72
72
|
::
|
|
@@ -36,9 +36,9 @@ 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/guide/directory-structure/app/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
40
40
|
|
|
41
|
-
```vue [pages/[...slug\\].vue]
|
|
41
|
+
```vue [app/pages/[...slug\\].vue]
|
|
42
42
|
<script lang="ts" setup>
|
|
43
43
|
const route = useRoute()
|
|
44
44
|
const { data: page } = await useAsyncData(route.path, () => {
|
|
@@ -31,7 +31,7 @@ export default defineEventHandler((event) => {
|
|
|
31
31
|
|
|
32
32
|
You can now universally call this API in your pages and components:
|
|
33
33
|
|
|
34
|
-
```vue [pages/index.vue]
|
|
34
|
+
```vue [app/pages/index.vue]
|
|
35
35
|
<script setup lang="ts">
|
|
36
36
|
const { data } = await useFetch('/api/hello')
|
|
37
37
|
</script>
|
|
@@ -58,7 +58,7 @@ export default defineEventHandler(() => 'Hello World!')
|
|
|
58
58
|
Given the example above, the `/hello` route will be accessible at <http://localhost:3000/hello>.
|
|
59
59
|
|
|
60
60
|
::note
|
|
61
|
-
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/guide/directory-structure/pages#dynamic-routes) do.
|
|
61
|
+
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/guide/directory-structure/app/pages#dynamic-routes) do.
|
|
62
62
|
::
|
|
63
63
|
|
|
64
64
|
## Server Middleware
|
|
@@ -232,7 +232,7 @@ Alternatively, use `readValidatedBody` with a schema validator such as Zod for r
|
|
|
232
232
|
|
|
233
233
|
You can now universally call this API using:
|
|
234
234
|
|
|
235
|
-
```vue [app.vue]
|
|
235
|
+
```vue [app/app.vue]
|
|
236
236
|
<script setup lang="ts">
|
|
237
237
|
async function submit() {
|
|
238
238
|
const { body } = await $fetch('/api/submit', {
|
|
@@ -37,7 +37,7 @@ export default function (input: string) {
|
|
|
37
37
|
|
|
38
38
|
You can now use [auto-imported](/docs/guide/directory-structure/shared#auto-imports) utilities in your Nuxt app and `server/` directory.
|
|
39
39
|
|
|
40
|
-
```vue [app.vue]
|
|
40
|
+
```vue [app/app.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
42
42
|
const hello = capitalize('hello')
|
|
43
43
|
</script>
|
|
@@ -62,10 +62,10 @@ export default defineEventHandler((event) => {
|
|
|
62
62
|
Only files in the `shared/utils/` and `shared/types/` directories will be auto-imported. Files nested within subdirectories of these directories will not be auto-imported unless you add these directories to `imports.dirs` and `nitro.imports.dirs`.
|
|
63
63
|
|
|
64
64
|
::tip
|
|
65
|
-
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`composables/`](/docs/guide/directory-structure/composables) and [`utils/`](/docs/guide/directory-structure/utils) directories.
|
|
65
|
+
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/guide/directory-structure/app/composables) and [`app/utils/`](/docs/guide/directory-structure/app/utils) directories.
|
|
66
66
|
::
|
|
67
67
|
|
|
68
|
-
:read-more{to="/docs/guide/directory-structure/composables#how-files-are-scanned"}
|
|
68
|
+
:read-more{to="/docs/guide/directory-structure/app/composables#how-files-are-scanned"}
|
|
69
69
|
|
|
70
70
|
```bash [Directory Structure]
|
|
71
71
|
-| shared/
|
|
@@ -27,6 +27,10 @@ modules[]=nuxt-security
|
|
|
27
27
|
|
|
28
28
|
If present, the properties in the `nuxt.config` file will overwrite the properties in `.nuxtrc` file.
|
|
29
29
|
|
|
30
|
+
::note
|
|
31
|
+
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
32
|
+
::
|
|
33
|
+
|
|
30
34
|
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
31
35
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
36
|
::
|
|
@@ -61,7 +61,7 @@ This feature will likely be removed in a near future.
|
|
|
61
61
|
|
|
62
62
|
Emits `app:chunkError` hook when there is an error loading vite/webpack chunks. Default behavior is to perform a reload of the new route on navigation to a new route when a chunk fails to load.
|
|
63
63
|
|
|
64
|
-
If you set this to `'automatic-immediate'` Nuxt will reload the current route immediately, instead of waiting for a navigation. This is useful for chunk errors that are not triggered by navigation, e.g., when your Nuxt app fails to load a [lazy component](/docs/guide/directory-structure/components#dynamic-imports). A potential downside of this behavior is undesired reloads, e.g., when your app does not need the chunk that caused the error.
|
|
64
|
+
If you set this to `'automatic-immediate'` Nuxt will reload the current route immediately, instead of waiting for a navigation. This is useful for chunk errors that are not triggered by navigation, e.g., when your Nuxt app fails to load a [lazy component](/docs/guide/directory-structure/app/components#dynamic-imports). A potential downside of this behavior is undesired reloads, e.g., when your app does not need the chunk that caused the error.
|
|
65
65
|
|
|
66
66
|
You can disable automatic handling by setting this to `false`, or handle chunk errors manually by setting it to `manual`.
|
|
67
67
|
|
|
@@ -220,7 +220,7 @@ export default defineNuxtConfig({
|
|
|
220
220
|
})
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
-
:read-more{to="/docs/guide/directory-structure/components#server-components"}
|
|
223
|
+
:read-more{to="/docs/guide/directory-structure/app/components#server-components"}
|
|
224
224
|
|
|
225
225
|
::read-more{icon="i-simple-icons-github" to="https://github.com/nuxt/nuxt/issues/19772" target="_blank"}
|
|
226
226
|
You can follow the server components roadmap on GitHub.
|
|
@@ -423,7 +423,7 @@ export default defineNuxtConfig({
|
|
|
423
423
|
})
|
|
424
424
|
```
|
|
425
425
|
|
|
426
|
-
This allows modules to access additional metadata from the page metadata in the build context. If you are using this within a module, it's recommended also to [augment the `NuxtPage` types with your keys](/docs/guide/directory-structure/pages#typing-custom-metadata).
|
|
426
|
+
This allows modules to access additional metadata from the page metadata in the build context. If you are using this within a module, it's recommended also to [augment the `NuxtPage` types with your keys](/docs/guide/directory-structure/app/pages#typing-custom-metadata).
|
|
427
427
|
|
|
428
428
|
## normalizeComponentNames
|
|
429
429
|
|
|
@@ -531,7 +531,7 @@ export default defineNuxtConfig({
|
|
|
531
531
|
})
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
::read-more{icon="i-simple-icons-github" color="gray" to="/docs/guide/directory-structure/components#delayed-or-lazy-hydration"}
|
|
534
|
+
::read-more{icon="i-simple-icons-github" color="gray" to="/docs/guide/directory-structure/app/components#delayed-or-lazy-hydration"}
|
|
535
535
|
Read more about lazy hydration.
|
|
536
536
|
::
|
|
537
537
|
|
|
@@ -575,7 +575,7 @@ export default defineNuxtConfig({
|
|
|
575
575
|
})
|
|
576
576
|
```
|
|
577
577
|
|
|
578
|
-
```ts [app.vue]
|
|
578
|
+
```ts [app/app.vue]
|
|
579
579
|
function something (_method: () => unknown) {
|
|
580
580
|
return () => 'decorated'
|
|
581
581
|
}
|
|
@@ -637,3 +637,36 @@ export default defineNuxtConfig({
|
|
|
637
637
|
}
|
|
638
638
|
})
|
|
639
639
|
```
|
|
640
|
+
|
|
641
|
+
## entryImportMap
|
|
642
|
+
|
|
643
|
+
By default, Nuxt improves chunk stability by using an import map to resolve the entry chunk of the bundle.
|
|
644
|
+
|
|
645
|
+
This injects an import map at the top of your `<head>` tag:
|
|
646
|
+
|
|
647
|
+
```html
|
|
648
|
+
<script type="importmap">{"imports":{"#entry":"/_nuxt/DC5HVSK5.js"}}</script>
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Within the script chunks emitted by Vite, imports will be from `#entry`. This means that changes to the entry will not invalidate chunks which are otherwise unchanged.
|
|
652
|
+
|
|
653
|
+
::note
|
|
654
|
+
Nuxt smartly disables this feature if you have configured `vite.build.target` to include a browser that doesn't support import maps, or if you have configured `vite.build.rollupOptions.output.entryFileNames` to a value that does not include `[hash]`.
|
|
655
|
+
::
|
|
656
|
+
|
|
657
|
+
If you need to disable this feature you can do so:
|
|
658
|
+
|
|
659
|
+
```ts twoslash [nuxt.config.ts]
|
|
660
|
+
export default defineNuxtConfig({
|
|
661
|
+
experimental: {
|
|
662
|
+
entryImportMap: false
|
|
663
|
+
},
|
|
664
|
+
// or, better, simply tell vite your desired target
|
|
665
|
+
// which nuxt will respect
|
|
666
|
+
vite: {
|
|
667
|
+
build: {
|
|
668
|
+
target: 'safari13'
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
})
|
|
672
|
+
```
|
|
@@ -97,7 +97,7 @@ The behavior is different between the client-side and server-side:
|
|
|
97
97
|
- On server-side, the entire runtime config is available, but it is read-only to avoid context sharing.
|
|
98
98
|
::
|
|
99
99
|
|
|
100
|
-
```vue [pages/index.vue]
|
|
100
|
+
```vue [app/pages/index.vue]
|
|
101
101
|
<script setup lang="ts">
|
|
102
102
|
const config = useRuntimeConfig()
|
|
103
103
|
|
|
@@ -122,7 +122,7 @@ if (import.meta.server) {
|
|
|
122
122
|
|
|
123
123
|
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
124
124
|
|
|
125
|
-
```ts [plugins/config.ts]
|
|
125
|
+
```ts [app/plugins/config.ts]
|
|
126
126
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
127
127
|
const config = useRuntimeConfig()
|
|
128
128
|
|
|
@@ -41,7 +41,7 @@ Explore all available Nuxt hooks.
|
|
|
41
41
|
|
|
42
42
|
App hooks can be mainly used by [Nuxt Plugins](/docs/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
|
-
```js [plugins/test.ts]
|
|
44
|
+
```js [app/plugins/test.ts]
|
|
45
45
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
46
46
|
nuxtApp.hook('page:start', () => {
|
|
47
47
|
/* your code goes here */
|