@nuxt/docs-nightly 4.2.2-29382831.243261ed → 4.2.2-29385843.5bf66d4f
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 +5 -5
- package/1.getting-started/04.views.md +5 -5
- package/1.getting-started/05.assets.md +7 -7
- package/1.getting-started/06.styling.md +5 -5
- package/1.getting-started/07.routing.md +7 -7
- package/1.getting-started/08.seo-meta.md +3 -3
- package/1.getting-started/09.transitions.md +6 -6
- package/1.getting-started/10.data-fetching.md +2 -2
- package/1.getting-started/11.state-management.md +2 -2
- package/1.getting-started/12.error-handling.md +3 -3
- package/1.getting-started/13.server.md +2 -2
- package/1.getting-started/14.layers.md +3 -3
- package/1.getting-started/16.deployment.md +1 -1
- package/1.getting-started/17.testing.md +1 -1
- package/1.getting-started/18.upgrade.md +6 -6
- package/2.directory-structure/0.nuxt.md +1 -1
- package/2.directory-structure/0.output.md +1 -1
- package/2.directory-structure/1.app/1.assets.md +2 -2
- package/2.directory-structure/1.app/1.components.md +2 -2
- package/2.directory-structure/1.app/1.composables.md +2 -2
- package/2.directory-structure/1.app/1.layouts.md +3 -3
- package/2.directory-structure/1.app/1.middleware.md +1 -1
- package/2.directory-structure/1.app/1.pages.md +7 -7
- package/2.directory-structure/1.app/1.plugins.md +2 -2
- package/2.directory-structure/1.app/1.utils.md +3 -3
- package/2.directory-structure/1.app/3.app.md +4 -4
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.modules.md +1 -1
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +3 -3
- package/2.directory-structure/1.shared.md +3 -3
- package/2.directory-structure/2.env.md +2 -2
- package/2.directory-structure/2.nuxtignore.md +1 -1
- package/2.directory-structure/2.nuxtrc.md +1 -1
- package/2.directory-structure/3.nuxt-config.md +1 -1
- package/2.directory-structure/3.package.md +1 -1
- package/2.directory-structure/index.md +24 -24
- package/3.guide/1.concepts/{3.rendering.md → 1.rendering.md} +1 -27
- package/3.guide/1.concepts/{2.vuejs-development.md → 10.vuejs-development.md} +4 -3
- package/3.guide/1.concepts/{10.nuxt-lifecycle.md → 2.nuxt-lifecycle.md} +32 -25
- package/3.guide/1.concepts/{1.auto-imports.md → 3.auto-imports.md} +5 -5
- package/3.guide/1.concepts/4.server-engine.md +3 -3
- package/3.guide/1.concepts/5.modules.md +1 -1
- package/3.guide/1.concepts/7.esm.md +1 -0
- package/3.guide/1.concepts/8.typescript.md +4 -4
- package/3.guide/2.best-practices/performance.md +2 -2
- package/3.guide/3.ai/.navigation.yml +3 -0
- package/3.guide/3.ai/1.mcp.md +255 -0
- package/3.guide/3.ai/2.llms-txt.md +65 -0
- package/3.guide/{3.recipes → 4.recipes}/1.custom-routing.md +1 -1
- package/3.guide/{3.recipes → 4.recipes}/2.vite-plugin.md +1 -1
- package/3.guide/{3.recipes → 4.recipes}/3.custom-usefetch.md +1 -1
- package/3.guide/{3.recipes → 4.recipes}/4.sessions-and-authentication.md +1 -1
- package/3.guide/{4.going-further → 5.going-further}/1.events.md +2 -3
- package/3.guide/{4.going-further → 5.going-further}/1.experimental-features.md +4 -4
- package/3.guide/{4.going-further → 5.going-further}/1.internals.md +3 -2
- package/3.guide/{4.going-further → 5.going-further}/10.runtime-config.md +2 -2
- package/3.guide/{4.going-further → 5.going-further}/2.hooks.md +2 -2
- package/3.guide/{4.going-further → 5.going-further}/3.modules.md +2 -2
- package/3.guide/{4.going-further → 5.going-further}/6.nuxt-app.md +3 -3
- package/3.guide/{4.going-further → 5.going-further}/7.layers.md +11 -11
- package/4.api/1.components/12.nuxt-route-announcer.md +1 -1
- package/4.api/1.components/2.nuxt-page.md +2 -2
- package/4.api/1.components/3.nuxt-layout.md +5 -5
- package/4.api/1.components/5.nuxt-loading-indicator.md +1 -1
- package/4.api/1.components/7.nuxt-welcome.md +2 -2
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-nuxt-app.md +4 -4
- package/4.api/2.composables/use-response-header.md +1 -1
- package/4.api/2.composables/use-route.md +1 -1
- package/4.api/2.composables/use-router.md +2 -2
- package/4.api/2.composables/use-runtime-config.md +1 -1
- package/4.api/3.utils/$fetch.md +1 -1
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +1 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +1 -1
- package/4.api/3.utils/define-page-meta.md +6 -6
- package/4.api/3.utils/navigate-to.md +1 -1
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/module.md +3 -3
- package/4.api/4.commands/prepare.md +1 -1
- package/4.api/4.commands/preview.md +1 -1
- package/4.api/4.commands/typecheck.md +1 -1
- package/4.api/5.kit/1.modules.md +1 -1
- package/4.api/5.kit/2.programmatic.md +2 -2
- package/4.api/6.advanced/1.hooks.md +1 -1
- package/4.api/6.nuxt-config.md +4 -4
- package/5.community/6.roadmap.md +4 -4
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +1 -1
- package/6.bridge/4.plugins-and-middleware.md +2 -2
- package/7.migration/11.server.md +1 -1
- package/7.migration/2.configuration.md +2 -2
- package/7.migration/20.module-authors.md +1 -1
- 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 +6 -6
- package/package.json +1 -1
- /package/3.guide/{3.recipes → 4.recipes}/.navigation.yml +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/.navigation.yml +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/1.features.md +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/11.nightly-release-channel.md +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/4.kit.md +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/9.debugging.md +0 -0
- /package/3.guide/{4.going-further → 5.going-further}/index.md +0 -0
|
@@ -6,7 +6,7 @@ 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/4.x/
|
|
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/directory-structure/app/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
|
|
@@ -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/4.x/
|
|
49
|
+
If you are using [`app.vue`](/docs/4.x/directory-structure/app/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>
|
|
@@ -313,11 +313,11 @@ You can set a default value for this property [in your `nuxt.config`](/docs/4.x/
|
|
|
313
313
|
|
|
314
314
|
#### `key`
|
|
315
315
|
|
|
316
|
-
[See above](/docs/4.x/
|
|
316
|
+
[See above](/docs/4.x/directory-structure/app/pages#child-route-keys).
|
|
317
317
|
|
|
318
318
|
#### `layout`
|
|
319
319
|
|
|
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/
|
|
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/directory-structure/app/layouts).
|
|
321
321
|
|
|
322
322
|
#### `layoutTransition` and `pageTransition`
|
|
323
323
|
|
|
@@ -327,7 +327,7 @@ You can set default values for these properties [in your `nuxt.config`](/docs/4.
|
|
|
327
327
|
|
|
328
328
|
#### `middleware`
|
|
329
329
|
|
|
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#Global-Before-Guards)), or an array of strings/functions. [More about named middleware](/docs/4.x/
|
|
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#Global-Before-Guards)), or an array of strings/functions. [More about named middleware](/docs/4.x/directory-structure/app/middleware).
|
|
331
331
|
|
|
332
332
|
#### `name`
|
|
333
333
|
|
|
@@ -401,11 +401,11 @@ function navigate () {
|
|
|
401
401
|
|
|
402
402
|
## Client-Only Pages
|
|
403
403
|
|
|
404
|
-
You can define a page as [client only](/docs/4.x/
|
|
404
|
+
You can define a page as [client only](/docs/4.x/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.
|
|
405
405
|
|
|
406
406
|
## Server-Only Pages
|
|
407
407
|
|
|
408
|
-
You can define a page as [server only](/docs/4.x/
|
|
408
|
+
You can define a page as [server only](/docs/4.x/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.
|
|
409
409
|
|
|
410
410
|
::warning
|
|
411
411
|
Server-only pages must have a single root element. (HTML comments are considered elements as well.)
|
|
@@ -134,7 +134,7 @@ export default defineNuxtPlugin({
|
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/4.x/
|
|
137
|
+
You can use [composables](/docs/4.x/directory-structure/app/composables) as well as [utils](/docs/4.x/directory-structure/app/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
139
|
```ts [app/plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -200,7 +200,7 @@ const { $hello } = useNuxtApp()
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
::important
|
|
203
|
-
Note that we highly recommend using [`composables`](/docs/4.x/
|
|
203
|
+
Note that we highly recommend using [`composables`](/docs/4.x/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
|
|
@@ -5,7 +5,7 @@ description: Use the utils/ directory to auto-import your utility functions thro
|
|
|
5
5
|
navigation.icon: i-vscode-icons-folder-type-tools
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The main purpose of the [`app/utils/` directory](/docs/4.x/
|
|
8
|
+
The main purpose of the [`app/utils/` directory](/docs/4.x/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
|
|
|
@@ -40,10 +40,10 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
|
40
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/4.x/
|
|
43
|
+
The way `app/utils/` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/4.x/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/4.x/
|
|
48
|
+
Only `server/utils` are auto-imported in the [`server/`](/docs/4.x/directory-structure/server#server-utilities) directory.
|
|
49
49
|
::
|
|
@@ -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/4.x/
|
|
16
|
+
With Nuxt, the [`app/pages/`](/docs/4.x/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>
|
|
@@ -25,7 +25,7 @@ With Nuxt, the [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) dir
|
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`app/pages/`](/docs/4.x/
|
|
28
|
+
When you have a [`app/pages/`](/docs/4.x/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,7 +51,7 @@ 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/4.x/
|
|
54
|
+
::read-more{to="/docs/4.x/directory-structure/app/pages"}
|
|
55
55
|
Learn more about how to structure your pages using the `app/pages/` directory.
|
|
56
56
|
::
|
|
57
57
|
|
|
@@ -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/4.x/
|
|
70
|
+
::read-more{to="/docs/4.x/directory-structure/app/layouts"}
|
|
71
71
|
Learn more about how to structure your layouts using the `app/layouts/` directory.
|
|
72
72
|
::
|
|
@@ -36,7 +36,7 @@ The module automatically loads and parses them.
|
|
|
36
36
|
|
|
37
37
|
## Render Content
|
|
38
38
|
|
|
39
|
-
To render content pages, add a [catch-all route](/docs/4.x/
|
|
39
|
+
To render content pages, add a [catch-all route](/docs/4.x/directory-structure/app/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
|
|
40
40
|
|
|
41
41
|
```vue [app/pages/[...slug\\].vue]
|
|
42
42
|
<script lang="ts" setup>
|
|
@@ -11,7 +11,7 @@ The auto-registered files patterns are:
|
|
|
11
11
|
- `modules/*/index.ts`
|
|
12
12
|
- `modules/*.ts`
|
|
13
13
|
|
|
14
|
-
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/4.x/
|
|
14
|
+
You don't need to add those local modules to your [`nuxt.config.ts`](/docs/4.x/directory-structure/nuxt-config) separately.
|
|
15
15
|
|
|
16
16
|
::code-group
|
|
17
17
|
|
|
@@ -8,5 +8,5 @@ navigation.icon: i-vscode-icons-folder-type-node
|
|
|
8
8
|
The package manager ([`npm`](https://docs.npmjs.com/cli/commands/npm/) or [`yarn`](https://yarnpkg.com) or [`pnpm`](https://pnpm.io/cli/install) or [`bun`](https://bun.com/package-manager)) creates this directory to store the dependencies of your project.
|
|
9
9
|
|
|
10
10
|
::important
|
|
11
|
-
This directory should be added to your [`.gitignore`](/docs/4.x/
|
|
11
|
+
This directory should be added to your [`.gitignore`](/docs/4.x/directory-structure/gitignore) file to avoid pushing the dependencies to your repository.
|
|
12
12
|
::
|
|
@@ -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/4.x/
|
|
61
|
+
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/4.x/directory-structure/app/pages#dynamic-routes) do.
|
|
62
62
|
::
|
|
63
63
|
|
|
64
64
|
## Server Middleware
|
|
@@ -134,7 +134,7 @@ export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
|
134
134
|
|
|
135
135
|
Auto-imports and other types are different for the `server/` directory, as it is running in a different context from the `app/` directory.
|
|
136
136
|
|
|
137
|
-
By default, Nuxt 4 generates a [`tsconfig.json`](/docs/4.x/
|
|
137
|
+
By default, Nuxt 4 generates a [`tsconfig.json`](/docs/4.x/directory-structure/tsconfig) which includes a project reference covering the `server/` folder which ensures accurate typings.
|
|
138
138
|
|
|
139
139
|
## Recipes
|
|
140
140
|
|
|
@@ -454,7 +454,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
|
|
|
454
454
|
|
|
455
455
|
### Server Storage
|
|
456
456
|
|
|
457
|
-
Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/4.x/
|
|
457
|
+
Nitro provides a cross-platform [storage layer](https://nitro.build/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](/docs/4.x/directory-structure/server#server-plugins).
|
|
458
458
|
|
|
459
459
|
**Example of adding a Redis storage:**
|
|
460
460
|
|
|
@@ -35,7 +35,7 @@ export default function (input: string) {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
You can now use [auto-imported](/docs/4.x/
|
|
38
|
+
You can now use [auto-imported](/docs/4.x/directory-structure/shared) utilities in your Nuxt app and `server/` directory.
|
|
39
39
|
|
|
40
40
|
```vue [app/app.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
@@ -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 [`app/composables/`](/docs/4.x/
|
|
65
|
+
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/4.x/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/directory-structure/app/utils) directories.
|
|
66
66
|
::
|
|
67
67
|
|
|
68
|
-
:read-more{to="/docs/4.x/
|
|
68
|
+
:read-more{to="/docs/4.x/directory-structure/app/composables#how-files-are-scanned"}
|
|
69
69
|
|
|
70
70
|
```bash [Directory Structure]
|
|
71
71
|
-| shared/
|
|
@@ -6,7 +6,7 @@ navigation.icon: i-vscode-icons-file-type-dotenv
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This file should be added to your [`.gitignore`](/docs/4.x/
|
|
9
|
+
This file should be added to your [`.gitignore`](/docs/4.x/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Dev, Build and Generate Time
|
|
@@ -75,5 +75,5 @@ Note that for a purely static site, it is not possible to set runtime configurat
|
|
|
75
75
|
|
|
76
76
|
::note
|
|
77
77
|
If you want to use environment variables set at build time but do not care about updating these down the line (or only need to update them reactively _within_ your app) then `appConfig` may be a better choice. You can define `appConfig` both within your `nuxt.config` (using environment variables) and also within an `~/app.config.ts` file in your project.
|
|
78
|
-
:read-more{to="/docs/4.x/
|
|
78
|
+
:read-more{to="/docs/4.x/directory-structure/app/app-config"}
|
|
79
79
|
::
|
|
@@ -8,7 +8,7 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
8
8
|
|
|
9
9
|
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/4.x/api/nuxt-config#rootdir)) during the build phase.
|
|
10
10
|
|
|
11
|
-
It is subject to the same specification as [`.gitignore`](/docs/4.x/
|
|
11
|
+
It is subject to the same specification as [`.gitignore`](/docs/4.x/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
12
12
|
|
|
13
13
|
::tip
|
|
14
14
|
You can also configure [`ignoreOptions`](/docs/4.x/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/4.x/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/4.x/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
@@ -8,7 +8,7 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
8
8
|
The `.nuxtrc` file can be used to configure Nuxt with a flat syntax. It is based on [`unjs/rc9`](https://github.com/unjs/rc9).
|
|
9
9
|
|
|
10
10
|
::tip
|
|
11
|
-
For more advanced configurations, use [`nuxt.config`](/docs/4.x/
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/4.x/directory-structure/nuxt-config).
|
|
12
12
|
::
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -31,4 +31,4 @@ export default defineNuxtConfig({
|
|
|
31
31
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
32
|
::
|
|
33
33
|
|
|
34
|
-
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/4.x/
|
|
34
|
+
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/4.x/directory-structure/env), [`.nuxtignore`](/docs/4.x/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/4.x/directory-structure/nuxtrc) dotfiles.
|
|
@@ -27,6 +27,6 @@ The minimal `package.json` of your Nuxt application should looks like:
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
::read-more{icon="i-simple-icons-npm" to="https://docs.npmjs.com/cli/configuring-npm/package-json" target="_blank"}
|
|
30
|
+
::read-more{icon="i-simple-icons-npm" to="https://docs.npmjs.com/cli/configuring-npm/package-json/" target="_blank"}
|
|
31
31
|
Read more about the `package.json` file.
|
|
32
32
|
::
|
|
@@ -13,49 +13,49 @@ The root directory of a Nuxt application is the directory that contains the `nux
|
|
|
13
13
|
## App Directory
|
|
14
14
|
|
|
15
15
|
The `app/` directory is the main directory of the Nuxt application. It contains the following subdirectories:
|
|
16
|
-
- [`assets/`](/docs/directory-structure/app/assets): website's assets that the build tool (Vite or webpack) will process
|
|
17
|
-
- [`components/`](/docs/directory-structure/app/components): Vue components of the application
|
|
18
|
-
- [`composables/`](/docs/directory-structure/app/composables): add your Vue composables
|
|
19
|
-
- [`layouts/`](/docs/directory-structure/app/layouts): Vue components that wrap around your pages and avoid re-rendering between pages
|
|
20
|
-
- [`middleware/`](/docs/directory-structure/app/middleware): run code before navigating to a particular route
|
|
21
|
-
- [`pages/`](/docs/directory-structure/app/pages): file-based routing to create routes within your web application
|
|
22
|
-
- [`plugins/`](/docs/directory-structure/app/plugins): use Vue plugins and more at the creation of your Nuxt application
|
|
23
|
-
- [`utils/`](/docs/directory-structure/app/utils): add functions throughout your application that can be used in your components, composables, and pages.
|
|
16
|
+
- [`assets/`](/docs/4.x/directory-structure/app/assets): website's assets that the build tool (Vite or webpack) will process
|
|
17
|
+
- [`components/`](/docs/4.x/directory-structure/app/components): Vue components of the application
|
|
18
|
+
- [`composables/`](/docs/4.x/directory-structure/app/composables): add your Vue composables
|
|
19
|
+
- [`layouts/`](/docs/4.x/directory-structure/app/layouts): Vue components that wrap around your pages and avoid re-rendering between pages
|
|
20
|
+
- [`middleware/`](/docs/4.x/directory-structure/app/middleware): run code before navigating to a particular route
|
|
21
|
+
- [`pages/`](/docs/4.x/directory-structure/app/pages): file-based routing to create routes within your web application
|
|
22
|
+
- [`plugins/`](/docs/4.x/directory-structure/app/plugins): use Vue plugins and more at the creation of your Nuxt application
|
|
23
|
+
- [`utils/`](/docs/4.x/directory-structure/app/utils): add functions throughout your application that can be used in your components, composables, and pages.
|
|
24
24
|
|
|
25
25
|
This directory also includes specific files:
|
|
26
|
-
- [`app.config.ts`](/docs/directory-structure/app/app-config): a reactive configuration within your application
|
|
27
|
-
- [`app.vue`](/docs/directory-structure/app/app): the root component of your Nuxt application
|
|
28
|
-
- [`error.vue`](/docs/directory-structure/app/error): the error page of your Nuxt application
|
|
26
|
+
- [`app.config.ts`](/docs/4.x/directory-structure/app/app-config): a reactive configuration within your application
|
|
27
|
+
- [`app.vue`](/docs/4.x/directory-structure/app/app): the root component of your Nuxt application
|
|
28
|
+
- [`error.vue`](/docs/4.x/directory-structure/app/error): the error page of your Nuxt application
|
|
29
29
|
|
|
30
30
|
## Public Directory
|
|
31
31
|
|
|
32
|
-
The [`public/`](/docs/directory-structure/public) directory is the directory that contains the public files of the Nuxt application. Files contained within this directory are served at the root and are not modified by the build process.
|
|
32
|
+
The [`public/`](/docs/4.x/directory-structure/public) directory is the directory that contains the public files of the Nuxt application. Files contained within this directory are served at the root and are not modified by the build process.
|
|
33
33
|
|
|
34
34
|
This is suitable for files that have to keep their names (e.g. `robots.txt`) _or_ likely won't change (e.g. `favicon.ico`).
|
|
35
35
|
|
|
36
36
|
## Server Directory
|
|
37
37
|
|
|
38
|
-
The [`server/`](/docs/directory-structure/server) directory is the directory that contains the server-side code of the Nuxt application. It contains the following subdirectories:
|
|
39
|
-
- [`api/`](/docs/directory-structure/server#server-routes): contains the API routes of the application.
|
|
40
|
-
- [`routes/`](/docs/directory-structure/server#server-routes): contains the server routes of the application (e.g. dynamic `/sitemap.xml`).
|
|
41
|
-
- [`middleware/`](/docs/directory-structure/server#server-middleware): run code before a server route is processed
|
|
42
|
-
- [`plugins/`](/docs/directory-structure/server#server-plugins): use plugins and more at the creation of the Nuxt server
|
|
43
|
-
- [`utils/`](/docs/directory-structure/server#server-utilities): add functions throughout your application that can be used in your server code.
|
|
38
|
+
The [`server/`](/docs/4.x/directory-structure/server) directory is the directory that contains the server-side code of the Nuxt application. It contains the following subdirectories:
|
|
39
|
+
- [`api/`](/docs/4.x/directory-structure/server#server-routes): contains the API routes of the application.
|
|
40
|
+
- [`routes/`](/docs/4.x/directory-structure/server#server-routes): contains the server routes of the application (e.g. dynamic `/sitemap.xml`).
|
|
41
|
+
- [`middleware/`](/docs/4.x/directory-structure/server#server-middleware): run code before a server route is processed
|
|
42
|
+
- [`plugins/`](/docs/4.x/directory-structure/server#server-plugins): use plugins and more at the creation of the Nuxt server
|
|
43
|
+
- [`utils/`](/docs/4.x/directory-structure/server#server-utilities): add functions throughout your application that can be used in your server code.
|
|
44
44
|
|
|
45
45
|
## Shared Directory
|
|
46
46
|
|
|
47
|
-
The [`shared/`](/docs/directory-structure/shared) directory is the directory that contains the shared code of the Nuxt application and Nuxt server. This code can be used in both the Vue app and the Nitro server.
|
|
47
|
+
The [`shared/`](/docs/4.x/directory-structure/shared) directory is the directory that contains the shared code of the Nuxt application and Nuxt server. This code can be used in both the Vue app and the Nitro server.
|
|
48
48
|
|
|
49
49
|
## Content Directory
|
|
50
50
|
|
|
51
|
-
The [`content/`](/docs/directory-structure/content) directory is enabled by the [Nuxt Content](https://content.nuxt.com) module. It is used to create a file-based CMS for your application using Markdown files.
|
|
51
|
+
The [`content/`](/docs/4.x/directory-structure/content) directory is enabled by the [Nuxt Content](https://content.nuxt.com) module. It is used to create a file-based CMS for your application using Markdown files.
|
|
52
52
|
|
|
53
53
|
## Modules Directory
|
|
54
54
|
|
|
55
|
-
The [`modules/`](/docs/directory-structure/modules) directory is the directory that contains the local modules of the Nuxt application. Modules are used to extend the functionality of the Nuxt application.
|
|
55
|
+
The [`modules/`](/docs/4.x/directory-structure/modules) directory is the directory that contains the local modules of the Nuxt application. Modules are used to extend the functionality of the Nuxt application.
|
|
56
56
|
|
|
57
57
|
## Nuxt Files
|
|
58
58
|
|
|
59
|
-
- [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) file is the main configuration file for the Nuxt application.
|
|
60
|
-
- [`.nuxtrc`](/docs/directory-structure/nuxtrc) file is another syntax for configuring the Nuxt application (useful for global configurations).
|
|
61
|
-
- [`.nuxtignore`](/docs/directory-structure/nuxtignore) file is used to ignore files in the root directory during the build phase.
|
|
59
|
+
- [`nuxt.config.ts`](/docs/4.x/directory-structure/nuxt-config) file is the main configuration file for the Nuxt application.
|
|
60
|
+
- [`.nuxtrc`](/docs/4.x/directory-structure/nuxtrc) file is another syntax for configuring the Nuxt application (useful for global configurations).
|
|
61
|
+
- [`.nuxtignore`](/docs/4.x/directory-structure/nuxtignore) file is used to ignore files in the root directory during the build phase.
|
|
@@ -44,7 +44,7 @@ const handleClick = () => {
|
|
|
44
44
|
|
|
45
45
|
On the initial request, the `counter` ref is initialized in the server since it is rendered inside the `<p>` tag. The contents of `handleClick` is never executed here. During hydration in the browser, the `counter` ref is re-initialized. The `handleClick` finally binds itself to the button; Therefore it is reasonable to deduce that the body of `handleClick` will always run in a browser environment.
|
|
46
46
|
|
|
47
|
-
[Middlewares](/docs/4.x/
|
|
47
|
+
[Middlewares](/docs/4.x/directory-structure/app/middleware) and [pages](/docs/4.x/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/4.x/directory-structure/app/plugins) can be rendered on the server or client or both. [Components](/docs/4.x/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/4.x/directory-structure/app/composables) and [utilities](/docs/4.x/directory-structure/app/utils) are rendered based on the context of their usage.
|
|
48
48
|
|
|
49
49
|
**Benefits of server-side rendering:**
|
|
50
50
|
- **Performance**: Users can get immediate access to the page's content because browsers can display static content much faster than JavaScript-generated content. At the same time, Nuxt preserves the interactivity of a web application during the hydration process.
|
|
@@ -229,29 +229,3 @@ The current platforms where you can leverage ESR are:
|
|
|
229
229
|
- [Netlify Edge Functions](https://www.netlify.com/platform/#netlify-edge-functions) using the `nuxt build` command and `NITRO_PRESET=netlify-edge` environment variable
|
|
230
230
|
|
|
231
231
|
Note that **Hybrid Rendering** can be used when using Edge-Side Rendering with route rules.
|
|
232
|
-
|
|
233
|
-
You can explore open source examples deployed on some of the platform mentioned above:
|
|
234
|
-
::card-group
|
|
235
|
-
::card
|
|
236
|
-
---
|
|
237
|
-
icon: i-simple-icons-github
|
|
238
|
-
title: Nuxt Todos Edge
|
|
239
|
-
to: https://github.com/atinux/nuxt-todos-edge
|
|
240
|
-
target: _blank
|
|
241
|
-
ui.icon.base: text-black dark:text-white
|
|
242
|
-
---
|
|
243
|
-
A todos application with user authentication, SSR and SQLite.
|
|
244
|
-
::
|
|
245
|
-
::card
|
|
246
|
-
---
|
|
247
|
-
icon: i-simple-icons-github
|
|
248
|
-
title: Atinotes
|
|
249
|
-
to: https://github.com/atinux/atinotes
|
|
250
|
-
target: _blank
|
|
251
|
-
ui.icon.base: text-black dark:text-white
|
|
252
|
-
---
|
|
253
|
-
An editable website with universal rendering based on Cloudflare KV.
|
|
254
|
-
::
|
|
255
|
-
::
|
|
256
|
-
|
|
257
|
-
<!-- TODO: link to templates with ESR category for examples -->
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: 'Vue.js Development'
|
|
3
3
|
description: "Nuxt uses Vue.js and adds features such as component auto-imports, file-based routing and composables for an SSR-friendly usage."
|
|
4
|
+
navigation: false
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
Nuxt integrates Vue 3, the new major release of Vue that enables new patterns for Nuxt users.
|
|
@@ -25,13 +26,13 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
25
26
|
|
|
26
27
|
### Auto-imports
|
|
27
28
|
|
|
28
|
-
Every Vue component created in the [`app/components/`](/docs/4.x/
|
|
29
|
+
Every Vue component created in the [`app/components/`](/docs/4.x/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
|
|
29
30
|
|
|
30
31
|
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
31
32
|
|
|
32
33
|
### Vue Router
|
|
33
34
|
|
|
34
|
-
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/4.x/
|
|
35
|
+
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/4.x/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
|
|
35
36
|
|
|
36
37
|
:read-more{to="/docs/4.x/getting-started/routing"}
|
|
37
38
|
|
|
@@ -92,7 +93,7 @@ const increment = () => count.value++
|
|
|
92
93
|
The goal of Nuxt is to provide a great developer experience around the Composition API.
|
|
93
94
|
|
|
94
95
|
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core) from Vue and Nuxt [built-in composables](/docs/4.x/api/composables/use-async-data).
|
|
95
|
-
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/4.x/
|
|
96
|
+
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/4.x/directory-structure/app/composables).
|
|
96
97
|
|
|
97
98
|
### TypeScript Support
|
|
98
99
|
|
|
@@ -5,15 +5,16 @@ description: "Understanding the lifecycle of Nuxt applications can help you gain
|
|
|
5
5
|
|
|
6
6
|
The goal of this chapter is to provide a high-level overview of the different parts of the framework, their execution order, and how they work together.
|
|
7
7
|
|
|
8
|
-
## Server
|
|
8
|
+
## Server lifecycle
|
|
9
9
|
|
|
10
10
|
On the server, the following steps are executed for every initial request to your application:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
::steps
|
|
13
|
+
### Server plugins :badge[once]{color="info" class="align-middle"}
|
|
13
14
|
|
|
14
15
|
Nuxt is powered by [Nitro](https://nitro.build/), a modern server engine.
|
|
15
16
|
|
|
16
|
-
When Nitro starts, it initializes and executes the plugins under the `/server/plugins` directory. These plugins can:
|
|
17
|
+
When Nitro starts, it initializes and executes the plugins under the [`/server/plugins`](/docs/4.x/directory-structure/server#server-plugins) directory. These plugins can:
|
|
17
18
|
- Capture and handle application-wide errors.
|
|
18
19
|
- Register hooks that execute when Nitro shuts down.
|
|
19
20
|
- Register hooks for request lifecycle events, such as modifying responses.
|
|
@@ -22,9 +23,9 @@ When Nitro starts, it initializes and executes the plugins under the `/server/pl
|
|
|
22
23
|
Nitro plugins are executed only once when the server starts. In a serverless environment, the server boots on each incoming request, and so do the Nitro plugins. However, they are not awaited.
|
|
23
24
|
::
|
|
24
25
|
|
|
25
|
-
:read-more{to="/docs/4.x/
|
|
26
|
+
:read-more{to="/docs/4.x/directory-structure/server#server-plugins"}
|
|
26
27
|
|
|
27
|
-
###
|
|
28
|
+
### Server middleware
|
|
28
29
|
|
|
29
30
|
After initializing the Nitro server, middleware under `server/middleware/` is executed for every request. Middleware can be used for tasks such as authentication, logging, or request transformation.
|
|
30
31
|
|
|
@@ -32,23 +33,23 @@ After initializing the Nitro server, middleware under `server/middleware/` is ex
|
|
|
32
33
|
Returning a value from middleware will terminate the request and send the returned value as the response. This behavior should generally be avoided to ensure proper request handling!
|
|
33
34
|
::
|
|
34
35
|
|
|
35
|
-
:read-more{to="/docs/4.x/
|
|
36
|
+
:read-more{to="/docs/4.x/directory-structure/server#server-middleware"}
|
|
36
37
|
|
|
37
|
-
###
|
|
38
|
+
### App plugins
|
|
38
39
|
|
|
39
|
-
The Vue and Nuxt instances are created first. Afterward, Nuxt executes its
|
|
40
|
+
The Vue and Nuxt instances are created first. Afterward, Nuxt executes its app plugins. This includes:
|
|
40
41
|
- Built-in plugins, such as Vue Router and `unhead`.
|
|
41
42
|
- Custom plugins located in the `app/plugins/` directory, including those without a suffix (e.g., `myPlugin.ts`) and those with the `.server` suffix (e.g., `myServerPlugin.server.ts`).
|
|
42
43
|
|
|
43
|
-
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/
|
|
44
|
+
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/4.x/directory-structure/app/plugins).
|
|
44
45
|
|
|
45
46
|
::callout{icon="i-lucide-lightbulb"}
|
|
46
47
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
47
48
|
::
|
|
48
49
|
|
|
49
|
-
:read-more{to="/docs/4.x/
|
|
50
|
+
:read-more{to="/docs/4.x/directory-structure/app/plugins"}
|
|
50
51
|
|
|
51
|
-
###
|
|
52
|
+
### Route validation
|
|
52
53
|
|
|
53
54
|
After initializing plugins and before executing middleware, Nuxt calls the `validate` method if it is defined in the `definePageMeta` function. The `validate` method, which can be synchronous or asynchronous, is often used to validate dynamic route parameters.
|
|
54
55
|
|
|
@@ -59,7 +60,7 @@ For more information, see the [Route Validation documentation](/docs/4.x/getting
|
|
|
59
60
|
|
|
60
61
|
:read-more{to="/docs/4.x/getting-started/routing#route-validation"}
|
|
61
62
|
|
|
62
|
-
###
|
|
63
|
+
### App middleware
|
|
63
64
|
|
|
64
65
|
Middleware allows you to run code before navigating to a particular route. It is often used for tasks such as authentication, redirection, or logging.
|
|
65
66
|
|
|
@@ -70,13 +71,13 @@ In Nuxt, there are three types of middleware:
|
|
|
70
71
|
|
|
71
72
|
Nuxt executes all global middleware on the initial page load (both on server and client) and then again before any client-side navigation. Named and anonymous middleware are executed only on the routes specified in the middleware property of the page(route) meta defined in the corresponding page components.
|
|
72
73
|
|
|
73
|
-
For details about each type and examples, see the [Middleware documentation](/docs/4.x/
|
|
74
|
+
For details about each type and examples, see the [Middleware documentation](/docs/4.x/directory-structure/app/middleware).
|
|
74
75
|
|
|
75
76
|
Any redirection on the server will result in a `Location:` header being sent to the browser; the browser then makes a fresh request to this new location. All application state will be reset when this happens, unless persisted in a cookie.
|
|
76
77
|
|
|
77
|
-
:read-more{to="/docs/4.x/
|
|
78
|
+
:read-more{to="/docs/4.x/directory-structure/app/middleware"}
|
|
78
79
|
|
|
79
|
-
###
|
|
80
|
+
### Page and components
|
|
80
81
|
|
|
81
82
|
Nuxt renders the page and its components and fetches any required data with `useFetch` and `useAsyncData` during this step. Since there are no dynamic updates and no DOM operations occur on the server, Vue lifecycle hooks such as `onBeforeMount`, `onMounted`, and subsequent hooks are **NOT** executed during SSR.
|
|
82
83
|
|
|
@@ -94,7 +95,7 @@ You should avoid code that produces side effects that need cleanup in root scope
|
|
|
94
95
|
Watch a video from Daniel Roe explaining Server Rendering and Global State.
|
|
95
96
|
::
|
|
96
97
|
|
|
97
|
-
###
|
|
98
|
+
### HTML Output
|
|
98
99
|
|
|
99
100
|
After all required data is fetched and the components are rendered, Nuxt combines the rendered components with settings from `unhead` to generate a complete HTML document. This HTML, along with the associated data, is then sent back to the client to complete the SSR process.
|
|
100
101
|
|
|
@@ -106,11 +107,15 @@ After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/do
|
|
|
106
107
|
Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/4.x/api/advanced/hooks#nitro-app-hooks-runtime-server-side) hook. This hook allows you to manipulate the generated HTML, such as injecting additional scripts or modifying meta tags.
|
|
107
108
|
::
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
::
|
|
111
|
+
|
|
112
|
+
## Client lifecycle
|
|
110
113
|
|
|
111
114
|
This part of the lifecycle is fully executed in the browser, no matter which Nuxt mode you've chosen.
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
::steps
|
|
117
|
+
|
|
118
|
+
### App plugins
|
|
114
119
|
|
|
115
120
|
This step is similar to the server-side execution and includes both built-in and custom plugins.
|
|
116
121
|
|
|
@@ -120,21 +125,21 @@ Custom plugins in the `app/plugins/` directory, such as those without a suffix (
|
|
|
120
125
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
121
126
|
::
|
|
122
127
|
|
|
123
|
-
:read-more{to="/docs/4.x/
|
|
128
|
+
:read-more{to="/docs/4.x/directory-structure/app/plugins"}
|
|
124
129
|
|
|
125
|
-
###
|
|
130
|
+
### Route validation
|
|
126
131
|
|
|
127
132
|
This step is the same as the server-side execution and includes the `validate` method if defined in the `definePageMeta` function.
|
|
128
133
|
|
|
129
|
-
###
|
|
134
|
+
### App middleware
|
|
130
135
|
|
|
131
136
|
Nuxt middleware runs on both the server and the client. If you want certain code to run in specific environments, consider splitting it by using `import.meta.client` for the client and `import.meta.server` for the server.
|
|
132
137
|
|
|
133
|
-
:read-more{to="/docs/4.x/
|
|
138
|
+
:read-more{to="/docs/4.x/directory-structure/app/middleware#when-middleware-runs"}
|
|
134
139
|
|
|
135
|
-
###
|
|
140
|
+
### Mount Vue app and hydrate
|
|
136
141
|
|
|
137
|
-
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/4.x/
|
|
142
|
+
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/4.x/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
|
|
138
143
|
|
|
139
144
|
To ensure proper hydration, it's important to maintain consistency between the data on the server and the client. For API requests, it is recommended to use `useAsyncData`, `useFetch`, or other SSR-friendly composables. These methods ensure that the data fetched on the server side is reused during hydration, avoiding repeated requests. Any new requests should only be triggered after hydration, preventing hydration errors.
|
|
140
145
|
|
|
@@ -146,6 +151,8 @@ Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/4.
|
|
|
146
151
|
After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook.
|
|
147
152
|
::
|
|
148
153
|
|
|
149
|
-
###
|
|
154
|
+
### Vue lifecycle
|
|
150
155
|
|
|
151
156
|
Unlike on the server, the browser executes the full [Vue lifecycle](https://vuejs.org/guide/essentials/lifecycle).
|
|
157
|
+
|
|
158
|
+
::
|
|
@@ -11,7 +11,7 @@ const count = ref(1) // ref is auto-imported
|
|
|
11
11
|
</script>
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/4.x/
|
|
14
|
+
Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/4.x/directory-structure/app/components), [`app/composables/`](/docs/4.x/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/directory-structure/app/utils).
|
|
15
15
|
|
|
16
16
|
Contrary to a classic global declaration, Nuxt preserves typings, IDEs completions and hints, and **only includes what is used in your production code**.
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ In the docs, every function that is not explicitly imported is auto-imported by
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
In the [`server`](/docs/4.x/
|
|
23
|
+
In the [`server`](/docs/4.x/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
::note
|
|
@@ -101,8 +101,8 @@ export const useMyComposable = () => {
|
|
|
101
101
|
|
|
102
102
|
Nuxt directly auto-imports files created in defined directories:
|
|
103
103
|
|
|
104
|
-
- `app/components/` for [Vue components](/docs/4.x/
|
|
105
|
-
- `app/composables/` for [Vue composables](/docs/4.x/
|
|
104
|
+
- `app/components/` for [Vue components](/docs/4.x/directory-structure/app/components).
|
|
105
|
+
- `app/composables/` for [Vue composables](/docs/4.x/directory-structure/app/composables).
|
|
106
106
|
- `app/utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
108
|
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
@@ -167,7 +167,7 @@ With this configuration:
|
|
|
167
167
|
|
|
168
168
|
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
|
|
169
169
|
|
|
170
|
-
:read-more{to="/docs/4.x/
|
|
170
|
+
:read-more{to="/docs/4.x/directory-structure/app/components"}
|
|
171
171
|
|
|
172
172
|
To disable auto-importing components from your own `~/components` directory, you can set `components.dirs` to an empty array (though note that this will not affect components added by modules).
|
|
173
173
|
|