@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
|
@@ -12,14 +12,14 @@ We made everything so you can start writing `.vue` files from the beginning whil
|
|
|
12
12
|
Nuxt has no vendor lock-in, allowing you to deploy your application [**everywhere, even on the edge**](/blog/nuxt-on-the-edge).
|
|
13
13
|
|
|
14
14
|
::tip
|
|
15
|
-
If you want to play around with Nuxt in your browser, you can [try it out in one of our online sandboxes](/docs/
|
|
15
|
+
If you want to play around with Nuxt in your browser, you can [try it out in one of our online sandboxes](/docs/getting-started/installation#play-online).
|
|
16
16
|
::
|
|
17
17
|
|
|
18
18
|
## Automation and Conventions
|
|
19
19
|
|
|
20
20
|
Nuxt uses conventions and an opinionated directory structure to automate repetitive tasks and allow developers to focus on pushing features. The configuration file can still customize and override its default behaviors.
|
|
21
21
|
|
|
22
|
-
- **File-based routing:** define routes based on the structure of your [`app/pages/` directory](/docs/
|
|
22
|
+
- **File-based routing:** define routes based on the structure of your [`app/pages/` directory](/docs/directory-structure/app/pages). This can make it easier to organize your application and avoid the need for manual route configuration.
|
|
23
23
|
- **Code splitting:** Nuxt automatically splits your code into smaller chunks, which can help reduce the initial load time of your application.
|
|
24
24
|
- **Server-side rendering out of the box:** Nuxt comes with built-in SSR capabilities, so you don't have to set up a separate server yourself.
|
|
25
25
|
- **Auto-imports:** write Vue composables and components in their respective directories and use them without having to import them with the benefits of tree-shaking and optimized JS bundles.
|
|
@@ -44,29 +44,29 @@ Overall, server-side rendering can provide a faster and more efficient user expe
|
|
|
44
44
|
As Nuxt is a versatile framework, it gives you the possibility to statically render your whole application to a static hosting with `nuxt generate`,
|
|
45
45
|
disable SSR globally with the `ssr: false` option or leverage hybrid rendering by setting up the `routeRules` option.
|
|
46
46
|
|
|
47
|
-
:read-more{title="Nuxt rendering modes" to="/docs/
|
|
47
|
+
:read-more{title="Nuxt rendering modes" to="/docs/guide/concepts/rendering"}
|
|
48
48
|
|
|
49
49
|
### Server engine
|
|
50
50
|
|
|
51
|
-
The Nuxt server engine [Nitro](https://nitro.build/) unlocks new full-stack capabilities.
|
|
51
|
+
The Nuxt server engine, [Nitro](https://nitro.build/), unlocks new full-stack capabilities.
|
|
52
52
|
|
|
53
|
-
In development, it uses Rollup and Node.js workers for your server code and context isolation. It also generates your server API by reading files
|
|
53
|
+
In development, it uses Rollup and Node.js workers for your server code and context isolation. It also generates your server API by reading files from `server/api/` and server middleware from `server/middleware/`.
|
|
54
54
|
|
|
55
55
|
In production, Nitro builds your app and server into one universal `.output` directory. This output is light: minified and removed from any Node.js modules (except polyfills). You can deploy this output on any system supporting JavaScript, from Node.js, Serverless, Workers, Edge-side rendering or purely static.
|
|
56
56
|
|
|
57
|
-
:read-more{title="Nuxt server engine" to="/docs/
|
|
57
|
+
:read-more{title="Nuxt server engine" to="/docs/guide/concepts/server-engine"}
|
|
58
58
|
|
|
59
59
|
### Production-ready
|
|
60
60
|
|
|
61
61
|
A Nuxt application can be deployed on a Node or Deno server, pre-rendered to be hosted in static environments, or deployed to serverless and edge providers.
|
|
62
62
|
|
|
63
|
-
:read-more{title="Deployment section" to="/docs/
|
|
63
|
+
:read-more{title="Deployment section" to="/docs/getting-started/deployment"}
|
|
64
64
|
|
|
65
65
|
### Modular
|
|
66
66
|
|
|
67
67
|
A module system allows you to extend Nuxt with custom features and integrations with third-party services.
|
|
68
68
|
|
|
69
|
-
:read-more{title="Nuxt Modules Concept" to="/docs/
|
|
69
|
+
:read-more{title="Nuxt Modules Concept" to="/docs/guide/concepts/modules"}
|
|
70
70
|
|
|
71
71
|
### Architecture
|
|
72
72
|
|
|
@@ -108,9 +108,7 @@ Well done! A browser window should automatically open for <http://localhost:3000
|
|
|
108
108
|
::
|
|
109
109
|
|
|
110
110
|
::tip{icon="i-lucide-container"}
|
|
111
|
-
If you're using Docker or want a consistent development environment across machines, consider using a dev container.
|
|
112
|
-
|
|
113
|
-
[Learn more about dev containers](/docs/4.x/guide/best-practices/devcontainers)
|
|
111
|
+
If you're using Docker or want a consistent development environment across machines, consider using a dev container. [Learn more about dev containers.](/docs/guide/best-practices/devcontainers)
|
|
114
112
|
::
|
|
115
113
|
|
|
116
114
|
::
|
|
@@ -119,4 +117,4 @@ If you're using Docker or want a consistent development environment across machi
|
|
|
119
117
|
|
|
120
118
|
Now that you've created your Nuxt project, you are ready to start building your application.
|
|
121
119
|
|
|
122
|
-
:read-more{title="Nuxt Concepts" to="/docs/
|
|
120
|
+
:read-more{title="Nuxt Concepts" to="/docs/guide/concepts"}
|
|
@@ -4,11 +4,11 @@ description: Nuxt is configured with sensible defaults to make you productive.
|
|
|
4
4
|
navigation.icon: i-lucide-cog
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
By default, Nuxt is configured to cover most use cases. The [`nuxt.config.ts`](/docs/
|
|
7
|
+
By default, Nuxt is configured to cover most use cases. The [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) file can override or extend this default configuration.
|
|
8
8
|
|
|
9
9
|
## Nuxt Configuration
|
|
10
10
|
|
|
11
|
-
The [`nuxt.config.ts`](/docs/
|
|
11
|
+
The [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) file is located at the root of a Nuxt project and can override or extend the application's behavior.
|
|
12
12
|
|
|
13
13
|
A minimal configuration file exports the `defineNuxtConfig` function containing an object with your configuration. The `defineNuxtConfig` helper is globally available without import.
|
|
14
14
|
|
|
@@ -20,7 +20,7 @@ export default defineNuxtConfig({
|
|
|
20
20
|
|
|
21
21
|
This file will often be mentioned in the documentation, for example to add custom scripts, register modules or change rendering modes.
|
|
22
22
|
|
|
23
|
-
::read-more{to="/docs/
|
|
23
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
24
24
|
Every option is described in the **Configuration Reference**.
|
|
25
25
|
::
|
|
26
26
|
|
|
@@ -88,7 +88,7 @@ NUXT_API_SECRET=api_secret_token
|
|
|
88
88
|
|
|
89
89
|
::
|
|
90
90
|
|
|
91
|
-
These variables are exposed to the rest of your application using the [`useRuntimeConfig()`](/docs/
|
|
91
|
+
These variables are exposed to the rest of your application using the [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) composable.
|
|
92
92
|
|
|
93
93
|
```vue [app/pages/index.vue]
|
|
94
94
|
<script setup lang="ts">
|
|
@@ -96,7 +96,7 @@ const runtimeConfig = useRuntimeConfig()
|
|
|
96
96
|
</script>
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
:read-more{to="/docs/
|
|
99
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
100
100
|
|
|
101
101
|
## App Configuration
|
|
102
102
|
|
|
@@ -116,7 +116,7 @@ export default defineAppConfig({
|
|
|
116
116
|
})
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/
|
|
119
|
+
These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
120
120
|
|
|
121
121
|
```vue [app/pages/index.vue]
|
|
122
122
|
<script setup lang="ts">
|
|
@@ -124,7 +124,7 @@ const appConfig = useAppConfig()
|
|
|
124
124
|
</script>
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
:read-more{to="/docs/
|
|
127
|
+
:read-more{to="/docs/directory-structure/app/app-config"}
|
|
128
128
|
|
|
129
129
|
## `runtimeConfig` vs. `app.config`
|
|
130
130
|
|
|
@@ -145,20 +145,20 @@ As stated above, `runtimeConfig` and `app.config` are both used to expose variab
|
|
|
145
145
|
|
|
146
146
|
## External Configuration Files
|
|
147
147
|
|
|
148
|
-
Nuxt uses [`nuxt.config.ts`](/docs/
|
|
148
|
+
Nuxt uses [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) file as the single source of truth for configurations and skips reading external configuration files. During the course of building your project, you may have a need to configure those. The following table highlights common configurations and, where applicable, how they can be configured with Nuxt.
|
|
149
149
|
|
|
150
150
|
| Name | Config File | How To Configure |
|
|
151
151
|
|-----------------------------------|-------------------------|---------------------------------------------------------------------------|
|
|
152
|
-
| [Nitro](https://nitro.build) | ~~`nitro.config.ts`~~ | Use [`nitro`](/docs/
|
|
153
|
-
| [PostCSS](https://postcss.org) | ~~`postcss.config.js`~~ | Use [`postcss`](/docs/
|
|
154
|
-
| [Vite](https://vite.dev) | ~~`vite.config.ts`~~ | Use [`vite`](/docs/
|
|
155
|
-
| [webpack](https://webpack.js.org) | ~~`webpack.config.ts`~~ | Use [`webpack`](/docs/
|
|
152
|
+
| [Nitro](https://nitro.build) | ~~`nitro.config.ts`~~ | Use [`nitro`](/docs/api/nuxt-config#nitro) key in `nuxt.config` |
|
|
153
|
+
| [PostCSS](https://postcss.org) | ~~`postcss.config.js`~~ | Use [`postcss`](/docs/api/nuxt-config#postcss) key in `nuxt.config` |
|
|
154
|
+
| [Vite](https://vite.dev) | ~~`vite.config.ts`~~ | Use [`vite`](/docs/api/nuxt-config#vite) key in `nuxt.config` |
|
|
155
|
+
| [webpack](https://webpack.js.org) | ~~`webpack.config.ts`~~ | Use [`webpack`](/docs/api/nuxt-config#webpack-1) key in `nuxt.config` |
|
|
156
156
|
|
|
157
157
|
Here is a list of other common config files:
|
|
158
158
|
|
|
159
159
|
| Name | Config File | How To Configure |
|
|
160
160
|
|----------------------------------------------|-----------------------|-------------------------------------------------------------------------------|
|
|
161
|
-
| [TypeScript](https://www.typescriptlang.org) | `tsconfig.json` | [More Info](/docs/
|
|
161
|
+
| [TypeScript](https://www.typescriptlang.org) | `tsconfig.json` | [More Info](/docs/directory-structure/tsconfig) |
|
|
162
162
|
| [ESLint](https://eslint.org) | `eslint.config.js` | [More Info](https://eslint.org/docs/latest/use/configure/configuration-files) |
|
|
163
163
|
| [Prettier](https://prettier.io) | `prettier.config.js` | [More Info](https://prettier.io/docs/configuration.html) |
|
|
164
164
|
| [Stylelint](https://stylelint.io) | `stylelint.config.js` | [More Info](https://stylelint.io/user-guide/configure/) |
|
|
@@ -187,7 +187,7 @@ export default defineNuxtConfig({
|
|
|
187
187
|
})
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
:read-more{to="/docs/
|
|
190
|
+
:read-more{to="/docs/api/configuration/nuxt-config#vue"}
|
|
191
191
|
|
|
192
192
|
### With webpack
|
|
193
193
|
|
|
@@ -205,7 +205,7 @@ export default defineNuxtConfig({
|
|
|
205
205
|
})
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
:read-more{to="/docs/
|
|
208
|
+
:read-more{to="/docs/api/configuration/nuxt-config#loaders"}
|
|
209
209
|
|
|
210
210
|
### Enabling Experimental Vue Features
|
|
211
211
|
|
|
@@ -223,4 +223,4 @@ export default defineNuxtConfig({
|
|
|
223
223
|
|
|
224
224
|
Since Nuxt 3.9 and Vue 3.4, `reactivityTransform` has been moved from Vue to Vue Macros which has a [Nuxt integration](https://vue-macros.dev/guide/nuxt-integration.html).
|
|
225
225
|
|
|
226
|
-
:read-more{to="/docs/
|
|
226
|
+
:read-more{to="/docs/api/configuration/nuxt-config#vue-1"}
|
|
@@ -26,7 +26,7 @@ If you are familiar with Vue, you might wonder where `main.js` is (the file that
|
|
|
26
26
|
|
|
27
27
|

|
|
28
28
|
|
|
29
|
-
Most components are reusable pieces of the user interface, like buttons and menus. In Nuxt, you can create these components in the [`app/components/`](/docs/
|
|
29
|
+
Most components are reusable pieces of the user interface, like buttons and menus. In Nuxt, you can create these components in the [`app/components/`](/docs/directory-structure/app/components) directory, and they will be automatically available across your application without having to explicitly import them.
|
|
30
30
|
|
|
31
31
|
::code-group
|
|
32
32
|
|
|
@@ -55,9 +55,9 @@ Most components are reusable pieces of the user interface, like buttons and menu
|
|
|
55
55
|
|
|
56
56
|

|
|
57
57
|
|
|
58
|
-
Pages represent views for each specific route pattern. Every file in the [`app/pages/`](/docs/
|
|
58
|
+
Pages represent views for each specific route pattern. Every file in the [`app/pages/`](/docs/directory-structure/app/pages) directory represents a different route displaying its content.
|
|
59
59
|
|
|
60
|
-
To use pages, create an `app/pages/index.vue` file and add `<NuxtPage />` component to the [`app/app.vue`](/docs/
|
|
60
|
+
To use pages, create an `app/pages/index.vue` file and add `<NuxtPage />` component to the [`app/app.vue`](/docs/directory-structure/app/app) (or remove `app/app.vue` for default entry). You can now create more pages and their corresponding routes by adding new files in the [`app/pages/`](/docs/directory-structure/app/pages) directory.
|
|
61
61
|
|
|
62
62
|
::code-group
|
|
63
63
|
|
|
@@ -82,7 +82,7 @@ To use pages, create an `app/pages/index.vue` file and add `<NuxtPage />` compon
|
|
|
82
82
|
|
|
83
83
|
::
|
|
84
84
|
|
|
85
|
-
:read-more{title="Routing Section" to="/docs/
|
|
85
|
+
:read-more{title="Routing Section" to="/docs/getting-started/routing"}
|
|
86
86
|
|
|
87
87
|
## Layouts
|
|
88
88
|
|
|
@@ -91,7 +91,7 @@ To use pages, create an `app/pages/index.vue` file and add `<NuxtPage />` compon
|
|
|
91
91
|
Layouts are wrappers around pages that contain a common User Interface for several pages, such as header and footer displays. Layouts are Vue files using `<slot />` components to display the **page** content. The `app/layouts/default.vue` file will be used by default. Custom layouts can be set as part of your page metadata.
|
|
92
92
|
|
|
93
93
|
::note
|
|
94
|
-
If you only have a single layout in your application, we recommend using [`app/app.vue`](/docs/
|
|
94
|
+
If you only have a single layout in your application, we recommend using [`app/app.vue`](/docs/directory-structure/app/app) with [`<NuxtPage />`](/docs/api/components/nuxt-page) instead.
|
|
95
95
|
::
|
|
96
96
|
|
|
97
97
|
::code-group
|
|
@@ -137,12 +137,12 @@ If you only have a single layout in your application, we recommend using [`app/a
|
|
|
137
137
|
|
|
138
138
|
::
|
|
139
139
|
|
|
140
|
-
If you want to create more layouts and learn how to use them in your pages, find more information in the [Layouts section](/docs/
|
|
140
|
+
If you want to create more layouts and learn how to use them in your pages, find more information in the [Layouts section](/docs/directory-structure/app/layouts).
|
|
141
141
|
|
|
142
142
|
## Advanced: Extending the HTML Template
|
|
143
143
|
|
|
144
144
|
::note
|
|
145
|
-
If you only need to modify the `<head>`, you can refer to the [SEO and meta section](/docs/
|
|
145
|
+
If you only need to modify the `<head>`, you can refer to the [SEO and meta section](/docs/getting-started/seo-meta).
|
|
146
146
|
::
|
|
147
147
|
|
|
148
148
|
You can have full control over the HTML template by adding a Nitro plugin that registers a hook.
|
|
@@ -162,4 +162,4 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
162
162
|
})
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
:read-more{to="/docs/
|
|
165
|
+
:read-more{to="/docs/guide/going-further/hooks"}
|
|
@@ -6,14 +6,14 @@ navigation.icon: i-lucide-image
|
|
|
6
6
|
|
|
7
7
|
Nuxt uses two directories to handle assets like stylesheets, fonts or images.
|
|
8
8
|
|
|
9
|
-
- The [`public/`](/docs/
|
|
10
|
-
- The [`app/assets/`](/docs/
|
|
9
|
+
- The [`public/`](/docs/directory-structure/public) directory content is served at the server root as-is.
|
|
10
|
+
- The [`app/assets/`](/docs/directory-structure/app/assets) directory contains by convention every asset that you want the build tool (Vite or webpack) to process.
|
|
11
11
|
|
|
12
12
|
## Public Directory
|
|
13
13
|
|
|
14
|
-
The [`public/`](/docs/
|
|
14
|
+
The [`public/`](/docs/directory-structure/public) directory is used as a public server for static assets publicly available at a defined URL of your application.
|
|
15
15
|
|
|
16
|
-
You can get a file in the [`public/`](/docs/
|
|
16
|
+
You can get a file in the [`public/`](/docs/directory-structure/public) directory from your application's code or from a browser by the root URL `/`.
|
|
17
17
|
|
|
18
18
|
### Example
|
|
19
19
|
|
|
@@ -32,9 +32,9 @@ For example, referencing an image file in the `public/img/` directory, available
|
|
|
32
32
|
|
|
33
33
|
Nuxt uses [Vite](https://vite.dev/guide/assets) (default) or [webpack](https://webpack.js.org/guides/asset-management/) to build and bundle your application. The main function of these build tools is to process JavaScript files, but they can be extended through [plugins](https://vite.dev/plugins/) (for Vite) or [loaders](https://webpack.js.org/loaders/) (for webpack) to process other kinds of assets, like stylesheets, fonts or SVGs. This step transforms the original file, mainly for performance or caching purposes (such as stylesheet minification or browser cache invalidation).
|
|
34
34
|
|
|
35
|
-
By convention, Nuxt uses the [`app/assets/`](/docs/
|
|
35
|
+
By convention, Nuxt uses the [`app/assets/`](/docs/directory-structure/app/assets) directory to store these files but there is no auto-scan functionality for this directory, and you can use any other name for it.
|
|
36
36
|
|
|
37
|
-
In your application's code, you can reference a file located in the [`app/assets/`](/docs/
|
|
37
|
+
In your application's code, you can reference a file located in the [`app/assets/`](/docs/directory-structure/app/assets) directory by using the `~/assets/` path.
|
|
38
38
|
|
|
39
39
|
### Example
|
|
40
40
|
|
|
@@ -50,12 +50,12 @@ For example, referencing an image file that will be processed if a build tool is
|
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
::note
|
|
53
|
-
Nuxt won't serve files in the [`app/assets/`](/docs/
|
|
53
|
+
Nuxt won't serve files in the [`app/assets/`](/docs/directory-structure/app/assets) directory at a static URL like `/assets/my-file.png`. If you need a static URL, use the [`public/`](/docs/getting-started/assets#public-directory) directory.
|
|
54
54
|
::
|
|
55
55
|
|
|
56
56
|
### Static vs. Dynamic `src`
|
|
57
57
|
|
|
58
|
-
When an `src` is a static string literal in your template, the build tool rewrites it into a runtime helper that resolves the final URL. A public path such as `/img/nuxt.png` is wrapped so that your [`app.baseURL`](/docs/
|
|
58
|
+
When an `src` is a static string literal in your template, the build tool rewrites it into a runtime helper that resolves the final URL. A public path such as `/img/nuxt.png` is wrapped so that your [`app.baseURL`](/docs/api/nuxt-config#baseurl) is applied when the page renders, and a bundled path such as `~/assets/img/nuxt.png` additionally becomes an import that resolves to the hashed output file.
|
|
59
59
|
|
|
60
60
|
```vue
|
|
61
61
|
<template>
|
|
@@ -76,13 +76,13 @@ A bound `:src` whose value is assembled at runtime is opaque to the build tool,
|
|
|
76
76
|
</template>
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
A runtime-built public path like `/img/${name}.png` is therefore **not** prefixed with [`app.baseURL`](/docs/
|
|
79
|
+
A runtime-built public path like `/img/${name}.png` is therefore **not** prefixed with [`app.baseURL`](/docs/api/nuxt-config#baseurl). If your application is deployed below the origin root, prefix it yourself with [`useRuntimeConfig().app.baseURL`](/docs/api/composables/use-runtime-config) (for example via [`joinURL`](https://github.com/unjs/ufo#joinurl)).
|
|
80
80
|
|
|
81
81
|
The sections below cover how to handle each case when the path is only known at runtime.
|
|
82
82
|
|
|
83
83
|
#### Public Assets
|
|
84
84
|
|
|
85
|
-
If the files do not need to be processed or hashed, put them in the [`public/`](/docs/
|
|
85
|
+
If the files do not need to be processed or hashed, put them in the [`public/`](/docs/directory-structure/public) directory and reference them by URL:
|
|
86
86
|
|
|
87
87
|
```vue [app/app.vue]
|
|
88
88
|
<script setup lang="ts">
|
|
@@ -9,7 +9,7 @@ You can use CSS preprocessors, CSS frameworks, UI libraries and Nuxt modules to
|
|
|
9
9
|
|
|
10
10
|
## Local Stylesheets
|
|
11
11
|
|
|
12
|
-
If you're writing local stylesheets, the natural place to put them is the [`app/assets/` directory](/docs/
|
|
12
|
+
If you're writing local stylesheets, the natural place to put them is the [`app/assets/` directory](/docs/directory-structure/app/assets).
|
|
13
13
|
|
|
14
14
|
### Importing Within Components
|
|
15
15
|
|
|
@@ -37,7 +37,7 @@ The stylesheets will be inlined in the HTML rendered by Nuxt.
|
|
|
37
37
|
### The CSS Property
|
|
38
38
|
|
|
39
39
|
You can also use the `css` property in the Nuxt configuration.
|
|
40
|
-
The natural place for your stylesheets is the [`app/assets/` directory](/docs/
|
|
40
|
+
The natural place for your stylesheets is the [`app/assets/` directory](/docs/directory-structure/app/assets). You can then reference its path and Nuxt will include it to all the pages of your application.
|
|
41
41
|
|
|
42
42
|
```ts [nuxt.config.ts]
|
|
43
43
|
export default defineNuxtConfig({
|
|
@@ -125,7 +125,7 @@ export default defineNuxtConfig({
|
|
|
125
125
|
|
|
126
126
|
You can include external stylesheets in your application by adding a link element in the head section of your nuxt.config file. You can achieve this result using different methods. Note that local stylesheets can also be included this way.
|
|
127
127
|
|
|
128
|
-
You can manipulate the head with the [`app.head`](/docs/
|
|
128
|
+
You can manipulate the head with the [`app.head`](/docs/api/nuxt-config#head) property of your Nuxt configuration:
|
|
129
129
|
|
|
130
130
|
```ts twoslash [nuxt.config.ts]
|
|
131
131
|
export default defineNuxtConfig({
|
|
@@ -141,7 +141,7 @@ export default defineNuxtConfig({
|
|
|
141
141
|
|
|
142
142
|
You can use the useHead composable to dynamically set a value in your head in your code.
|
|
143
143
|
|
|
144
|
-
:read-more{to="/docs/
|
|
144
|
+
:read-more{to="/docs/api/composables/use-head"}
|
|
145
145
|
|
|
146
146
|
```ts twoslash
|
|
147
147
|
useHead({
|
|
@@ -286,7 +286,7 @@ This is an experimental option and you should refer to the Vite documentation an
|
|
|
286
286
|
|
|
287
287
|
## Single File Components (SFC) Styling
|
|
288
288
|
|
|
289
|
-
One of the best things about Vue and SFC is how great it is at naturally dealing with styling. You can directly write CSS or preprocessor code in the style block of your components file, therefore you will have fantastic developer experience without having to use something like CSS-in-JS. However if you wish to use CSS-in-JS, you can find 3rd party libraries and modules that support it, such as [pinceau](https://github.com/Tahul/pinceau).
|
|
289
|
+
One of the best things about Vue and SFC is how great it is at naturally dealing with styling. You can directly write CSS or preprocessor code in the style block of your components file, therefore you will have a fantastic developer experience without having to use something like CSS-in-JS. However if you wish to use CSS-in-JS, you can find 3rd party libraries and modules that support it, such as [pinceau](https://github.com/Tahul/pinceau).
|
|
290
290
|
|
|
291
291
|
You can refer to the [Vue docs](https://vuejs.org/api/sfc-css-features) for a comprehensive reference about styling components in SFC.
|
|
292
292
|
|
|
@@ -362,7 +362,7 @@ Refer to the [Vue docs](https://vuejs.org/guide/essentials/class-and-style) for
|
|
|
362
362
|
|
|
363
363
|
### Dynamic Styles With `v-bind`
|
|
364
364
|
|
|
365
|
-
You can reference JavaScript
|
|
365
|
+
You can reference JavaScript variables and expressions within your style blocks with the v-bind function.
|
|
366
366
|
The binding will be dynamic, meaning that if the variable value changes, the style will be updated.
|
|
367
367
|
|
|
368
368
|
```vue
|
|
@@ -504,7 +504,7 @@ Use different styles for different layouts.
|
|
|
504
504
|
</style>
|
|
505
505
|
```
|
|
506
506
|
|
|
507
|
-
:read-more{to="/docs/
|
|
507
|
+
:read-more{to="/docs/directory-structure/app/layouts"}
|
|
508
508
|
|
|
509
509
|
## Third Party Libraries And Modules
|
|
510
510
|
|
|
@@ -521,7 +521,7 @@ Here are a few modules to help you get started:
|
|
|
521
521
|
- [Nuxt UI](https://ui.nuxt.com): A UI Library for Modern Web Apps
|
|
522
522
|
- [Panda CSS](https://panda-css.com/docs/installation/nuxt): CSS-in-JS engine that generates atomic CSS at build time
|
|
523
523
|
|
|
524
|
-
Nuxt modules provide you with a good developer experience out of the box, but remember that if your favorite tool doesn't have a module, it doesn't mean that you can't use it with Nuxt! You can configure it yourself for your own project. Depending on the tool, you might need to use a [Nuxt plugin](/docs/
|
|
524
|
+
Nuxt modules provide you with a good developer experience out of the box, but remember that if your favorite tool doesn't have a module, it doesn't mean that you can't use it with Nuxt! You can configure it yourself for your own project. Depending on the tool, you might need to use a [Nuxt plugin](/docs/directory-structure/app/plugins) and/or [make your own module](/docs/guide/modules). Share them with the [community](/modules) if you do!
|
|
525
525
|
|
|
526
526
|
### Easily Load Webfonts
|
|
527
527
|
|
|
@@ -533,9 +533,9 @@ If you are using [UnoCSS](https://unocss.dev/integrations/nuxt), note that it co
|
|
|
533
533
|
|
|
534
534
|
### Transitions
|
|
535
535
|
|
|
536
|
-
Nuxt comes with the same `<Transition>` element that Vue has, and also has support for the experimental [View Transitions API](/docs/
|
|
536
|
+
Nuxt comes with the same `<Transition>` element that Vue has, and also has support for the experimental [View Transitions API](/docs/getting-started/transitions#view-transitions-api-experimental).
|
|
537
537
|
|
|
538
|
-
:read-more{to="/docs/
|
|
538
|
+
:read-more{to="/docs/getting-started/transitions"}
|
|
539
539
|
|
|
540
540
|
### Font Advanced Optimization
|
|
541
541
|
|
|
@@ -4,10 +4,10 @@ description: Nuxt file-system routing creates a route for every file in the page
|
|
|
4
4
|
navigation.icon: i-lucide-milestone
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
One core feature of Nuxt is the file system router. Every Vue file inside the [`app/pages/`](/docs/
|
|
7
|
+
One core feature of Nuxt is the file system router. Every Vue file inside the [`app/pages/`](/docs/directory-structure/app/pages) directory creates a corresponding URL (or route) that displays the contents of the file. By using dynamic imports for each page, Nuxt leverages code-splitting to ship the minimum amount of JavaScript for the requested route.
|
|
8
8
|
|
|
9
9
|
::note
|
|
10
|
-
Code-splitting is enabled by default and is recommended for most apps. If you have a specific reason to ship a single bundle instead, you can disable it in your [`nuxt.config`](/docs/
|
|
10
|
+
Code-splitting is enabled by default and is recommended for most apps. If you have a specific reason to ship a single bundle instead, you can disable it in your [`nuxt.config`](/docs/api/nuxt-config):
|
|
11
11
|
|
|
12
12
|
```ts [nuxt.config.ts]
|
|
13
13
|
export default defineNuxtConfig({
|
|
@@ -30,7 +30,7 @@ This ships all JavaScript in a single file. It is rarely beneficial — it usual
|
|
|
30
30
|
|
|
31
31
|
## Pages
|
|
32
32
|
|
|
33
|
-
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`app/pages/` directory](/docs/
|
|
33
|
+
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`app/pages/` directory](/docs/directory-structure/app/pages), based on their filename.
|
|
34
34
|
|
|
35
35
|
This file system routing uses naming conventions to create dynamic and nested routes:
|
|
36
36
|
|
|
@@ -65,13 +65,13 @@ This file system routing uses naming conventions to create dynamic and nested ro
|
|
|
65
65
|
|
|
66
66
|
::
|
|
67
67
|
|
|
68
|
-
:read-more{to="/docs/
|
|
68
|
+
:read-more{to="/docs/directory-structure/app/pages"}
|
|
69
69
|
|
|
70
70
|
## Navigation
|
|
71
71
|
|
|
72
|
-
The [`<NuxtLink>`](/docs/
|
|
72
|
+
The [`<NuxtLink>`](/docs/api/components/nuxt-link) component links pages between them. It renders an `<a>` tag with the `href` attribute set to the route of the page. Once the application is hydrated, page transitions are performed in JavaScript by updating the browser URL. This prevents full-page refreshes and allows for animated transitions.
|
|
73
73
|
|
|
74
|
-
When a [`<NuxtLink>`](/docs/
|
|
74
|
+
When a [`<NuxtLink>`](/docs/api/components/nuxt-link) enters the viewport on the client side, Nuxt will automatically prefetch components and payload (generated pages) of the linked pages ahead of time, resulting in faster navigation.
|
|
75
75
|
|
|
76
76
|
```vue [app/pages/index.vue]
|
|
77
77
|
<template>
|
|
@@ -87,11 +87,11 @@ When a [`<NuxtLink>`](/docs/4.x/api/components/nuxt-link) enters the viewport on
|
|
|
87
87
|
</template>
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
:read-more{to="/docs/
|
|
90
|
+
:read-more{to="/docs/api/components/nuxt-link"}
|
|
91
91
|
|
|
92
92
|
## Route Parameters
|
|
93
93
|
|
|
94
|
-
The [`useRoute()`](/docs/
|
|
94
|
+
The [`useRoute()`](/docs/api/composables/use-route) composable can be used in a `<script setup>` block or a `setup()` method of a Vue component to access the current route details.
|
|
95
95
|
|
|
96
96
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
97
97
|
<script setup lang="ts">
|
|
@@ -102,7 +102,7 @@ console.log(route.params.id)
|
|
|
102
102
|
</script>
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
:read-more{to="/docs/
|
|
105
|
+
:read-more{to="/docs/api/composables/use-route"}
|
|
106
106
|
|
|
107
107
|
## Route Middleware
|
|
108
108
|
|
|
@@ -113,14 +113,14 @@ Route middleware runs within the Vue part of your Nuxt app. Despite the similar
|
|
|
113
113
|
::
|
|
114
114
|
|
|
115
115
|
::important
|
|
116
|
-
Route middleware does **not** run for server routes (e.g. `/api/*`) or other server requests. To apply middleware to these requests, use [server middleware](/docs/
|
|
116
|
+
Route middleware does **not** run for server routes (e.g. `/api/*`) or other server requests. To apply middleware to these requests, use [server middleware](/docs/directory-structure/server#server-middleware) instead.
|
|
117
117
|
::
|
|
118
118
|
|
|
119
119
|
There are three kinds of route middleware:
|
|
120
120
|
|
|
121
121
|
1. Anonymous (or inline) route middleware, which are defined directly in the pages where they are used.
|
|
122
|
-
2. Named route middleware, which are placed in the [`app/middleware/`](/docs/
|
|
123
|
-
3. Global route middleware, which are placed in the [`app/middleware/`](/docs/
|
|
122
|
+
2. Named route middleware, which are placed in the [`app/middleware/`](/docs/directory-structure/app/middleware) directory and will be automatically loaded via asynchronous import when used on a page. (**Note**: The route middleware name is normalized to kebab-case, so `someMiddleware` becomes `some-middleware`.)
|
|
123
|
+
3. Global route middleware, which are placed in the [`app/middleware/`](/docs/directory-structure/app/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
124
124
|
|
|
125
125
|
Example of an `auth` middleware protecting the `/dashboard` page:
|
|
126
126
|
|
|
@@ -151,11 +151,11 @@ definePageMeta({
|
|
|
151
151
|
|
|
152
152
|
::
|
|
153
153
|
|
|
154
|
-
:read-more{to="/docs/
|
|
154
|
+
:read-more{to="/docs/directory-structure/app/middleware"}
|
|
155
155
|
|
|
156
156
|
## Route Validation
|
|
157
157
|
|
|
158
|
-
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/
|
|
158
|
+
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/api/utils/define-page-meta) in each page you wish to validate.
|
|
159
159
|
|
|
160
160
|
The `validate` property accepts the `route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return `false`, this will cause a 404 error. You can also directly return an object with `status`/`statusText` to customize the error returned.
|
|
161
161
|
|
|
@@ -172,4 +172,4 @@ definePageMeta({
|
|
|
172
172
|
</script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
:read-more{to="/docs/
|
|
175
|
+
:read-more{to="/docs/api/utils/define-page-meta"}
|
|
@@ -9,7 +9,7 @@ and numerous configuration options to manage your app's head and SEO meta tags.
|
|
|
9
9
|
|
|
10
10
|
## Nuxt Config
|
|
11
11
|
|
|
12
|
-
Providing an [`app.head`](/docs/
|
|
12
|
+
Providing an [`app.head`](/docs/api/nuxt-config#head) property in your [`nuxt.config.ts`](/docs/directory-structure/nuxt-config) allows you to statically customize the head for your entire app.
|
|
13
13
|
|
|
14
14
|
::important
|
|
15
15
|
This method does not allow you to provide reactive data. We recommend using `useHead()` in `app.vue`.
|
|
@@ -34,7 +34,7 @@ export default defineNuxtConfig({
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
::note
|
|
37
|
-
When you set [`app.cdnURL`](/docs/
|
|
37
|
+
When you set [`app.cdnURL`](/docs/api/nuxt-config#cdnurl), assets in your [`public/`](/docs/directory-structure/public) directory (including `favicon.ico`) are served from that CDN. Nuxt resolves public assets against `cdnURL`, falling back to `app.baseURL`. However, a static `app.head` link such as `href: '/favicon.ico'` above is a literal path and is **not** resolved against `cdnURL`. To point the favicon at the resolved location, build the `href` from runtime config with [`useHead()`](/docs/api/composables/use-head) in `app.vue`:
|
|
38
38
|
|
|
39
39
|
```vue [app/app.vue]
|
|
40
40
|
<script setup lang="ts">
|
|
@@ -48,7 +48,7 @@ useHead({
|
|
|
48
48
|
```
|
|
49
49
|
::
|
|
50
50
|
|
|
51
|
-
You can also provide any of the keys listed below in [Types](/docs/
|
|
51
|
+
You can also provide any of the keys listed below in [Types](/docs/getting-started/seo-meta#types).
|
|
52
52
|
|
|
53
53
|
### Default Tags
|
|
54
54
|
|
|
@@ -73,7 +73,7 @@ export default defineNuxtConfig({
|
|
|
73
73
|
|
|
74
74
|
## `useHead`
|
|
75
75
|
|
|
76
|
-
The [`useHead`](/docs/
|
|
76
|
+
The [`useHead`](/docs/api/composables/use-head) composable function supports reactive input, allowing you to manage your head tags programmatically.
|
|
77
77
|
|
|
78
78
|
```vue twoslash [app/app.vue]
|
|
79
79
|
<script setup lang="ts">
|
|
@@ -90,11 +90,11 @@ useHead({
|
|
|
90
90
|
</script>
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
We recommend taking a look at the [`useHead`](/docs/
|
|
93
|
+
We recommend taking a look at the [`useHead`](/docs/api/composables/use-head) and [`useHeadSafe`](/docs/api/composables/use-head-safe) composables.
|
|
94
94
|
|
|
95
95
|
## `useSeoMeta`
|
|
96
96
|
|
|
97
|
-
The [`useSeoMeta`](/docs/
|
|
97
|
+
The [`useSeoMeta`](/docs/api/composables/use-seo-meta) composable lets you define your site's SEO meta tags as an object with full type safety.
|
|
98
98
|
|
|
99
99
|
This helps you avoid typos and common mistakes, such as using `name` instead of `property`.
|
|
100
100
|
|
|
@@ -111,11 +111,11 @@ useSeoMeta({
|
|
|
111
111
|
</script>
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
:read-more{to="/docs/
|
|
114
|
+
:read-more{to="/docs/api/composables/use-seo-meta"}
|
|
115
115
|
|
|
116
116
|
## Components
|
|
117
117
|
|
|
118
|
-
While using [`useHead`](/docs/
|
|
118
|
+
While using [`useHead`](/docs/api/composables/use-head) is recommended in all cases, you may have a personal preference for defining your head tags in your template using components.
|
|
119
119
|
|
|
120
120
|
Nuxt provides the following components for this purpose: `<Title>`, `<Base>`, `<NoScript>`, `<Style>`, `<Meta>`, `<Link>`, `<Body>`, `<Html>` and `<Head>`. Note
|
|
121
121
|
the capitalization of these components ensuring we don't use invalid native HTML tags.
|
|
@@ -147,7 +147,7 @@ const title = ref('Hello World')
|
|
|
147
147
|
</template>
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
It's suggested to wrap your components in either a `<Head>` or `<Html>`
|
|
150
|
+
It's suggested to wrap your components in either a `<Head>` or `<Html>` component as tags will be deduped more intuitively.
|
|
151
151
|
|
|
152
152
|
::warning
|
|
153
153
|
If you need to duplicate tags across client-server boundaries, apply a `key` attribute on the `<Head>` component.
|
|
@@ -155,7 +155,7 @@ If you need to duplicate tags across client-server boundaries, apply a `key` att
|
|
|
155
155
|
|
|
156
156
|
## Types
|
|
157
157
|
|
|
158
|
-
Below are the non-reactive types used for [`useHead`](/docs/
|
|
158
|
+
Below are the non-reactive types used for [`useHead`](/docs/api/composables/use-head), [`app.head`](/docs/api/nuxt-config#head) and components.
|
|
159
159
|
|
|
160
160
|
```ts [Types]
|
|
161
161
|
interface MetaObject {
|
|
@@ -244,7 +244,7 @@ If you want to use a function (for full control), then this cannot be set in you
|
|
|
244
244
|
|
|
245
245
|
::
|
|
246
246
|
|
|
247
|
-
Now, if you set the title to `My Page` with [`useHead`](/docs/
|
|
247
|
+
Now, if you set the title to `My Page` with [`useHead`](/docs/api/composables/use-head) on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `null` to default to 'Site Title'.
|
|
248
248
|
|
|
249
249
|
### Template Parameters
|
|
250
250
|
|
|
@@ -292,7 +292,7 @@ useHead({
|
|
|
292
292
|
|
|
293
293
|
### With `definePageMeta`
|
|
294
294
|
|
|
295
|
-
Within your [`app/pages/` directory](/docs/
|
|
295
|
+
Within your [`app/pages/` directory](/docs/directory-structure/app/pages), you can use `definePageMeta` along with [`useHead`](/docs/api/composables/use-head) to set metadata based on the current route.
|
|
296
296
|
|
|
297
297
|
For example, you can first set the current page title (this is extracted at build time via a macro, so it can't be set dynamically):
|
|
298
298
|
|
|
@@ -316,9 +316,9 @@ useHead({
|
|
|
316
316
|
</script>
|
|
317
317
|
```
|
|
318
318
|
|
|
319
|
-
:link-example{to="/docs/
|
|
319
|
+
:link-example{to="/docs/examples/features/meta-tags"}
|
|
320
320
|
|
|
321
|
-
:read-more{to="/docs/
|
|
321
|
+
:read-more{to="/docs/directory-structure/app/pages/#page-metadata"}
|
|
322
322
|
|
|
323
323
|
### Dynamic Title
|
|
324
324
|
|
|
@@ -351,7 +351,7 @@ useHead({
|
|
|
351
351
|
|
|
352
352
|
### External CSS
|
|
353
353
|
|
|
354
|
-
The example below shows how you might enable Google Fonts using either the `link` property of the [`useHead`](/docs/
|
|
354
|
+
The example below shows how you might enable Google Fonts using either the `link` property of the [`useHead`](/docs/api/composables/use-head) composable or using the `<Link>` component:
|
|
355
355
|
|
|
356
356
|
::code-group
|
|
357
357
|
|