@nuxt/docs-nightly 4.1.3-29300098.2f71703a → 4.1.3-29303775.dc69e26c
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 +2 -2
- package/1.getting-started/03.configuration.md +10 -10
- package/1.getting-started/04.views.md +6 -6
- package/1.getting-started/05.assets.md +7 -7
- package/1.getting-started/06.styling.md +5 -5
- package/1.getting-started/07.routing.md +8 -8
- package/1.getting-started/08.seo-meta.md +10 -10
- package/1.getting-started/09.transitions.md +11 -11
- package/1.getting-started/10.data-fetching.md +36 -36
- package/1.getting-started/11.state-management.md +7 -7
- package/1.getting-started/12.error-handling.md +9 -9
- package/1.getting-started/14.layers.md +3 -3
- package/1.getting-started/15.prerendering.md +4 -4
- package/1.getting-started/16.deployment.md +2 -2
- package/1.getting-started/17.testing.md +3 -3
- package/1.getting-started/18.upgrade.md +3 -3
- package/2.guide/1.concepts/1.auto-imports.md +8 -8
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +10 -10
- package/2.guide/1.concepts/2.vuejs-development.md +4 -4
- package/2.guide/1.concepts/3.rendering.md +9 -9
- package/2.guide/1.concepts/4.server-engine.md +5 -5
- package/2.guide/1.concepts/5.modules.md +2 -2
- package/2.guide/1.concepts/7.esm.md +3 -3
- package/2.guide/1.concepts/8.typescript.md +8 -8
- package/2.guide/2.directory-structure/0.nuxt.md +2 -2
- package/2.guide/2.directory-structure/0.output.md +2 -2
- package/2.guide/2.directory-structure/1.app/1.assets.md +2 -2
- package/2.guide/2.directory-structure/1.app/1.components.md +5 -5
- package/2.guide/2.directory-structure/1.app/1.composables.md +3 -3
- package/2.guide/2.directory-structure/1.app/1.layouts.md +6 -6
- package/2.guide/2.directory-structure/1.app/1.middleware.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.pages.md +14 -14
- package/2.guide/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.guide/2.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/2.directory-structure/1.app/3.app-config.md +5 -5
- package/2.guide/2.directory-structure/1.app/3.app.md +3 -3
- package/2.guide/2.directory-structure/1.app/3.error.md +1 -1
- package/2.guide/2.directory-structure/1.content.md +2 -2
- package/2.guide/2.directory-structure/1.modules.md +2 -2
- package/2.guide/2.directory-structure/1.node_modules.md +1 -1
- package/2.guide/2.directory-structure/1.server.md +5 -5
- package/2.guide/2.directory-structure/1.shared.md +2 -2
- package/2.guide/2.directory-structure/2.env.md +4 -4
- package/2.guide/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.guide/2.directory-structure/2.nuxtrc.md +2 -2
- package/2.guide/2.directory-structure/3.nuxt-config.md +1 -1
- package/2.guide/2.directory-structure/3.tsconfig.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +9 -9
- package/2.guide/3.going-further/1.internals.md +10 -10
- package/2.guide/3.going-further/10.runtime-config.md +4 -4
- package/2.guide/3.going-further/2.hooks.md +3 -3
- package/2.guide/3.going-further/3.modules.md +16 -16
- package/2.guide/3.going-further/4.kit.md +2 -2
- package/2.guide/3.going-further/6.nuxt-app.md +4 -4
- package/2.guide/3.going-further/7.layers.md +11 -11
- package/2.guide/4.recipes/1.custom-routing.md +11 -11
- package/2.guide/4.recipes/2.vite-plugin.md +1 -1
- package/2.guide/4.recipes/3.custom-usefetch.md +3 -3
- package/2.guide/4.recipes/4.sessions-and-authentication.md +1 -1
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +4 -4
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +2 -2
- package/3.api/1.components/2.nuxt-page.md +2 -2
- package/3.api/1.components/3.nuxt-layout.md +2 -2
- package/3.api/1.components/4.nuxt-link.md +3 -3
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/2.composables/use-async-data.md +6 -6
- package/3.api/2.composables/use-cookie.md +2 -2
- package/3.api/2.composables/use-fetch.md +4 -4
- package/3.api/2.composables/use-head-safe.md +2 -2
- package/3.api/2.composables/use-head.md +2 -2
- package/3.api/2.composables/use-hydration.md +1 -1
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +2 -2
- package/3.api/2.composables/use-nuxt-app.md +12 -12
- package/3.api/2.composables/use-nuxt-data.md +1 -1
- package/3.api/2.composables/use-preview-mode.md +3 -3
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +2 -2
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +1 -1
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +2 -2
- package/3.api/2.composables/use-route-announcer.md +1 -1
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +4 -4
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +1 -1
- package/3.api/2.composables/use-server-seo-meta.md +3 -3
- package/3.api/2.composables/use-state.md +1 -1
- package/3.api/3.utils/$fetch.md +4 -4
- package/3.api/3.utils/abort-navigation.md +1 -1
- package/3.api/3.utils/add-route-middleware.md +2 -2
- package/3.api/3.utils/call-once.md +1 -1
- package/3.api/3.utils/clear-error.md +1 -1
- package/3.api/3.utils/clear-nuxt-data.md +1 -1
- package/3.api/3.utils/clear-nuxt-state.md +1 -1
- package/3.api/3.utils/define-nuxt-plugin.md +3 -3
- package/3.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/3.api/3.utils/define-page-meta.md +8 -8
- package/3.api/3.utils/define-route-rules.md +2 -2
- package/3.api/3.utils/navigate-to.md +1 -1
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +1 -1
- package/3.api/3.utils/refresh-nuxt-data.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +1 -1
- package/3.api/3.utils/show-error.md +2 -2
- package/3.api/3.utils/update-app-config.md +1 -1
- package/3.api/4.commands/module.md +2 -2
- package/3.api/4.commands/prepare.md +1 -1
- package/3.api/4.commands/preview.md +2 -2
- package/3.api/4.commands/typecheck.md +1 -1
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/3.compatibility.md +2 -2
- package/3.api/5.kit/4.autoimports.md +1 -1
- package/3.api/5.kit/5.components.md +2 -2
- package/3.api/5.kit/7.pages.md +3 -3
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.nuxt-config.md +4 -4
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +10 -10
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +5 -5
- 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/2.configuration.md +5 -5
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +3 -3
- package/7.migration/6.pages-and-layouts.md +8 -8
- package/7.migration/7.component-options.md +11 -11
- package/7.migration/8.runtime-config.md +3 -3
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ description: "Nuxt provides a runtime config API to expose configuration and sec
|
|
|
5
5
|
|
|
6
6
|
## Exposing
|
|
7
7
|
|
|
8
|
-
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your [`nuxt.config`](/docs/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig) option.
|
|
8
|
+
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your [`nuxt.config`](/docs/4.x/guide/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/4.x/api/nuxt-config#runtimeconfig) option.
|
|
9
9
|
|
|
10
10
|
```ts [nuxt.config.ts]
|
|
11
11
|
export default defineNuxtConfig({
|
|
@@ -87,7 +87,7 @@ export default defineNuxtConfig({
|
|
|
87
87
|
|
|
88
88
|
### Vue App
|
|
89
89
|
|
|
90
|
-
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) to access the runtime config.
|
|
90
|
+
Within the Vue part of your Nuxt app, you will need to call [`useRuntimeConfig()`](/docs/4.x/api/composables/use-runtime-config) to access the runtime config.
|
|
91
91
|
|
|
92
92
|
::important
|
|
93
93
|
The behavior is different between the client-side and server-side:
|
|
@@ -120,7 +120,7 @@ if (import.meta.server) {
|
|
|
120
120
|
|
|
121
121
|
### Plugins
|
|
122
122
|
|
|
123
|
-
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
123
|
+
If you want to use the runtime config within any (custom) plugin, you can use [`useRuntimeConfig()`](/docs/4.x/api/composables/use-runtime-config) inside of your `defineNuxtPlugin` function.
|
|
124
124
|
|
|
125
125
|
```ts [app/plugins/config.ts]
|
|
126
126
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -147,7 +147,7 @@ export default defineEventHandler(async (event) => {
|
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
::note
|
|
150
|
-
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
150
|
+
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/4.x/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
151
151
|
::
|
|
152
152
|
|
|
153
153
|
## Typing Runtime Config
|
|
@@ -9,7 +9,7 @@ The hooking system is powered by [unjs/hookable](https://github.com/unjs/hookabl
|
|
|
9
9
|
|
|
10
10
|
## Nuxt Hooks (Build Time)
|
|
11
11
|
|
|
12
|
-
These hooks are available for [Nuxt Modules](/docs/guide/going-further/modules) and build context.
|
|
12
|
+
These hooks are available for [Nuxt Modules](/docs/4.x/guide/going-further/modules) and build context.
|
|
13
13
|
|
|
14
14
|
### Within `nuxt.config.ts`
|
|
15
15
|
|
|
@@ -39,7 +39,7 @@ Explore all available Nuxt hooks.
|
|
|
39
39
|
|
|
40
40
|
## App Hooks (Runtime)
|
|
41
41
|
|
|
42
|
-
App hooks can be mainly used by [Nuxt Plugins](/docs/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/4.x/guide/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
44
|
```js [app/plugins/test.ts]
|
|
45
45
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -55,7 +55,7 @@ Explore all available App hooks.
|
|
|
55
55
|
|
|
56
56
|
## Server Hooks (Runtime)
|
|
57
57
|
|
|
58
|
-
These hooks are available for [server plugins](/docs/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
58
|
+
These hooks are available for [server plugins](/docs/4.x/guide/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
59
59
|
|
|
60
60
|
```js [~/server/plugins/test.ts]
|
|
61
61
|
export default defineNitroPlugin((nitroApp) => {
|
|
@@ -4,7 +4,7 @@ description: "Learn how to create a Nuxt Module to integrate, enhance or extend
|
|
|
4
4
|
image: '/socials/module-author-guide.jpg'
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Nuxt's [configuration](/docs/api/nuxt-config) and [hooks](/docs/guide/going-further/hooks) systems make it possible to customize every aspect of Nuxt and add any integration you might need (Vue plugins, CMS, server routes, components, logging, etc.).
|
|
7
|
+
Nuxt's [configuration](/docs/4.x/api/nuxt-config) and [hooks](/docs/4.x/guide/going-further/hooks) systems make it possible to customize every aspect of Nuxt and add any integration you might need (Vue plugins, CMS, server routes, components, logging, etc.).
|
|
8
8
|
|
|
9
9
|
**Nuxt Modules** are functions that sequentially run when starting Nuxt in development mode using `nuxt dev` or building a project for production with `nuxt build`.
|
|
10
10
|
With modules, you can encapsulate, properly test, and share custom solutions as npm packages without adding unnecessary boilerplate to your project, or requiring changes to Nuxt itself.
|
|
@@ -117,7 +117,7 @@ Nuxt Modules come with a variety of powerful APIs and patterns allowing them to
|
|
|
117
117
|
We can consider two kinds of Nuxt Modules:
|
|
118
118
|
|
|
119
119
|
- published modules are distributed on npm - you can see a list of some community modules on [the Nuxt website](/modules).
|
|
120
|
-
- "local" modules, they exist within a Nuxt project itself, either [inlined in Nuxt config](/docs/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/guide/directory-structure/modules).
|
|
120
|
+
- "local" modules, they exist within a Nuxt project itself, either [inlined in Nuxt config](/docs/4.x/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/4.x/guide/directory-structure/modules).
|
|
121
121
|
|
|
122
122
|
In either case, their anatomy is similar.
|
|
123
123
|
|
|
@@ -142,7 +142,7 @@ export default function (inlineOptions, nuxt) {
|
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
You can get type-hint support for this function using the higher-level `defineNuxtModule` helper provided by [Nuxt Kit](/docs/guide/going-further/kit).
|
|
145
|
+
You can get type-hint support for this function using the higher-level `defineNuxtModule` helper provided by [Nuxt Kit](/docs/4.x/guide/going-further/kit).
|
|
146
146
|
|
|
147
147
|
```ts
|
|
148
148
|
import { defineNuxtModule } from '@nuxt/kit'
|
|
@@ -224,9 +224,9 @@ Modules, like everything in a Nuxt configuration, aren't included in your applic
|
|
|
224
224
|
Inside the runtime directory, you can provide any kind of assets related to the Nuxt App:
|
|
225
225
|
- Vue components
|
|
226
226
|
- Composables
|
|
227
|
-
- [Nuxt plugins](/docs/guide/directory-structure/plugins)
|
|
227
|
+
- [Nuxt plugins](/docs/4.x/guide/directory-structure/plugins)
|
|
228
228
|
|
|
229
|
-
To the [server engine](/docs/guide/concepts/server-engine), Nitro:
|
|
229
|
+
To the [server engine](/docs/4.x/guide/concepts/server-engine), Nitro:
|
|
230
230
|
- API routes
|
|
231
231
|
- Middlewares
|
|
232
232
|
- Nitro plugins
|
|
@@ -237,10 +237,10 @@ Or any other kind of asset you want to inject in users' Nuxt applications:
|
|
|
237
237
|
- Images
|
|
238
238
|
- etc.
|
|
239
239
|
|
|
240
|
-
You'll then be able to inject all those assets inside the application from your [module definition](#module-definition).
|
|
240
|
+
You'll then be able to inject all those assets inside the application from your [module definition](/docs/guide/going-further/modules#module-definition).
|
|
241
241
|
|
|
242
242
|
::tip
|
|
243
|
-
Learn more about asset injection in [the recipes section](#recipes).
|
|
243
|
+
Learn more about asset injection in [the recipes section](/docs/guide/going-further/modules#recipes).
|
|
244
244
|
::
|
|
245
245
|
|
|
246
246
|
::warning
|
|
@@ -259,13 +259,13 @@ Modules come with a set of first-party tools to help you with their development.
|
|
|
259
259
|
|
|
260
260
|
#### `@nuxt/kit`
|
|
261
261
|
|
|
262
|
-
[Nuxt Kit](/docs/guide/going-further/kit) provides composable utilities to help your module interact with Nuxt applications. It's recommended to use Nuxt Kit utilities over manual alternatives whenever possible to ensure better compatibility and code readability of your module.
|
|
262
|
+
[Nuxt Kit](/docs/4.x/guide/going-further/kit) provides composable utilities to help your module interact with Nuxt applications. It's recommended to use Nuxt Kit utilities over manual alternatives whenever possible to ensure better compatibility and code readability of your module.
|
|
263
263
|
|
|
264
264
|
:read-more{to="/docs/guide/going-further/kit"}
|
|
265
265
|
|
|
266
266
|
#### `@nuxt/test-utils`
|
|
267
267
|
|
|
268
|
-
[Nuxt Test Utils](/docs/getting-started/testing) is a collection of utilities to help set up and run Nuxt applications within your module tests.
|
|
268
|
+
[Nuxt Test Utils](/docs/4.x/getting-started/testing) is a collection of utilities to help set up and run Nuxt applications within your module tests.
|
|
269
269
|
|
|
270
270
|
### Recipes
|
|
271
271
|
|
|
@@ -295,7 +295,7 @@ Watch Vue School video about altering Nuxt configuration.
|
|
|
295
295
|
|
|
296
296
|
#### Exposing Options to Runtime
|
|
297
297
|
|
|
298
|
-
Because modules aren't part of the application runtime, their options aren't either. However, in many cases, you might need access to some of these module options within your runtime code. We recommend exposing the needed config using Nuxt's [`runtimeConfig`](/docs/api/nuxt-config#runtimeconfig).
|
|
298
|
+
Because modules aren't part of the application runtime, their options aren't either. However, in many cases, you might need access to some of these module options within your runtime code. We recommend exposing the needed config using Nuxt's [`runtimeConfig`](/docs/4.x/api/nuxt-config#runtimeconfig).
|
|
299
299
|
|
|
300
300
|
<!-- TODO: Update after #18466 (or equivalent) -->
|
|
301
301
|
|
|
@@ -477,7 +477,7 @@ export default defineNuxtModule({
|
|
|
477
477
|
})
|
|
478
478
|
```
|
|
479
479
|
|
|
480
|
-
And a more advanced one, exposing a folder of assets through [Nitro](/docs/guide/concepts/server-engine)'s `publicAssets` option:
|
|
480
|
+
And a more advanced one, exposing a folder of assets through [Nitro](/docs/4.x/guide/concepts/server-engine)'s `publicAssets` option:
|
|
481
481
|
|
|
482
482
|
```js
|
|
483
483
|
import { defineNuxtModule, createResolver } from '@nuxt/kit'
|
|
@@ -530,7 +530,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
530
530
|
|
|
531
531
|
#### Using Hooks
|
|
532
532
|
|
|
533
|
-
[Lifecycle hooks](/docs/guide/going-further/hooks) allow you to expand almost every aspect of Nuxt. Modules can hook to them programmatically or through the `hooks` map in their definition.
|
|
533
|
+
[Lifecycle hooks](/docs/4.x/guide/going-further/hooks) allow you to expand almost every aspect of Nuxt. Modules can hook to them programmatically or through the `hooks` map in their definition.
|
|
534
534
|
|
|
535
535
|
```js
|
|
536
536
|
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
|
|
@@ -700,7 +700,7 @@ We're still discussing and exploring how to ease unit and integration testing on
|
|
|
700
700
|
|
|
701
701
|
#### End to End
|
|
702
702
|
|
|
703
|
-
[Nuxt Test Utils](/docs/getting-started/testing) is the go-to library to help you test your module in an end-to-end way. Here's the workflow to adopt with it:
|
|
703
|
+
[Nuxt Test Utils](/docs/4.x/getting-started/testing) is the go-to library to help you test your module in an end-to-end way. Here's the workflow to adopt with it:
|
|
704
704
|
|
|
705
705
|
1. Create a Nuxt application to be used as a "fixture" inside `test/fixtures/*`
|
|
706
706
|
2. Setup Nuxt with this fixture inside your test file
|
|
@@ -754,7 +754,7 @@ An example of such a workflow is available on [the module starter](https://githu
|
|
|
754
754
|
|
|
755
755
|
#### Manual QA With Playground and Externally
|
|
756
756
|
|
|
757
|
-
Having a playground Nuxt application to test your module when developing it is really useful. [The module starter integrates one for that purpose](#how-to-develop).
|
|
757
|
+
Having a playground Nuxt application to test your module when developing it is really useful. [The module starter integrates one for that purpose](/docs/guide/going-further/modules#how-to-develop).
|
|
758
758
|
|
|
759
759
|
You can test your module with other Nuxt applications (applications that are not part of your module repository) locally. To do so, you can use [`npm pack`](https://docs.npmjs.com/cli/commands/npm-pack) command, or your package manager equivalent, to create a tarball from your module. Then in your test project, you can add your module to `package.json` packages as: `"my-module": "file:/path/to/tarball.tgz"`.
|
|
760
760
|
|
|
@@ -810,7 +810,7 @@ export default defineNuxtModule({
|
|
|
810
810
|
})
|
|
811
811
|
```
|
|
812
812
|
|
|
813
|
-
This pattern prevents unnecessary work on every build and provides a better developer experience. See the [lifecycle hooks documentation](/docs/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) for more details.
|
|
813
|
+
This pattern prevents unnecessary work on every build and provides a better developer experience. See the [lifecycle hooks documentation](/docs/4.x/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) for more details.
|
|
814
814
|
|
|
815
815
|
#### Be TypeScript Friendly
|
|
816
816
|
|
|
@@ -820,7 +820,7 @@ Exposing types and using TypeScript to develop modules benefits users even when
|
|
|
820
820
|
|
|
821
821
|
#### Avoid CommonJS Syntax
|
|
822
822
|
|
|
823
|
-
Nuxt relies on native ESM. Please read [Native ES Modules](/docs/guide/concepts/esm) for more information.
|
|
823
|
+
Nuxt relies on native ESM. Please read [Native ES Modules](/docs/4.x/guide/concepts/esm) for more information.
|
|
824
824
|
|
|
825
825
|
#### Document Module Usage
|
|
826
826
|
|
|
@@ -3,7 +3,7 @@ title: "Nuxt Kit"
|
|
|
3
3
|
description: "@nuxt/kit provides features for module authors."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/api/advanced/hooks), the [Nuxt Interface](/docs/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/guide/going-further/modules) super easy.
|
|
6
|
+
Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/docs/4.x/api/advanced/hooks), the [Nuxt Interface](/docs/4.x/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/docs/4.x/guide/going-further/modules) super easy.
|
|
7
7
|
|
|
8
8
|
::read-more{to="/docs/api/kit"}
|
|
9
9
|
Discover all Nuxt Kit utilities.
|
|
@@ -39,7 +39,7 @@ import { useNuxt } from '@nuxt/kit'
|
|
|
39
39
|
Nuxt Kit utilities are only available for modules and not meant to be imported in runtime (components, Vue composables, pages, plugins, or server routes).
|
|
40
40
|
::
|
|
41
41
|
|
|
42
|
-
Nuxt Kit is an [esm-only package](/docs/guide/concepts/esm) meaning that you **cannot** `require('@nuxt/kit')`. As a workaround, use dynamic import in the CommonJS context:
|
|
42
|
+
Nuxt Kit is an [esm-only package](/docs/4.x/guide/concepts/esm) meaning that you **cannot** `require('@nuxt/kit')`. As a workaround, use dynamic import in the CommonJS context:
|
|
43
43
|
|
|
44
44
|
```js [test.cjs]
|
|
45
45
|
// This does NOT work!
|
|
@@ -23,13 +23,13 @@ Jump over the `NuxtApp` interface documentation.
|
|
|
23
23
|
|
|
24
24
|
Many composables and utilities, both built-in and user-made, may require access to the Nuxt instance. This doesn't exist everywhere on your application, because a fresh instance is created on every request.
|
|
25
25
|
|
|
26
|
-
Currently, the Nuxt context is only accessible in [plugins](/docs/guide/directory-structure/plugins), [Nuxt hooks](/docs/guide/going-further/hooks), [Nuxt middleware](/docs/guide/directory-structure/app/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
|
|
26
|
+
Currently, the Nuxt context is only accessible in [plugins](/docs/4.x/guide/directory-structure/plugins), [Nuxt hooks](/docs/4.x/guide/going-further/hooks), [Nuxt middleware](/docs/4.x/guide/directory-structure/app/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
|
|
27
27
|
|
|
28
|
-
If a composable is called without access to the context, you may get an error stating that 'A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.' In that case, you can also explicitly call functions within this context by using [`nuxtApp.runWithContext`](/docs/api/composables/use-nuxt-app#runwithcontext).
|
|
28
|
+
If a composable is called without access to the context, you may get an error stating that 'A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.' In that case, you can also explicitly call functions within this context by using [`nuxtApp.runWithContext`](/docs/4.x/api/composables/use-nuxt-app#runwithcontext).
|
|
29
29
|
|
|
30
30
|
## Accessing NuxtApp
|
|
31
31
|
|
|
32
|
-
Within composables, plugins and components you can access `nuxtApp` with [`useNuxtApp()`](/docs/api/composables/use-nuxt-app):
|
|
32
|
+
Within composables, plugins and components you can access `nuxtApp` with [`useNuxtApp()`](/docs/4.x/api/composables/use-nuxt-app):
|
|
33
33
|
|
|
34
34
|
```ts [app/composables/useMyComposable.ts]
|
|
35
35
|
export function useMyComposable () {
|
|
@@ -38,7 +38,7 @@ export function useMyComposable () {
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
If your composable does not always need `nuxtApp` or you simply want to check if it is present or not, since [`useNuxtApp`](/docs/api/composables/use-nuxt-app) throws an exception, you can use [`tryUseNuxtApp`](/docs/api/composables/use-nuxt-app#tryusenuxtapp) instead.
|
|
41
|
+
If your composable does not always need `nuxtApp` or you simply want to check if it is present or not, since [`useNuxtApp`](/docs/4.x/api/composables/use-nuxt-app) throws an exception, you can use [`tryUseNuxtApp`](/docs/4.x/api/composables/use-nuxt-app#tryusenuxtapp) instead.
|
|
42
42
|
|
|
43
43
|
Plugins also receive `nuxtApp` as the first argument for convenience.
|
|
44
44
|
|
|
@@ -7,7 +7,7 @@ Nuxt layers are a powerful feature that you can use to share and reuse partial N
|
|
|
7
7
|
|
|
8
8
|
:read-more{to="/docs/getting-started/layers"}
|
|
9
9
|
|
|
10
|
-
A minimal Nuxt layer directory should contain a [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file to indicate it is a layer.
|
|
10
|
+
A minimal Nuxt layer directory should contain a [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) file to indicate it is a layer.
|
|
11
11
|
|
|
12
12
|
```ts [base/nuxt.config.ts]
|
|
13
13
|
export default defineNuxtConfig({})
|
|
@@ -15,16 +15,16 @@ export default defineNuxtConfig({})
|
|
|
15
15
|
|
|
16
16
|
Additionally, certain other files in the layer directory will be auto-scanned and used by Nuxt for the project extending this layer.
|
|
17
17
|
|
|
18
|
-
- [`app/components/*`](/docs/guide/directory-structure/app/components) - Extend the default components
|
|
19
|
-
- [`app/composables/*`](/docs/guide/directory-structure/app/composables) - Extend the default composables
|
|
20
|
-
- [`app/layouts/*`](/docs/guide/directory-structure/app/layouts) - Extend the default layouts
|
|
21
|
-
- [`app/middleware/*`](/docs/guide/directory-structure/app/middleware) - Extend the default middleware
|
|
22
|
-
- [`app/pages/*`](/docs/guide/directory-structure/app/pages) - Extend the default pages
|
|
23
|
-
- [`app/plugins/*`](/docs/guide/directory-structure/plugins) - Extend the default plugins
|
|
24
|
-
- [`app/utils/*`](/docs/guide/directory-structure/app/utils) - Extend the default utils
|
|
25
|
-
- [`app/app.config.ts`](/docs/guide/directory-structure/app-config) - Extend the default app config
|
|
26
|
-
- [`server/*`](/docs/guide/directory-structure/server) - Extend the default server endpoints & middleware
|
|
27
|
-
- [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config)- Extend the default nuxt config
|
|
18
|
+
- [`app/components/*`](/docs/4.x/guide/directory-structure/app/components) - Extend the default components
|
|
19
|
+
- [`app/composables/*`](/docs/4.x/guide/directory-structure/app/composables) - Extend the default composables
|
|
20
|
+
- [`app/layouts/*`](/docs/4.x/guide/directory-structure/app/layouts) - Extend the default layouts
|
|
21
|
+
- [`app/middleware/*`](/docs/4.x/guide/directory-structure/app/middleware) - Extend the default middleware
|
|
22
|
+
- [`app/pages/*`](/docs/4.x/guide/directory-structure/app/pages) - Extend the default pages
|
|
23
|
+
- [`app/plugins/*`](/docs/4.x/guide/directory-structure/plugins) - Extend the default plugins
|
|
24
|
+
- [`app/utils/*`](/docs/4.x/guide/directory-structure/app/utils) - Extend the default utils
|
|
25
|
+
- [`app/app.config.ts`](/docs/4.x/guide/directory-structure/app-config) - Extend the default app config
|
|
26
|
+
- [`server/*`](/docs/4.x/guide/directory-structure/server) - Extend the default server endpoints & middleware
|
|
27
|
+
- [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config)- Extend the default nuxt config
|
|
28
28
|
|
|
29
29
|
## Basic Example
|
|
30
30
|
|
|
@@ -5,11 +5,11 @@ description: "In Nuxt, your routing is defined by the structure of your files in
|
|
|
5
5
|
|
|
6
6
|
## Adding custom routes
|
|
7
7
|
|
|
8
|
-
In Nuxt, your routing is defined by the structure of your files inside the [app/pages directory](/docs/guide/directory-structure/app/pages). However, since it uses [vue-router](https://router.vuejs.org) under the hood, Nuxt offers you several ways to add custom routes in your project.
|
|
8
|
+
In Nuxt, your routing is defined by the structure of your files inside the [app/pages directory](/docs/4.x/guide/directory-structure/app/pages). However, since it uses [vue-router](https://router.vuejs.org) under the hood, Nuxt offers you several ways to add custom routes in your project.
|
|
9
9
|
|
|
10
10
|
### Router Config
|
|
11
11
|
|
|
12
|
-
Using [router options](/docs/guide/recipes/custom-routing#router-options), you can optionally override or extend your routes using a function that accepts the scanned routes and returns customized routes.
|
|
12
|
+
Using [router options](/docs/4.x/guide/recipes/custom-routing#router-options), you can optionally override or extend your routes using a function that accepts the scanned routes and returns customized routes.
|
|
13
13
|
|
|
14
14
|
If it returns `null` or `undefined`, Nuxt will fall back to the default routes (useful to modify input array).
|
|
15
15
|
|
|
@@ -29,7 +29,7 @@ export default {
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
::note
|
|
32
|
-
Nuxt will not augment any new routes you return from the `routes` function with metadata defined in `definePageMeta` of the component you provide. If you want that to happen, you should use the `pages:extend` hook which is [called at build-time](/docs/api/advanced/hooks#nuxt-hooks-build-time).
|
|
32
|
+
Nuxt will not augment any new routes you return from the `routes` function with metadata defined in `definePageMeta` of the component you provide. If you want that to happen, you should use the `pages:extend` hook which is [called at build-time](/docs/4.x/api/advanced/hooks#nuxt-hooks-build-time).
|
|
33
33
|
::
|
|
34
34
|
|
|
35
35
|
### Pages Hook
|
|
@@ -75,17 +75,17 @@ export default defineNuxtConfig({
|
|
|
75
75
|
|
|
76
76
|
If you plan to add a whole set of pages related with a specific functionality, you might want to use a [Nuxt module](/modules).
|
|
77
77
|
|
|
78
|
-
The [Nuxt kit](/docs/guide/going-further/kit) provides a few ways [to add routes](/docs/api/kit/pages):
|
|
79
|
-
- [`extendPages`](/docs/api/kit/pages#extendpages) (callback: pages => void)
|
|
80
|
-
- [`extendRouteRules`](/docs/api/kit/pages#extendrouterules) (route: string, rule: NitroRouteConfig, options: ExtendRouteRulesOptions)
|
|
78
|
+
The [Nuxt kit](/docs/4.x/guide/going-further/kit) provides a few ways [to add routes](/docs/4.x/api/kit/pages):
|
|
79
|
+
- [`extendPages`](/docs/4.x/api/kit/pages#extendpages) (callback: pages => void)
|
|
80
|
+
- [`extendRouteRules`](/docs/4.x/api/kit/pages#extendrouterules) (route: string, rule: NitroRouteConfig, options: ExtendRouteRulesOptions)
|
|
81
81
|
|
|
82
82
|
## Router Options
|
|
83
83
|
|
|
84
|
-
On top of customizing options for [`vue-router`](https://router.vuejs.org/api/interfaces/routeroptions.html), Nuxt offers [additional options](/docs/api/nuxt-config#router) to customize the router.
|
|
84
|
+
On top of customizing options for [`vue-router`](https://router.vuejs.org/api/interfaces/routeroptions.html), Nuxt offers [additional options](/docs/4.x/api/nuxt-config#router) to customize the router.
|
|
85
85
|
|
|
86
86
|
### Using `router.options`
|
|
87
87
|
|
|
88
|
-
This is the recommended way to specify [router options](/docs/api/nuxt-config#router).
|
|
88
|
+
This is the recommended way to specify [router options](/docs/4.x/api/nuxt-config#router).
|
|
89
89
|
|
|
90
90
|
```ts [router.options.ts]
|
|
91
91
|
import type { RouterConfig } from '@nuxt/schema'
|
|
@@ -119,7 +119,7 @@ export default defineNuxtConfig({
|
|
|
119
119
|
|
|
120
120
|
### Using `nuxt.config`
|
|
121
121
|
|
|
122
|
-
**Note:** Only JSON serializable [options](/docs/api/nuxt-config#router) are configurable:
|
|
122
|
+
**Note:** Only JSON serializable [options](/docs/4.x/api/nuxt-config#router) are configurable:
|
|
123
123
|
|
|
124
124
|
- `linkActiveClass`
|
|
125
125
|
- `linkExactActiveClass`
|
|
@@ -139,7 +139,7 @@ export default defineNuxtConfig({
|
|
|
139
139
|
|
|
140
140
|
### Hash Mode (SPA)
|
|
141
141
|
|
|
142
|
-
You can enable hash history in SPA mode using the `hashMode` [config](/docs/api/nuxt-config#router). In this mode, router uses a hash character (#) before the actual URL that is internally passed. When enabled, the **URL is never sent to the server** and **SSR is not supported**.
|
|
142
|
+
You can enable hash history in SPA mode using the `hashMode` [config](/docs/4.x/api/nuxt-config#router). In this mode, router uses a hash character (#) before the actual URL that is internally passed. When enabled, the **URL is never sent to the server** and **SSR is not supported**.
|
|
143
143
|
|
|
144
144
|
```ts [nuxt.config.ts]
|
|
145
145
|
export default defineNuxtConfig({
|
|
@@ -154,7 +154,7 @@ export default defineNuxtConfig({
|
|
|
154
154
|
|
|
155
155
|
### Scroll Behavior for hash links
|
|
156
156
|
|
|
157
|
-
You can optionally customize the scroll behavior for hash links. When you set the [config](/docs/api/nuxt-config#router) to be `smooth` and you load a page with a hash link (e.g. `https://example.com/blog/my-article#comments`), you will see that the browser smoothly scrolls to this anchor.
|
|
157
|
+
You can optionally customize the scroll behavior for hash links. When you set the [config](/docs/4.x/api/nuxt-config#router) to be `smooth` and you load a page with a hash link (e.g. `https://example.com/blog/my-article#comments`), you will see that the browser smoothly scrolls to this anchor.
|
|
158
158
|
|
|
159
159
|
```ts [nuxt.config.ts]
|
|
160
160
|
export default defineNuxtConfig({
|
|
@@ -28,7 +28,7 @@ First, we need to install the Vite plugin, for our example, we'll use `@rollup/p
|
|
|
28
28
|
|
|
29
29
|
::
|
|
30
30
|
|
|
31
|
-
Next, we need to import and add it to our [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file:
|
|
31
|
+
Next, we need to import and add it to our [`nuxt.config.ts`](/docs/4.x/guide/directory-structure/nuxt-config) file:
|
|
32
32
|
|
|
33
33
|
```ts [nuxt.config.ts]
|
|
34
34
|
import yaml from '@rollup/plugin-yaml'
|
|
@@ -6,13 +6,13 @@ description: How to create a custom fetcher for calling your external API in Nux
|
|
|
6
6
|
|
|
7
7
|
When working with Nuxt, you might be making the frontend and fetching an external API, and you might want to set some default options for fetching from your API.
|
|
8
8
|
|
|
9
|
-
The [`$fetch`](/docs/api/utils/dollarfetch) utility function (used by the [`useFetch`](/docs/api/composables/use-fetch) composable) is intentionally not globally configurable. This is important so that fetching behavior throughout your application remains consistent, and other integrations (like modules) can rely on the behavior of core utilities like `$fetch`.
|
|
9
|
+
The [`$fetch`](/docs/4.x/api/utils/dollarfetch) utility function (used by the [`useFetch`](/docs/4.x/api/composables/use-fetch) composable) is intentionally not globally configurable. This is important so that fetching behavior throughout your application remains consistent, and other integrations (like modules) can rely on the behavior of core utilities like `$fetch`.
|
|
10
10
|
|
|
11
11
|
However, Nuxt provides a way to create a custom fetcher for your API (or multiple fetchers if you have multiple APIs to call).
|
|
12
12
|
|
|
13
13
|
## Custom `$fetch`
|
|
14
14
|
|
|
15
|
-
Let's create a custom `$fetch` instance with a [Nuxt plugin](/docs/guide/directory-structure/plugins).
|
|
15
|
+
Let's create a custom `$fetch` instance with a [Nuxt plugin](/docs/4.x/guide/directory-structure/plugins).
|
|
16
16
|
|
|
17
17
|
::note
|
|
18
18
|
`$fetch` is a configured instance of [ofetch](https://github.com/unjs/ofetch) which supports adding the base URL of your Nuxt server as well as direct function calls during SSR (avoiding HTTP roundtrips).
|
|
@@ -61,7 +61,7 @@ const { data: modules } = await useAsyncData('modules', () => $api('/modules'))
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
::callout
|
|
64
|
-
Wrapping with [`useAsyncData`](/docs/api/composables/use-async-data) **avoid double data fetching when doing server-side rendering** (server & client on hydration).
|
|
64
|
+
Wrapping with [`useAsyncData`](/docs/4.x/api/composables/use-async-data) **avoid double data fetching when doing server-side rendering** (server & client on hydration).
|
|
65
65
|
::
|
|
66
66
|
|
|
67
67
|
## Custom `useFetch`/`useAsyncData`
|
|
@@ -164,7 +164,7 @@ export default defineNuxtRouteMiddleware(() => {
|
|
|
164
164
|
|
|
165
165
|
Now that we have our app middleware to protect our routes, we can use it on our home page that display our authenticated user information. If the user is not authenticated, they will be redirected to the login page.
|
|
166
166
|
|
|
167
|
-
We'll use [`definePageMeta`](/docs/api/utils/define-page-meta) to apply the middleware to the route that we want to protect.
|
|
167
|
+
We'll use [`definePageMeta`](/docs/4.x/api/utils/define-page-meta) to apply the middleware to the route that we want to protect.
|
|
168
168
|
|
|
169
169
|
```vue [app/pages/index.vue]
|
|
170
170
|
<script setup lang="ts">
|
|
@@ -47,7 +47,7 @@ const userTheme = localStorage.getItem('theme') || 'light'
|
|
|
47
47
|
</script>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
**Solution**: You can use [`useCookie`](/docs/api/composables/use-cookie):
|
|
50
|
+
**Solution**: You can use [`useCookie`](/docs/4.x/api/composables/use-cookie):
|
|
51
51
|
|
|
52
52
|
```html
|
|
53
53
|
<template>
|
|
@@ -144,7 +144,7 @@ const greeting = hour < 12 ? 'Good morning' : 'Good afternoon'
|
|
|
144
144
|
</script>
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
**Solution**: Use [`NuxtTime`](/docs/api/components/nuxt-time) component or handle it client-side:
|
|
147
|
+
**Solution**: Use [`NuxtTime`](/docs/4.x/api/components/nuxt-time) component or handle it client-side:
|
|
148
148
|
|
|
149
149
|
```html
|
|
150
150
|
<template>
|
|
@@ -178,8 +178,8 @@ onMounted(() => {
|
|
|
178
178
|
|
|
179
179
|
## In summary
|
|
180
180
|
|
|
181
|
-
1. **Use SSR-friendly composables**: [`useFetch`](/docs/api/composables/use-fetch), [`useAsyncData`](/docs/api/composables/use-async-data), [`useState`](/docs/api/composables/use-state)
|
|
182
|
-
2. **Wrap client-only code**: Use [`ClientOnly`](/docs/api/components/client-only) component for browser-specific content
|
|
181
|
+
1. **Use SSR-friendly composables**: [`useFetch`](/docs/4.x/api/composables/use-fetch), [`useAsyncData`](/docs/4.x/api/composables/use-async-data), [`useState`](/docs/4.x/api/composables/use-state)
|
|
182
|
+
2. **Wrap client-only code**: Use [`ClientOnly`](/docs/4.x/api/components/client-only) component for browser-specific content
|
|
183
183
|
3. **Consistent data sources**: Ensure server and client uses the same data
|
|
184
184
|
4. **Avoid side effects in setup**: Move browser-dependent code to `onMounted`
|
|
185
185
|
|
|
@@ -12,7 +12,7 @@ Nuxt offers several built-in features that help you optimize performance of your
|
|
|
12
12
|
|
|
13
13
|
### Links
|
|
14
14
|
|
|
15
|
-
[`<NuxtLink>`](/docs/api/components/nuxt-link) is a drop-in replacement for both Vue Router's `<RouterLink>` component and HTML's `<a>` tag. It intelligently determines whether the link is internal or external and renders it accordingly with available optimizations (prefetching, default attributes, etc.)
|
|
15
|
+
[`<NuxtLink>`](/docs/4.x/api/components/nuxt-link) is a drop-in replacement for both Vue Router's `<RouterLink>` component and HTML's `<a>` tag. It intelligently determines whether the link is internal or external and renders it accordingly with available optimizations (prefetching, default attributes, etc.)
|
|
16
16
|
|
|
17
17
|
```html
|
|
18
18
|
<template>
|
|
@@ -110,7 +110,7 @@ To optimize your app, you may want to delay the hydration of some components unt
|
|
|
110
110
|
|
|
111
111
|
### Fetching data
|
|
112
112
|
|
|
113
|
-
To avoid fetching same data twice (once on the server and once on client) Nuxt provides [`useFetch`](/docs/api/composables/use-fetch) and [`useAsyncData`](/docs/api/composables/use-async-data). They ensure that if an API call is made on the server, the data is forwarded to the client in the payload instead of being fetched again.
|
|
113
|
+
To avoid fetching same data twice (once on the server and once on client) Nuxt provides [`useFetch`](/docs/4.x/api/composables/use-fetch) and [`useAsyncData`](/docs/4.x/api/composables/use-async-data). They ensure that if an API call is made on the server, the data is forwarded to the client in the payload instead of being fetched again.
|
|
114
114
|
|
|
115
115
|
:read-more{title="Data fetching" to="/docs/getting-started/data-fetching"}
|
|
116
116
|
|
|
@@ -126,7 +126,7 @@ In Nuxt we can use [Nuxt Image](https://image.nuxt.com/) module that is a plug-a
|
|
|
126
126
|
|
|
127
127
|
:video-accordion{title="Watch the video by LearnVue about Nuxt Image" videoId="_UBff2eqGY0"}
|
|
128
128
|
|
|
129
|
-
[`<NuxtImg>`](/docs/api/components/nuxt-img) is a drop-in replacement for the native `<img>` tag that comes with following enhancements:
|
|
129
|
+
[`<NuxtImg>`](/docs/4.x/api/components/nuxt-img) is a drop-in replacement for the native `<img>` tag that comes with following enhancements:
|
|
130
130
|
|
|
131
131
|
* Uses built-in provider to optimize local and remote images
|
|
132
132
|
* Converts `src` to provider optimized URLs with modern formats such as WebP or Avif
|
|
@@ -216,7 +216,7 @@ To improve performance, we need to first know how to measure it, starting with m
|
|
|
216
216
|
|
|
217
217
|
### Nuxi Analyze
|
|
218
218
|
|
|
219
|
-
[This](/docs/api/commands/analyze) command of `nuxi` allows to analyze the production bundle or your Nuxt application. It leverages `vite-bundle-visualizer` (similar to `webpack-bundle-analyzer`) to generate a visual representation of your application's bundle, making it easier to identify which components take up the most space.
|
|
219
|
+
[This](/docs/4.x/api/commands/analyze) command of `nuxi` allows to analyze the production bundle or your Nuxt application. It leverages `vite-bundle-visualizer` (similar to `webpack-bundle-analyzer`) to generate a visual representation of your application's bundle, making it easier to identify which components take up the most space.
|
|
220
220
|
|
|
221
221
|
When you see a large block in the visualization, it often signals an opportunity for optimization—whether by splitting it into smaller parts, implementing lazy loading, or replacing it with a more efficient alternative, especially for third-party libraries.
|
|
222
222
|
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
`<NuxtPicture>` is a drop-in replacement for the native `<picture>` tag.
|
|
12
12
|
|
|
13
|
-
Usage of `<NuxtPicture>` is almost identical to [`<NuxtImg>`](/docs/api/components/nuxt-img) but it also allows serving modern formats like `webp` when possible.
|
|
13
|
+
Usage of `<NuxtPicture>` is almost identical to [`<NuxtImg>`](/docs/4.x/api/components/nuxt-img) but it also allows serving modern formats like `webp` when possible.
|
|
14
14
|
|
|
15
15
|
Learn more about the [`<picture>` tag on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture).
|
|
16
16
|
|
|
@@ -16,7 +16,7 @@ This component is available in Nuxt v3.12+.
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`app/layouts/`](/docs/guide/directory-structure/app/layouts) to enhance accessibility by informing assistive technologies about page title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
19
|
+
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/4.x/guide/directory-structure/app) or [`app/layouts/`](/docs/4.x/guide/directory-structure/app/layouts) to enhance accessibility by informing assistive technologies about page title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
20
20
|
|
|
21
21
|
```vue [app/app.vue]
|
|
22
22
|
<template>
|
|
@@ -52,5 +52,5 @@ To achieve full customization, you can implement your own one based on [its sour
|
|
|
52
52
|
::
|
|
53
53
|
|
|
54
54
|
::callout
|
|
55
|
-
You can hook into the underlying announcer instance using [the `useRouteAnnouncer` composable](/docs/api/composables/use-route-announcer), which allows you to set a custom announcement message.
|
|
55
|
+
You can hook into the underlying announcer instance using [the `useRouteAnnouncer` composable](/docs/4.x/api/composables/use-route-announcer), which allows you to set a custom announcement message.
|
|
56
56
|
::
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`app/pages/`](/docs/guide/directory-structure/app/pages) directory.
|
|
11
|
+
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory.
|
|
12
12
|
|
|
13
13
|
::note
|
|
14
14
|
`<NuxtPage>` is a wrapper around [`<RouterView>`](https://router.vuejs.org/api/interfaces/RouterViewProps.html#interface-routerviewprops) from Vue Router. It should be used instead of `<RouterView>` because the former takes additional care of internal states. Otherwise, `useRoute()` may return incorrect paths.
|
|
@@ -79,7 +79,7 @@ You can also use a dynamic key based on the current route:
|
|
|
79
79
|
Don't use `$route` object here as it can cause problems with how `<NuxtPage>` renders pages with `<Suspense>`.
|
|
80
80
|
::
|
|
81
81
|
|
|
82
|
-
Alternatively, `pageKey` can be passed as a `key` value via [`definePageMeta`](/docs/api/utils/define-page-meta) from the `<script>` section of your Vue component in the `/pages` directory.
|
|
82
|
+
Alternatively, `pageKey` can be passed as a `key` value via [`definePageMeta`](/docs/4.x/api/utils/define-page-meta) from the `<script>` section of your Vue component in the `/pages` directory.
|
|
83
83
|
|
|
84
84
|
```vue [app/pages/my-page.vue]
|
|
85
85
|
<script setup lang="ts">
|
|
@@ -22,7 +22,7 @@ You can use `<NuxtLayout />` component to activate the `default` layout on `app.
|
|
|
22
22
|
|
|
23
23
|
## Props
|
|
24
24
|
|
|
25
|
-
- `name`: Specify a layout name to be rendered, can be a string, reactive reference or a computed property. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/guide/directory-structure/app/layouts) directory.
|
|
25
|
+
- `name`: Specify a layout name to be rendered, can be a string, reactive reference or a computed property. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/4.x/guide/directory-structure/app/layouts) directory.
|
|
26
26
|
- **type**: `string`
|
|
27
27
|
- **default**: `default`
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ Please note the layout name is normalized to kebab-case, so if your layout file
|
|
|
55
55
|
Read more about dynamic layouts.
|
|
56
56
|
::
|
|
57
57
|
|
|
58
|
-
- `fallback`: If an invalid layout is passed to the `name` prop, no layout will be rendered. Specify a `fallback` layout to be rendered in this scenario. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/guide/directory-structure/app/layouts) directory.
|
|
58
|
+
- `fallback`: If an invalid layout is passed to the `name` prop, no layout will be rendered. Specify a `fallback` layout to be rendered in this scenario. It **must** match the name of the corresponding layout file in the [`app/layouts/`](/docs/4.x/guide/directory-structure/app/layouts) directory.
|
|
59
59
|
- **type**: `string`
|
|
60
60
|
- **default**: `null`
|
|
61
61
|
|
|
@@ -238,7 +238,7 @@ When not using `external`, `<NuxtLink>` supports all Vue Router's [`RouterLink`
|
|
|
238
238
|
- `href`: An alias for `to`. If used with `to`, `href` will be ignored
|
|
239
239
|
- `noRel`: If set to `true`, no `rel` attribute will be added to the external link
|
|
240
240
|
- `external`: Forces the link to be rendered as an `<a>` tag instead of a Vue Router `RouterLink`.
|
|
241
|
-
- `prefetch`: When enabled will prefetch middleware, layouts and payloads (when using [payloadExtraction](/docs/api/nuxt-config#crossoriginprefetch)) of links in the viewport. Used by the experimental [crossOriginPrefetch](/docs/api/nuxt-config#crossoriginprefetch) config.
|
|
241
|
+
- `prefetch`: When enabled will prefetch middleware, layouts and payloads (when using [payloadExtraction](/docs/4.x/api/nuxt-config#crossoriginprefetch)) of links in the viewport. Used by the experimental [crossOriginPrefetch](/docs/4.x/api/nuxt-config#crossoriginprefetch) config.
|
|
242
242
|
- `prefetchOn`: Allows custom control of when to prefetch links. Possible options are `interaction` and `visibility` (default). You can also pass an object for full control, for example: `{ interaction: true, visibility: true }`. This prop is only used when `prefetch` is enabled (default) and `noPrefetch` is not set.
|
|
243
243
|
- `noPrefetch`: Disables prefetching.
|
|
244
244
|
- `prefetchedClass`: A class to apply to links that have been prefetched.
|
|
@@ -249,14 +249,14 @@ When not using `external`, `<NuxtLink>` supports all Vue Router's [`RouterLink`
|
|
|
249
249
|
- `rel`: A `rel` attribute value to apply on the link. Defaults to `"noopener noreferrer"` for external links.
|
|
250
250
|
|
|
251
251
|
::tip
|
|
252
|
-
Defaults can be overwritten, see [overwriting defaults](#overwriting-defaults) if you want to change them.
|
|
252
|
+
Defaults can be overwritten, see [overwriting defaults](/docs/api/components/nuxt-link#overwriting-defaults) if you want to change them.
|
|
253
253
|
::
|
|
254
254
|
|
|
255
255
|
## Overwriting Defaults
|
|
256
256
|
|
|
257
257
|
### In Nuxt Config
|
|
258
258
|
|
|
259
|
-
You can overwrite some `<NuxtLink>` defaults in your [`nuxt.config`](/docs/api/nuxt-config#defaults)
|
|
259
|
+
You can overwrite some `<NuxtLink>` defaults in your [`nuxt.config`](/docs/4.x/api/nuxt-config#defaults)
|
|
260
260
|
|
|
261
261
|
::important
|
|
262
262
|
These options will likely be moved elsewhere in the future, such as into `app.config` or into the `app/` directory.
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`app/layouts/`](/docs/guide/directory-structure/app/layouts).
|
|
13
|
+
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/4.x/guide/directory-structure/app) or [`app/layouts/`](/docs/4.x/guide/directory-structure/app/layouts).
|
|
14
14
|
|
|
15
15
|
```vue [app/app.vue]
|
|
16
16
|
<template>
|
|
@@ -42,7 +42,7 @@ To achieve full customization, you can implement your own one based on [its sour
|
|
|
42
42
|
::
|
|
43
43
|
|
|
44
44
|
::note
|
|
45
|
-
You can hook into the underlying indicator instance using [the `useLoadingIndicator` composable](/docs/api/composables/use-loading-indicator), which will allow you to trigger start/finish events yourself.
|
|
45
|
+
You can hook into the underlying indicator instance using [the `useLoadingIndicator` composable](/docs/4.x/api/composables/use-loading-indicator), which will allow you to trigger start/finish events yourself.
|
|
46
46
|
::
|
|
47
47
|
|
|
48
48
|
::tip
|