@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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 +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
|
@@ -13,53 +13,57 @@ 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/
|
|
17
|
-
- [`components/`](/docs/
|
|
18
|
-
- [`composables/`](/docs/
|
|
19
|
-
- [`layouts/`](/docs/
|
|
20
|
-
- [`middleware/`](/docs/
|
|
21
|
-
- [`pages/`](/docs/
|
|
22
|
-
- [`plugins/`](/docs/
|
|
23
|
-
- [`utils/`](/docs/
|
|
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.
|
|
24
24
|
|
|
25
25
|
This directory also includes specific files:
|
|
26
|
-
- [`app.config.ts`](/docs/
|
|
27
|
-
- [`app.vue`](/docs/
|
|
28
|
-
- [`error.vue`](/docs/
|
|
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
|
|
29
29
|
|
|
30
30
|
## Public Directory
|
|
31
31
|
|
|
32
|
-
The [`public/`](/docs/
|
|
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.
|
|
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/
|
|
39
|
-
- [`api/`](/docs/
|
|
40
|
-
- [`routes/`](/docs/
|
|
41
|
-
- [`middleware/`](/docs/
|
|
42
|
-
- [`plugins/`](/docs/
|
|
43
|
-
- [`utils/`](/docs/
|
|
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.
|
|
44
44
|
|
|
45
45
|
## Shared Directory
|
|
46
46
|
|
|
47
|
-
The [`shared/`](/docs/
|
|
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.
|
|
48
|
+
|
|
49
|
+
## Test Directory
|
|
50
|
+
|
|
51
|
+
The [`test/`](/docs/directory-structure/test) directory is the recommended place for application tests (unit, Nuxt runtime, and end-to-end). See [Organizing Your Tests](/docs/getting-started/testing#organizing-your-tests) for layout and setup details.
|
|
48
52
|
|
|
49
53
|
## Content Directory
|
|
50
54
|
|
|
51
|
-
The [`content/`](/docs/
|
|
55
|
+
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.
|
|
52
56
|
|
|
53
57
|
## Modules Directory
|
|
54
58
|
|
|
55
|
-
The [`modules/`](/docs/
|
|
59
|
+
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.
|
|
56
60
|
|
|
57
61
|
## Layers Directory
|
|
58
62
|
|
|
59
|
-
The [`layers/`](/docs/
|
|
63
|
+
The [`layers/`](/docs/directory-structure/layers) directory allows you to organize and share reusable code, components, composables, and configurations. Layers within this directory are automatically registered in your project.
|
|
60
64
|
|
|
61
65
|
## Nuxt Files
|
|
62
66
|
|
|
63
|
-
- [`nuxt.config.ts`](/docs/
|
|
64
|
-
- [`.nuxtrc`](/docs/
|
|
65
|
-
- [`.nuxtignore`](/docs/
|
|
67
|
+
- [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) file is the main configuration file for the Nuxt application.
|
|
68
|
+
- [`.nuxtrc`](/docs/directory-structure/nuxtrc) file is another syntax for configuring the Nuxt application (useful for global configurations).
|
|
69
|
+
- [`.nuxtignore`](/docs/directory-structure/nuxtignore) file is used to ignore files in the root directory during the build phase.
|
package/3.guide/0.index.md
CHANGED
|
@@ -7,22 +7,22 @@ surround: false
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
::card-group{class="sm:grid-cols-1"}
|
|
10
|
-
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/
|
|
10
|
+
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
|
|
11
11
|
Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
|
|
12
12
|
::
|
|
13
|
-
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/
|
|
13
|
+
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/guide/best-practices"}
|
|
14
14
|
Learn about best practices when developing with Nuxt.
|
|
15
15
|
::
|
|
16
|
-
::card{icon="i-lucide-bot" title="Working with AI" to="/docs/
|
|
16
|
+
::card{icon="i-lucide-bot" title="Working with AI" to="/docs/guide/ai"}
|
|
17
17
|
Integrate AI tools into your Nuxt workflow with MCP Server and LLMs.txt.
|
|
18
18
|
::
|
|
19
|
-
::card{icon="i-lucide-box" title="Module Author Guide" to="/docs/
|
|
19
|
+
::card{icon="i-lucide-box" title="Module Author Guide" to="/docs/guide/modules"}
|
|
20
20
|
Learn how to create Nuxt modules to integrate, enhance or extend any Nuxt application.
|
|
21
21
|
::
|
|
22
|
-
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/
|
|
22
|
+
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/guide/recipes"}
|
|
23
23
|
Find solutions to common problems and learn how to implement them in your Nuxt project.
|
|
24
24
|
::
|
|
25
|
-
::card{icon="i-lucide-star" title="Going Further" to="/docs/
|
|
25
|
+
::card{icon="i-lucide-star" title="Going Further" to="/docs/guide/going-further"}
|
|
26
26
|
Master Nuxt with advanced concepts like experimental features, hooks, and more.
|
|
27
27
|
::
|
|
28
28
|
::
|
|
@@ -3,11 +3,11 @@ title: 'Rendering Modes'
|
|
|
3
3
|
description: 'Learn about the different rendering modes available in Nuxt.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Nuxt supports different rendering modes, [universal rendering](/docs/
|
|
6
|
+
Nuxt supports different rendering modes, [universal rendering](/docs/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/guide/concepts/rendering#edge-side-rendering).
|
|
7
7
|
|
|
8
8
|
Both the browser and server can interpret JavaScript code to turn Vue.js components into HTML elements. This step is called **rendering**. Nuxt supports both **universal** and **client-side** rendering. The two approaches have benefits and downsides that we will cover.
|
|
9
9
|
|
|
10
|
-
By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/
|
|
10
|
+
By default, Nuxt uses **universal rendering** to provide better user experience, performance and to optimize search engine indexing, but you can switch rendering modes in [one line of configuration](/docs/api/nuxt-config#ssr).
|
|
11
11
|
|
|
12
12
|
## Universal Rendering
|
|
13
13
|
|
|
@@ -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/
|
|
47
|
+
[Middlewares](/docs/directory-structure/app/middleware) and [pages](/docs/directory-structure/app/pages) run in the server and on the client during hydration. [Plugins](/docs/directory-structure/app/plugins) can be rendered on the server or client or both. [Components](/docs/directory-structure/app/components) can be forced to run on the client only as well. [Composables](/docs/directory-structure/app/composables) and [utilities](/docs/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.
|
|
@@ -52,7 +52,7 @@ On the initial request, the `counter` ref is initialized in the server since it
|
|
|
52
52
|
|
|
53
53
|
**Downsides of server-side rendering:**
|
|
54
54
|
- **Development constraints:** Server and browser environments don't provide the same APIs, and it can be tricky to write code that can run on both sides seamlessly. Fortunately, Nuxt provides guidelines and specific variables to help you determine where a piece of code is executed.
|
|
55
|
-
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/
|
|
55
|
+
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/guide/concepts/rendering#edge-side-rendering).
|
|
56
56
|
|
|
57
57
|
Universal rendering is very versatile and can fit almost any use case, and is especially appropriate for any content-oriented websites: **blogs, marketing websites, portfolios, e-commerce sites, and marketplaces.**
|
|
58
58
|
|
|
@@ -91,14 +91,14 @@ export default defineNuxtConfig({
|
|
|
91
91
|
|
|
92
92
|
::note
|
|
93
93
|
If you do use `ssr: false`, you should also place an HTML file in `~/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
|
|
94
|
-
:read-more{title="SPA Loading Template" to="/docs/
|
|
94
|
+
:read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
95
95
|
::
|
|
96
96
|
|
|
97
97
|
:video-accordion{title="Watch a video from Alexander Lichter about Building a plain SPA with Nuxt" videoId="7Lr0QTP1Ro8"}
|
|
98
98
|
|
|
99
99
|
### Deploying a Static Client-Rendered App
|
|
100
100
|
|
|
101
|
-
If you deploy your app to [static hosting](/docs/
|
|
101
|
+
If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `nuxt generate` or `nuxt build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file.
|
|
102
102
|
|
|
103
103
|
::warning
|
|
104
104
|
If you prerender your app with the `nuxt generate` or `nuxt build --prerender` commands, then you will not be able to use any server endpoints as no server will be included in your output folder. If you need server functionality, use `nuxt build` instead.
|
|
@@ -106,7 +106,7 @@ If you prerender your app with the `nuxt generate` or `nuxt build --prerender` c
|
|
|
106
106
|
|
|
107
107
|
If you are using purely client-side rendering, then this might be unnecessary. You might only need a single `index.html` file, plus `200.html` and `404.html` fallbacks, which you can tell your static web host to serve up for all requests.
|
|
108
108
|
|
|
109
|
-
In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/
|
|
109
|
+
In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`:
|
|
110
110
|
|
|
111
111
|
```ts twoslash [nuxt.config.ts]
|
|
112
112
|
export default defineNuxtConfig({
|
|
@@ -133,9 +133,61 @@ Static hosts need an HTML shell for client-side routes and missing paths. Nuxt e
|
|
|
133
133
|
|
|
134
134
|
`nuxt generate` and `nuxt build --prerender` write these into `.output/public/`. A plain `nuxt build` without prerender does not. With hybrid route rules, add the fallbacks with route rules or run a prerender build if you need them. Point your host at the file your provider expects.
|
|
135
135
|
|
|
136
|
+
#### Server-rendering the Error Page
|
|
137
|
+
|
|
138
|
+
By default `404.html` is an empty shell, so your `error.vue` (and its layout and data) only appear once the client app has booted. You can prerender it instead:
|
|
139
|
+
|
|
140
|
+
```ts twoslash [nuxt.config.ts]
|
|
141
|
+
export default defineNuxtConfig({
|
|
142
|
+
experimental: {
|
|
143
|
+
prerenderErrorPages: true,
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Nuxt then renders `error.vue` at build time with a synthetic 404 error and writes the result to `404.html`, which hydrates in place at whatever URL your host served it from. Pass an array of status codes between 400 and 599 (`[404, 500]`) to emit additional pages, if your host can serve them.
|
|
149
|
+
|
|
150
|
+
Because a single file is served for every missing path, the error page cannot depend on the request: `useRoute()`, `useRequestURL()` and data fetched with the current path will hold the build-time values in the prerendered HTML and be corrected on hydration. Wrap request-specific markup in [`<ClientOnly>`](/docs/api/components/client-only), and skip request-specific data fetching with `import.meta.prerender`:
|
|
151
|
+
|
|
152
|
+
```vue [error.vue]
|
|
153
|
+
<script setup lang="ts">
|
|
154
|
+
import type { NuxtError } from '#app'
|
|
155
|
+
|
|
156
|
+
defineProps<{ error: NuxtError }>()
|
|
157
|
+
|
|
158
|
+
const route = useRoute()
|
|
159
|
+
|
|
160
|
+
const { data: suggestions } = await useAsyncData(
|
|
161
|
+
'error-suggestions',
|
|
162
|
+
() => $fetch('/api/suggestions', { query: { path: route.path } }),
|
|
163
|
+
// at build time the path is `/404.html`, so fetch on the client instead
|
|
164
|
+
{ server: !import.meta.prerender },
|
|
165
|
+
)
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<template>
|
|
169
|
+
<div>
|
|
170
|
+
<h1>{{ error.statusCode }}</h1>
|
|
171
|
+
<ClientOnly>
|
|
172
|
+
<p>Nothing found at {{ route.path }}</p>
|
|
173
|
+
</ClientOnly>
|
|
174
|
+
<ul v-if="suggestions">
|
|
175
|
+
<li
|
|
176
|
+
v-for="suggestion in suggestions"
|
|
177
|
+
:key="suggestion"
|
|
178
|
+
>
|
|
179
|
+
{{ suggestion }}
|
|
180
|
+
</li>
|
|
181
|
+
</ul>
|
|
182
|
+
</div>
|
|
183
|
+
</template>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`import.meta.prerender` is only `true` while the page is being generated, so the same `error.vue` still server-renders its data when the app is deployed with a server.
|
|
187
|
+
|
|
136
188
|
#### Skipping Client Fallback Generation
|
|
137
189
|
|
|
138
|
-
When prerendering a client-rendered app, Nuxt will generate `index.html`, `200.html` and `404.html` files by default. However, if you need to prevent any (or all) of these files from being generated in your build, you can use the `'prerender:generate'` hook from [Nitro](/docs/
|
|
190
|
+
When prerendering a client-rendered app, Nuxt will generate `index.html`, `200.html` and `404.html` files by default. However, if you need to prevent any (or all) of these files from being generated in your build, you can use the `'prerender:generate'` hook from [Nitro](/docs/getting-started/prerendering#prerendergenerate-nitro-hook).
|
|
139
191
|
|
|
140
192
|
```ts twoslash [nuxt.config.ts]
|
|
141
193
|
// @errors: 2353 7006
|
|
@@ -197,17 +249,29 @@ The different properties you can use are the following:
|
|
|
197
249
|
- `swr: number | boolean`{lang=ts} - Add cache headers to the server response and cache it on the server or reverse proxy for a configurable TTL (time to live). The `node-server` preset of Nitro is able to cache the full response. When the TTL expired, the cached response will be sent while the page will be regenerated in the background. If true is used, a `stale-while-revalidate` header is added without a MaxAge.
|
|
198
250
|
- `isr: number | boolean`{lang=ts} - The behavior is the same as `swr` except that we are able to add the response to the CDN cache on platforms that support this (currently Netlify or Vercel). If `true` is used, the content persists until the next deploy inside the CDN.
|
|
199
251
|
- `prerender: boolean`{lang=ts} - Prerenders routes at build time and includes them in your build as static assets
|
|
200
|
-
- `noScripts: boolean`{lang=ts} - Disables rendering of Nuxt scripts and JS resource hints for sections of your site.
|
|
252
|
+
- `noScripts: boolean`{lang=ts} - Disables rendering of Nuxt scripts and JS resource hints for sections of your site. Read more about [`noScripts`](/docs/guide/going-further/features#noscripts).
|
|
201
253
|
- `appMiddleware: string | string[] | Record<string, boolean>`{lang=ts} - Allows you to define middleware that should or should not run for page paths within the Vue app part of your application (that is, not your Nitro routes)
|
|
202
254
|
|
|
203
255
|
::note
|
|
204
|
-
Routes using `isr` or `swr` also generate `_payload.json` files alongside HTML. Client-side navigation loads these cached payloads instead of re-fetching data. Read more about [payload extraction](/docs/
|
|
256
|
+
Routes using `isr` or `swr` also generate `_payload.json` files alongside HTML. Client-side navigation loads these cached payloads instead of re-fetching data. Read more about [payload extraction](/docs/getting-started/prerendering#payload-extraction).
|
|
205
257
|
::
|
|
206
258
|
|
|
259
|
+
### Server Bundle Size with `ssr: false`
|
|
260
|
+
|
|
261
|
+
A route covered by `ssr: false` is only ever rendered in the browser, so Nuxt excludes its page component from the server bundle. This applies whenever the rules covering every path that reaches the page can be resolved at build time, including dynamic routes such as `pages/products/[id].vue` under a `/products/**` rule.
|
|
262
|
+
|
|
263
|
+
A page is kept in the server bundle when any path that reaches it might still be rendered on the server:
|
|
264
|
+
|
|
265
|
+
- a more specific rule re-enables SSR somewhere below the client-only one (`'/admin/**': { ssr: false }`{lang=ts} with `'/admin/report': { ssr: true }`{lang=ts})
|
|
266
|
+
- the page has an alias, or a child declared with an absolute path, that falls outside the client-only region
|
|
267
|
+
- the page is a parent shell rendering a child that is still server-rendered
|
|
268
|
+
|
|
269
|
+
This is a build-time optimization only; it does not change what the server sends to the browser.
|
|
270
|
+
|
|
207
271
|
Whenever possible, route rules will be automatically applied to the deployment platform's native rules for optimal performances (Netlify and Vercel are currently supported).
|
|
208
272
|
|
|
209
273
|
::important
|
|
210
|
-
Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/
|
|
274
|
+
Note that Hybrid Rendering is not available when using [`nuxt generate`](/docs/api/commands/generate).
|
|
211
275
|
::
|
|
212
276
|
|
|
213
277
|
**Examples:**
|
|
@@ -233,7 +297,7 @@ With ESR, the rendering process is pushed to the 'edge' of the network - the CDN
|
|
|
233
297
|
|
|
234
298
|
When a request for a page is made, instead of going all the way to the original server, it's intercepted by the nearest edge server. This server generates the HTML for the page and sends it back to the user. This process minimizes the physical distance the data has to travel, **reducing latency and loading the page faster**.
|
|
235
299
|
|
|
236
|
-
Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/
|
|
300
|
+
Edge-side rendering is possible thanks to [Nitro](https://nitro.build/), the [server engine](/docs/guide/concepts/server-engine) that powers Nuxt. It offers cross-platform support for Node.js, Deno, Cloudflare Workers, and more.
|
|
237
301
|
|
|
238
302
|
The current platforms where you can leverage ESR are:
|
|
239
303
|
- [Cloudflare Pages](https://pages.cloudflare.com) with zero configuration using the git integration and the `nuxt build` command
|
|
@@ -26,17 +26,82 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
26
26
|
|
|
27
27
|
### Auto-imports
|
|
28
28
|
|
|
29
|
-
Every Vue component created in the [`app/components/`](/docs/
|
|
29
|
+
Every Vue component created in the [`app/components/`](/docs/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.
|
|
30
30
|
|
|
31
|
-
:read-more{to="/docs/
|
|
31
|
+
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
32
32
|
|
|
33
33
|
### Vue Router
|
|
34
34
|
|
|
35
|
-
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/
|
|
35
|
+
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/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).
|
|
36
36
|
|
|
37
|
-
:read-more{to="/docs/
|
|
37
|
+
:read-more{to="/docs/getting-started/routing"}
|
|
38
38
|
|
|
39
|
-
:link-example{to="/docs/
|
|
39
|
+
:link-example{to="/docs/examples/features/auto-imports"}
|
|
40
|
+
|
|
41
|
+
## Vapor Mode
|
|
42
|
+
|
|
43
|
+
::warning
|
|
44
|
+
Vapor Mode support is experimental and requires Vue 3.6 or newer. The API may change.
|
|
45
|
+
::
|
|
46
|
+
|
|
47
|
+
[Vapor Mode](https://github.com/vuejs/core/releases/tag/v3.6.0-rc.1#about-vapor-mode) is an alternative compilation strategy introduced in Vue 3.6 that renders components without the Virtual DOM, lowering memory use and improving runtime performance.
|
|
48
|
+
|
|
49
|
+
Nuxt supports Vapor Mode in **interop mode**: your application is still rendered with the Virtual DOM, and you opt individual components or pages into Vapor by writing them as Vapor single-file components. This lets you adopt Vapor incrementally, and the rest of Nuxt (routing, `useAsyncData`, layouts, and most built-in components) keeps working unchanged.
|
|
50
|
+
|
|
51
|
+
### Enabling Vapor Mode
|
|
52
|
+
|
|
53
|
+
Enable the `vue.vapor` option in your Nuxt config:
|
|
54
|
+
|
|
55
|
+
```ts twoslash [nuxt.config.ts]
|
|
56
|
+
export default defineNuxtConfig({
|
|
57
|
+
vue: {
|
|
58
|
+
vapor: true,
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This installs Vue's `vaporInteropPlugin`, which lets Vapor and Virtual DOM components render alongside each other. You can then mark any component or page as Vapor by adding the `vapor` attribute to `<script setup>`:
|
|
64
|
+
|
|
65
|
+
```vue [app/pages/index.vue]
|
|
66
|
+
<script setup vapor lang="ts">
|
|
67
|
+
const count = ref(0)
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<button @click="count++">
|
|
72
|
+
count is {{ count }}
|
|
73
|
+
</button>
|
|
74
|
+
</template>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Trying it out
|
|
78
|
+
|
|
79
|
+
Vapor Mode needs a version of Vue that includes both Vapor and its interop fixes. While Vue 3.6 is in pre-release, install a release candidate (or newer) that contains those fixes:
|
|
80
|
+
|
|
81
|
+
```json [package.json]
|
|
82
|
+
{
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"vue": "^3.6.0-rc.2"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
If you enable `vue.vapor` on an older version of Vue, Nuxt warns and disables it.
|
|
90
|
+
|
|
91
|
+
We recommend trying Vapor Mode in a fresh project rather than adding it to an existing one. You can also explore a working setup in the [Nuxt Vapor demo](https://github.com/danielroe/nuxt-vapor-demo).
|
|
92
|
+
|
|
93
|
+
### Known limitations
|
|
94
|
+
|
|
95
|
+
Because Nuxt runs Vapor in interop mode, some patterns that rely on the Virtual DOM behave differently inside Vapor components:
|
|
96
|
+
|
|
97
|
+
- **Full Vapor apps are not yet supported.** The application root stays Virtual DOM and you opt in per component; we may support a full Vapor app later on.
|
|
98
|
+
- **Template refs** on a Vapor component do not expose `$el`.
|
|
99
|
+
- **Some built-in components inspect their slot content** and cannot read Vapor slot children. `<ClientOnly>` skips its attribute-forwarding fallthrough, and `<NuxtIsland>`, server components, and the head components that read text children (such as `<Title>`, `<Style>` and `<Noscript>`) warn if you pass a Vapor slot. Pass the value directly instead (for example, a string to `<Title>`).
|
|
100
|
+
- **The Options API is not supported** in Vapor components, so `asyncData` and `fetchKey` via `defineNuxtComponent` are unavailable. Use `<script setup>` with `useAsyncData` instead.
|
|
101
|
+
- **Keyed `onPrehydrate`** falls back to the unkeyed form (and warns in development), because there is no component instance to attach the key to.
|
|
102
|
+
- **Nuxt composables called after `await`** in a Vapor `<script setup>` may lose the Nuxt context. Call them before the first `await` where possible.
|
|
103
|
+
|
|
104
|
+
Most other Nuxt composables and built-in components work unchanged, because they rely on injection rather than on a component instance.
|
|
40
105
|
|
|
41
106
|
## Differences with Nuxt 2 / Vue 2
|
|
42
107
|
|
|
@@ -92,13 +157,13 @@ const increment = () => count.value++
|
|
|
92
157
|
|
|
93
158
|
The goal of Nuxt is to provide a great developer experience around the Composition API.
|
|
94
159
|
|
|
95
|
-
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core) from Vue and Nuxt [built-in composables](/docs/
|
|
96
|
-
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/
|
|
160
|
+
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core) from Vue and Nuxt [built-in composables](/docs/api/composables/use-async-data).
|
|
161
|
+
- Write your own auto-imported reusable functions in the [`app/composables/` directory](/docs/directory-structure/app/composables).
|
|
97
162
|
|
|
98
163
|
### TypeScript Support
|
|
99
164
|
|
|
100
165
|
Both Vue 3 and Nuxt 3+ are written in TypeScript. A fully typed codebase prevents mistakes and documents APIs usage. This doesn’t mean that you have to write your application in TypeScript to take advantage of it. With Nuxt 3, you can opt-in by renaming your file from `.js` to `.ts` , or add `<script setup lang="ts">` in a component.
|
|
101
166
|
|
|
102
|
-
::read-more{to="/docs/
|
|
167
|
+
::read-more{to="/docs/guide/concepts/typescript"}
|
|
103
168
|
Read the details about TypeScript in Nuxt
|
|
104
169
|
::
|
|
@@ -14,7 +14,7 @@ On the server, the following steps are executed for every initial request to you
|
|
|
14
14
|
|
|
15
15
|
Nuxt is powered by [Nitro](https://nitro.build/), a modern server engine.
|
|
16
16
|
|
|
17
|
-
When Nitro starts, it initializes and executes the plugins under the [`/server/plugins`](/docs/
|
|
17
|
+
When Nitro starts, it initializes and executes the plugins under the [`/server/plugins`](/docs/directory-structure/server#server-plugins) directory. These plugins can:
|
|
18
18
|
- Capture and handle application-wide errors.
|
|
19
19
|
- Register hooks that execute when Nitro shuts down.
|
|
20
20
|
- Register hooks for request lifecycle events, such as modifying responses.
|
|
@@ -23,7 +23,7 @@ When Nitro starts, it initializes and executes the plugins under the [`/server/p
|
|
|
23
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.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
|
-
:read-more{to="/docs/
|
|
26
|
+
:read-more{to="/docs/directory-structure/server#server-plugins"}
|
|
27
27
|
|
|
28
28
|
### Server middleware
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ After initializing the Nitro server, middleware under `server/middleware/` is ex
|
|
|
33
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!
|
|
34
34
|
::
|
|
35
35
|
|
|
36
|
-
:read-more{to="/docs/
|
|
36
|
+
:read-more{to="/docs/directory-structure/server#server-middleware"}
|
|
37
37
|
|
|
38
38
|
### App plugins
|
|
39
39
|
|
|
@@ -41,13 +41,13 @@ The Vue and Nuxt instances are created first. Afterward, Nuxt executes its app p
|
|
|
41
41
|
- Built-in plugins, such as Vue Router and `unhead`.
|
|
42
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`).
|
|
43
43
|
|
|
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/
|
|
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/directory-structure/app/plugins).
|
|
45
45
|
|
|
46
46
|
::callout{icon="i-lucide-lightbulb"}
|
|
47
|
-
After this step, Nuxt calls the [`app:created`](/docs/
|
|
47
|
+
After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
48
48
|
::
|
|
49
49
|
|
|
50
|
-
:read-more{to="/docs/
|
|
50
|
+
:read-more{to="/docs/directory-structure/app/plugins"}
|
|
51
51
|
|
|
52
52
|
### Route validation
|
|
53
53
|
|
|
@@ -56,9 +56,9 @@ After initializing plugins and before executing middleware, Nuxt calls the `vali
|
|
|
56
56
|
- The `validate` function should return `true` if the parameters are valid.
|
|
57
57
|
- If validation fails, it should return `false` or an object containing a `status` and/or `statusText` to terminate the request.
|
|
58
58
|
|
|
59
|
-
For more information, see the [Route Validation documentation](/docs/
|
|
59
|
+
For more information, see the [Route Validation documentation](/docs/getting-started/routing#route-validation).
|
|
60
60
|
|
|
61
|
-
:read-more{to="/docs/
|
|
61
|
+
:read-more{to="/docs/getting-started/routing#route-validation"}
|
|
62
62
|
|
|
63
63
|
### App middleware
|
|
64
64
|
|
|
@@ -71,11 +71,11 @@ In Nuxt, there are three types of middleware:
|
|
|
71
71
|
|
|
72
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.
|
|
73
73
|
|
|
74
|
-
For details about each type and examples, see the [Middleware documentation](/docs/
|
|
74
|
+
For details about each type and examples, see the [Middleware documentation](/docs/directory-structure/app/middleware).
|
|
75
75
|
|
|
76
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.
|
|
77
77
|
|
|
78
|
-
:read-more{to="/docs/
|
|
78
|
+
:read-more{to="/docs/directory-structure/app/middleware"}
|
|
79
79
|
|
|
80
80
|
### Page and components
|
|
81
81
|
|
|
@@ -100,11 +100,11 @@ Watch a video from Daniel Roe explaining Server Rendering and Global State.
|
|
|
100
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.
|
|
101
101
|
|
|
102
102
|
::callout{icon="i-lucide-lightbulb"}
|
|
103
|
-
After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/
|
|
103
|
+
After rendering the Vue application to HTML, Nuxt calls the [`app:rendered`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
104
104
|
::
|
|
105
105
|
|
|
106
106
|
::callout{icon="i-lucide-lightbulb"}
|
|
107
|
-
Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/
|
|
107
|
+
Before finalizing and sending the HTML, Nitro will call the [`render:html`](/docs/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.
|
|
108
108
|
::
|
|
109
109
|
|
|
110
110
|
::
|
|
@@ -122,10 +122,10 @@ This step is similar to the server-side execution and includes both built-in and
|
|
|
122
122
|
Custom plugins in the `app/plugins/` directory, such as those without a suffix (e.g., `myPlugin.ts`) and with the `.client` suffix (e.g., `myClientPlugin.client.ts`), are executed on the client side.
|
|
123
123
|
|
|
124
124
|
::callout{icon="i-lucide-lightbulb"}
|
|
125
|
-
After this step, Nuxt calls the [`app:created`](/docs/
|
|
125
|
+
After this step, Nuxt calls the [`app:created`](/docs/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
126
126
|
::
|
|
127
127
|
|
|
128
|
-
:read-more{to="/docs/
|
|
128
|
+
:read-more{to="/docs/directory-structure/app/plugins"}
|
|
129
129
|
|
|
130
130
|
### Route validation
|
|
131
131
|
|
|
@@ -135,20 +135,20 @@ This step is the same as the server-side execution and includes the `validate` m
|
|
|
135
135
|
|
|
136
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.
|
|
137
137
|
|
|
138
|
-
:read-more{to="/docs/
|
|
138
|
+
:read-more{to="/docs/directory-structure/app/middleware#when-middleware-runs"}
|
|
139
139
|
|
|
140
140
|
### Mount Vue app and hydrate
|
|
141
141
|
|
|
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/
|
|
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/directory-structure/app/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
|
|
143
143
|
|
|
144
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.
|
|
145
145
|
|
|
146
146
|
::callout{icon="i-lucide-lightbulb"}
|
|
147
|
-
Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/
|
|
147
|
+
Before mounting the Vue application, Nuxt calls the [`app:beforeMount`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
148
148
|
::
|
|
149
149
|
|
|
150
150
|
::callout{icon="i-lucide-lightbulb"}
|
|
151
|
-
After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/
|
|
151
|
+
After mounting the Vue application, Nuxt calls the [`app:mounted`](/docs/api/advanced/hooks#app-hooks-runtime) hook.
|
|
152
152
|
::
|
|
153
153
|
|
|
154
154
|
### Vue lifecycle
|
|
@@ -11,25 +11,25 @@ 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/
|
|
14
|
+
Thanks to its opinionated directory structure, Nuxt can auto-import your [`app/components/`](/docs/directory-structure/app/components), [`app/composables/`](/docs/directory-structure/app/composables) and [`app/utils/`](/docs/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
|
|
|
18
18
|
::note
|
|
19
|
-
In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/
|
|
19
|
+
In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code. You can find a reference for auto-imported components, composables and utilities in the [API section](/docs/api).
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
In the [`server`](/docs/
|
|
23
|
+
In the [`server`](/docs/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
::note
|
|
27
|
-
You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/
|
|
27
|
+
You can also auto-import functions exported from custom folders or third-party packages by configuring the [`imports`](/docs/api/nuxt-config#imports) section of your `nuxt.config` file.
|
|
28
28
|
::
|
|
29
29
|
|
|
30
30
|
## Built-in Auto-imports
|
|
31
31
|
|
|
32
|
-
Nuxt auto-imports functions and composables to perform [data fetching](/docs/
|
|
32
|
+
Nuxt auto-imports functions and composables to perform [data fetching](/docs/getting-started/data-fetching), get access to the [app context](/docs/api/composables/use-nuxt-app) and [runtime config](/docs/guide/going-further/runtime-config), manage [state](/docs/getting-started/state-management) or define components and plugins.
|
|
33
33
|
|
|
34
34
|
```vue twoslash
|
|
35
35
|
<script setup lang="ts">
|
|
@@ -66,7 +66,7 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
|
|
|
66
66
|
When using a composable that requires the Nuxt context inside a non-SFC component, you need to wrap your component with `defineNuxtComponent` instead of `defineComponent`
|
|
67
67
|
::
|
|
68
68
|
|
|
69
|
-
::read-more{to="/docs/
|
|
69
|
+
::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
|
|
70
70
|
Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
|
|
71
71
|
::
|
|
72
72
|
|
|
@@ -101,11 +101,11 @@ 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/
|
|
105
|
-
- `app/composables/` for [Vue composables](/docs/
|
|
104
|
+
- `app/components/` for [Vue components](/docs/directory-structure/app/components).
|
|
105
|
+
- `app/composables/` for [Vue composables](/docs/directory-structure/app/composables).
|
|
106
106
|
- `app/utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
|
-
:link-example{to="/docs/
|
|
108
|
+
:link-example{to="/docs/examples/features/auto-imports"}
|
|
109
109
|
|
|
110
110
|
::warning
|
|
111
111
|
**Auto-imported `ref` and `computed` won't be unwrapped in a component `<template>`.** :br
|
|
@@ -139,7 +139,7 @@ export default defineNuxtConfig({
|
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/
|
|
142
|
+
This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/guide/concepts/auto-imports#explicit-imports) from `#imports`.
|
|
143
143
|
|
|
144
144
|
### Partially Disabling Auto-imports
|
|
145
145
|
|
|
@@ -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/
|
|
170
|
+
:read-more{to="/docs/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
|
|