@nuxt/docs-nightly 4.1.3-29313386.edc02e27 → 4.1.3-29316215.910d159d
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 +4 -4
- package/1.getting-started/02.installation.md +1 -1
- package/1.getting-started/03.configuration.md +25 -25
- package/1.getting-started/04.views.md +3 -3
- package/1.getting-started/05.assets.md +9 -3
- package/1.getting-started/06.styling.md +53 -43
- package/1.getting-started/07.routing.md +9 -9
- package/1.getting-started/08.seo-meta.md +50 -37
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +61 -53
- package/1.getting-started/11.state-management.md +19 -12
- package/1.getting-started/12.error-handling.md +17 -15
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +19 -13
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +8 -8
- package/1.getting-started/17.testing.md +42 -42
- package/1.getting-started/18.upgrade.md +50 -68
- package/2.guide/0.index.md +5 -5
- package/2.guide/1.directory-structure/0.output.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.assets.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.components.md +40 -23
- package/2.guide/1.directory-structure/1.app/1.composables.md +9 -9
- package/2.guide/1.directory-structure/1.app/1.layouts.md +12 -8
- package/2.guide/1.directory-structure/1.app/1.middleware.md +23 -17
- package/2.guide/1.directory-structure/1.app/1.pages.md +25 -23
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.app-config.md +7 -7
- package/2.guide/1.directory-structure/1.app/3.app.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +5 -5
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +30 -30
- package/2.guide/1.directory-structure/1.shared.md +3 -3
- package/2.guide/1.directory-structure/2.env.md +3 -3
- package/2.guide/1.directory-structure/2.nuxtrc.md +1 -1
- package/2.guide/1.directory-structure/3.nuxt-config.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +15 -15
- package/2.guide/2.concepts/10.nuxt-lifecycle.md +7 -7
- package/2.guide/2.concepts/2.vuejs-development.md +9 -9
- package/2.guide/2.concepts/3.rendering.md +17 -15
- package/2.guide/2.concepts/4.server-engine.md +1 -1
- package/2.guide/2.concepts/5.modules.md +3 -3
- package/2.guide/2.concepts/7.esm.md +16 -14
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +238 -77
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +8 -8
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +83 -81
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +4 -4
- package/2.guide/3.going-further/7.layers.md +51 -42
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +10 -10
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/performance.md +13 -13
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +13 -8
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +14 -14
- package/3.api/2.composables/use-cookie.md +27 -19
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +17 -17
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +3 -3
- package/3.api/2.composables/use-hydration.md +5 -5
- 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 +10 -10
- package/3.api/2.composables/use-nuxt-app.md +10 -10
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +6 -4
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +3 -3
- package/3.api/2.composables/use-server-seo-meta.md +3 -3
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +6 -4
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +5 -5
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +16 -16
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +10 -5
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +3 -3
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/generate.md +1 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/4.commands/typecheck.md +1 -1
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +299 -864
- package/3.api/index.md +7 -7
- package/5.community/4.contribution.md +5 -5
- package/5.community/5.framework-contribution.md +1 -1
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +4 -4
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +12 -9
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +18 -16
- package/7.migration/20.module-authors.md +1 -1
- package/7.migration/4.meta.md +18 -15
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +20 -16
- package/7.migration/7.component-options.md +7 -7
- package/7.migration/8.runtime-config.md +4 -4
- package/package.json +1 -1
|
@@ -52,7 +52,7 @@ const hello = capitalize('hello')
|
|
|
52
52
|
```ts [server/api/hello.get.ts]
|
|
53
53
|
export default defineEventHandler((event) => {
|
|
54
54
|
return {
|
|
55
|
-
hello: capitalize('hello')
|
|
55
|
+
hello: capitalize('hello'),
|
|
56
56
|
}
|
|
57
57
|
})
|
|
58
58
|
```
|
|
@@ -65,7 +65,7 @@ Only files in the `shared/utils/` and `shared/types/` directories will be auto-i
|
|
|
65
65
|
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`app/composables/`](/docs/4.x/guide/directory-structure/app/composables) and [`app/utils/`](/docs/4.x/guide/directory-structure/app/utils) directories.
|
|
66
66
|
::
|
|
67
67
|
|
|
68
|
-
:read-more{to="/docs/guide/directory-structure/app/composables#how-files-are-scanned"}
|
|
68
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/composables#how-files-are-scanned"}
|
|
69
69
|
|
|
70
70
|
```bash [Directory Structure]
|
|
71
71
|
-| shared/
|
|
@@ -95,4 +95,4 @@ import upper from '#shared/utils/formatters/upper'
|
|
|
95
95
|
|
|
96
96
|
This alias ensures consistent imports across your application, regardless of the importing file's location.
|
|
97
97
|
|
|
98
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
98
|
+
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
@@ -56,7 +56,7 @@ Since `.env` files are not used in production, you must explicitly set environme
|
|
|
56
56
|
* Many cloud service providers, such as Vercel, Netlify, and AWS, provide interfaces for setting environment variables via their dashboards, CLI tools or configuration files.
|
|
57
57
|
|
|
58
58
|
::important
|
|
59
|
-
`runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
|
|
59
|
+
`runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/4.x/guide/going-further/runtime-config#environment-variables).
|
|
60
60
|
::
|
|
61
61
|
|
|
62
62
|
## Production Preview
|
|
@@ -71,9 +71,9 @@ DATABASE_HOST=mydatabaseconnectionstring node .output/server/index.mjs
|
|
|
71
71
|
|
|
72
72
|
Note that for a purely static site, it is not possible to set runtime configuration config after your project is prerendered.
|
|
73
73
|
|
|
74
|
-
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
74
|
+
:read-more{to="/docs/4.x/guide/going-further/runtime-config"}
|
|
75
75
|
|
|
76
76
|
::note
|
|
77
77
|
If you want to use environment variables set at build time but do not care about updating these down the line (or only need to update them reactively _within_ your app) then `appConfig` may be a better choice. You can define `appConfig` both within your `nuxt.config` (using environment variables) and also within an `~/app.config.ts` file in your project.
|
|
78
|
-
:read-more{to="/docs/guide/directory-structure/app-config"}
|
|
78
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app-config"}
|
|
79
79
|
::
|
|
@@ -31,7 +31,7 @@ If present, the properties in the `nuxt.config` file will overwrite the properti
|
|
|
31
31
|
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/4.x/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
32
32
|
::
|
|
33
33
|
|
|
34
|
-
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
34
|
+
::read-more{to="/docs/4.x/api/configuration/nuxt-config"}
|
|
35
35
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
36
36
|
::
|
|
37
37
|
|
|
@@ -66,7 +66,7 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
|
|
|
66
66
|
When using a composable that requires the Nuxt context inside a non-SFC component, you need to wrap your component with `defineNuxtComponent` instead of `defineComponent`
|
|
67
67
|
::
|
|
68
68
|
|
|
69
|
-
::read-more{to="/docs/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
|
|
69
|
+
::read-more{to="/docs/4.x/guide/going-further/experimental-features#asynccontext" icon="i-lucide-star"}
|
|
70
70
|
Checkout the `asyncContext` experimental feature to use Nuxt composables in async functions.
|
|
71
71
|
::
|
|
72
72
|
|
|
@@ -105,7 +105,7 @@ Nuxt directly auto-imports files created in defined directories:
|
|
|
105
105
|
- `app/composables/` for [Vue composables](/docs/4.x/guide/directory-structure/app/composables).
|
|
106
106
|
- `app/utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
108
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
109
109
|
|
|
110
110
|
::warning
|
|
111
111
|
**Auto-imported `ref` and `computed` won't be unwrapped in a component `<template>`.** :br
|
|
@@ -120,7 +120,7 @@ Nuxt exposes every auto-import with the `#imports` alias that can be used to mak
|
|
|
120
120
|
|
|
121
121
|
```vue
|
|
122
122
|
<script setup lang="ts">
|
|
123
|
-
import {
|
|
123
|
+
import { computed, ref } from '#imports'
|
|
124
124
|
|
|
125
125
|
const count = ref(1)
|
|
126
126
|
const double = computed(() => count.value * 2)
|
|
@@ -134,12 +134,12 @@ If you want to disable auto-importing composables and utilities, you can set `im
|
|
|
134
134
|
```ts twoslash [nuxt.config.ts]
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
imports: {
|
|
137
|
-
autoImport: false
|
|
138
|
-
}
|
|
137
|
+
autoImport: false,
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/guide/concepts/auto-imports#explicit-imports) from `#imports`.
|
|
142
|
+
This will disable auto-imports completely but it's still possible to use [explicit imports](/docs/4.x/guide/concepts/auto-imports#explicit-imports) from `#imports`.
|
|
143
143
|
|
|
144
144
|
### Partially Disabling Auto-imports
|
|
145
145
|
|
|
@@ -148,8 +148,8 @@ If you want framework-specific functions like `ref` to remain auto-imported but
|
|
|
148
148
|
```ts
|
|
149
149
|
export default defineNuxtConfig({
|
|
150
150
|
imports: {
|
|
151
|
-
scan: false
|
|
152
|
-
}
|
|
151
|
+
scan: false,
|
|
152
|
+
},
|
|
153
153
|
})
|
|
154
154
|
```
|
|
155
155
|
|
|
@@ -167,15 +167,15 @@ With this configuration:
|
|
|
167
167
|
|
|
168
168
|
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
|
|
169
169
|
|
|
170
|
-
:read-more{to="/docs/guide/directory-structure/app/components"}
|
|
170
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/components"}
|
|
171
171
|
|
|
172
172
|
To disable auto-importing components from your own `~/components` directory, you can set `components.dirs` to an empty array (though note that this will not affect components added by modules).
|
|
173
173
|
|
|
174
174
|
```ts twoslash [nuxt.config.ts]
|
|
175
175
|
export default defineNuxtConfig({
|
|
176
176
|
components: {
|
|
177
|
-
dirs: []
|
|
178
|
-
}
|
|
177
|
+
dirs: [],
|
|
178
|
+
},
|
|
179
179
|
})
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -195,10 +195,10 @@ export default defineNuxtConfig({
|
|
|
195
195
|
presets: [
|
|
196
196
|
{
|
|
197
197
|
from: 'vue-i18n',
|
|
198
|
-
imports: ['useI18n']
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
}
|
|
198
|
+
imports: ['useI18n'],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
202
|
})
|
|
203
203
|
```
|
|
204
204
|
|
|
@@ -22,7 +22,7 @@ When Nitro starts, it initializes and executes the plugins under the `/server/pl
|
|
|
22
22
|
Nitro plugins are executed only once when the server starts. In a serverless environment, the server boots on each incoming request, and so do the Nitro plugins. However, they are not awaited.
|
|
23
23
|
::
|
|
24
24
|
|
|
25
|
-
:read-more{to="/docs/guide/directory-structure/server#server-plugins"}
|
|
25
|
+
:read-more{to="/docs/4.x/guide/directory-structure/server#server-plugins"}
|
|
26
26
|
|
|
27
27
|
### Step 2: Nitro Server Middleware
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ After initializing the Nitro server, middleware under `server/middleware/` is ex
|
|
|
32
32
|
Returning a value from middleware will terminate the request and send the returned value as the response. This behavior should generally be avoided to ensure proper request handling!
|
|
33
33
|
::
|
|
34
34
|
|
|
35
|
-
:read-more{to="/docs/guide/directory-structure/server#server-middleware"}
|
|
35
|
+
:read-more{to="/docs/4.x/guide/directory-structure/server#server-middleware"}
|
|
36
36
|
|
|
37
37
|
### Step 3: Initialize Nuxt and Execute Nuxt App Plugins
|
|
38
38
|
|
|
@@ -46,7 +46,7 @@ Plugins execute in a specific order and may have dependencies on one another. Fo
|
|
|
46
46
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
47
47
|
::
|
|
48
48
|
|
|
49
|
-
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
49
|
+
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
50
50
|
|
|
51
51
|
### Step 4: Route Validation
|
|
52
52
|
|
|
@@ -57,7 +57,7 @@ After initializing plugins and before executing middleware, Nuxt calls the `vali
|
|
|
57
57
|
|
|
58
58
|
For more information, see the [Route Validation documentation](/docs/4.x/getting-started/routing#route-validation).
|
|
59
59
|
|
|
60
|
-
:read-more{to="/docs/getting-started/routing#route-validation"}
|
|
60
|
+
:read-more{to="/docs/4.x/getting-started/routing#route-validation"}
|
|
61
61
|
|
|
62
62
|
### Step 5: Execute Nuxt App Middleware
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ For details about each type and examples, see the [Middleware documentation](/do
|
|
|
74
74
|
|
|
75
75
|
Any redirection on the server will result in a `Location:` header being sent to the browser; the browser then makes a fresh request to this new location. All application state will be reset when this happens, unless persisted in a cookie.
|
|
76
76
|
|
|
77
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware"}
|
|
77
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware"}
|
|
78
78
|
|
|
79
79
|
### Step 6: Render Page and Components
|
|
80
80
|
|
|
@@ -120,7 +120,7 @@ Custom plugins in the `app/plugins/` directory, such as those without a suffix (
|
|
|
120
120
|
After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
121
121
|
::
|
|
122
122
|
|
|
123
|
-
:read-more{to="/docs/guide/directory-structure/plugins"}
|
|
123
|
+
:read-more{to="/docs/4.x/guide/directory-structure/plugins"}
|
|
124
124
|
|
|
125
125
|
### Step 2: Route Validation
|
|
126
126
|
|
|
@@ -130,7 +130,7 @@ This step is the same as the server-side execution and includes the `validate` m
|
|
|
130
130
|
|
|
131
131
|
Nuxt middleware runs on both the server and the client. If you want certain code to run in specific environments, consider splitting it by using `import.meta.client` for the client and `import.meta.server` for the server.
|
|
132
132
|
|
|
133
|
-
:read-more{to="/docs/guide/directory-structure/app/middleware#when-middleware-runs"}
|
|
133
|
+
:read-more{to="/docs/4.x/guide/directory-structure/app/middleware#when-middleware-runs"}
|
|
134
134
|
|
|
135
135
|
### Step 4: Mount Vue Application and Hydration
|
|
136
136
|
|
|
@@ -27,15 +27,15 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
27
27
|
|
|
28
28
|
Every Vue component created in the [`app/components/`](/docs/4.x/guide/directory-structure/app/components) directory of a Nuxt project will be available in your project without having to import it. If a component is not used anywhere, your production’s code will not include it.
|
|
29
29
|
|
|
30
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
30
|
+
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
31
31
|
|
|
32
32
|
### Vue Router
|
|
33
33
|
|
|
34
34
|
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses an [`app/pages/`](/docs/4.x/guide/directory-structure/app/pages) directory and naming conventions to directly create routes mapped to your files using the official [Vue Router library](https://router.vuejs.org).
|
|
35
35
|
|
|
36
|
-
:read-more{to="/docs/getting-started/routing"}
|
|
36
|
+
:read-more{to="/docs/4.x/getting-started/routing"}
|
|
37
37
|
|
|
38
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
38
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
39
39
|
|
|
40
40
|
## Differences with Nuxt 2 / Vue 2
|
|
41
41
|
|
|
@@ -64,16 +64,16 @@ The only way to provide data and logic to components in Vue 2 was through the Op
|
|
|
64
64
|
```vue twoslash
|
|
65
65
|
<script>
|
|
66
66
|
export default {
|
|
67
|
-
data() {
|
|
67
|
+
data () {
|
|
68
68
|
return {
|
|
69
|
-
count: 0
|
|
69
|
+
count: 0,
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
methods: {
|
|
73
|
-
increment(){
|
|
73
|
+
increment () {
|
|
74
74
|
this.count++
|
|
75
|
-
}
|
|
76
|
-
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
77
|
}
|
|
78
78
|
</script>
|
|
79
79
|
```
|
|
@@ -98,6 +98,6 @@ The goal of Nuxt is to provide a great developer experience around the Compositi
|
|
|
98
98
|
|
|
99
99
|
Both Vue 3 and Nuxt 3+ are written in TypeScript. A fully typed codebase prevents mistakes and documents APIs usage. This doesn’t mean that you have to write your application in TypeScript to take advantage of it. With Nuxt 3, you can opt-in by renaming your file from `.js` to `.ts` , or add `<script setup lang="ts">` in a component.
|
|
100
100
|
|
|
101
|
-
::read-more{to="/docs/guide/concepts/typescript"}
|
|
101
|
+
::read-more{to="/docs/4.x/guide/concepts/typescript"}
|
|
102
102
|
Read the details about TypeScript in Nuxt
|
|
103
103
|
::
|
|
@@ -3,7 +3,7 @@ title: 'Rendering Modes'
|
|
|
3
3
|
description: 'Learn about the different rendering modes available in Nuxt.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Nuxt supports different rendering modes, [universal rendering](/docs/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/guide/concepts/rendering#edge-side-rendering).
|
|
6
|
+
Nuxt supports different rendering modes, [universal rendering](/docs/4.x/guide/concepts/rendering#universal-rendering), [client-side rendering](/docs/4.x/guide/concepts/rendering#client-side-rendering) but also offers [hybrid-rendering](/docs/4.x/guide/concepts/rendering#hybrid-rendering) and the possibility to render your application on [CDN Edge Servers](/docs/4.x/guide/concepts/rendering#edge-side-rendering).
|
|
7
7
|
|
|
8
8
|
Both the browser and server can interpret JavaScript code to turn Vue.js components into HTML elements. This step is called **rendering**. Nuxt supports both **universal** and **client-side** rendering. The two approaches have benefits and downsides that we will cover.
|
|
9
9
|
|
|
@@ -25,17 +25,19 @@ It is normal to ask which parts of a Vue file runs on the server and/or the clie
|
|
|
25
25
|
|
|
26
26
|
```vue [app/app.vue]
|
|
27
27
|
<script setup lang="ts">
|
|
28
|
-
const counter = ref(0)
|
|
28
|
+
const counter = ref(0) // executes in server and client environments
|
|
29
29
|
|
|
30
30
|
const handleClick = () => {
|
|
31
|
-
counter.value
|
|
32
|
-
}
|
|
31
|
+
counter.value++ // executes only in a client environment
|
|
32
|
+
}
|
|
33
33
|
</script>
|
|
34
34
|
|
|
35
35
|
<template>
|
|
36
36
|
<div>
|
|
37
37
|
<p>Count: {{ counter }}</p>
|
|
38
|
-
<button @click="handleClick">
|
|
38
|
+
<button @click="handleClick">
|
|
39
|
+
Increment
|
|
40
|
+
</button>
|
|
39
41
|
</div>
|
|
40
42
|
</template>
|
|
41
43
|
```
|
|
@@ -50,7 +52,7 @@ On the initial request, the `counter` ref is initialized in the server since it
|
|
|
50
52
|
|
|
51
53
|
**Downsides of server-side rendering:**
|
|
52
54
|
- **Development constraints:** Server and browser environments don't provide the same APIs, and it can be tricky to write code that can run on both sides seamlessly. Fortunately, Nuxt provides guidelines and specific variables to help you determine where a piece of code is executed.
|
|
53
|
-
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/guide/concepts/rendering#edge-side-rendering).
|
|
55
|
+
- **Cost:** A server needs to be running in order to render pages on the fly. This adds a monthly cost like any traditional server. However, the server calls are highly reduced thanks to universal rendering with the browser taking over on client-side navigation. A cost reduction is possible by leveraging [edge-side-rendering](/docs/4.x/guide/concepts/rendering#edge-side-rendering).
|
|
54
56
|
|
|
55
57
|
Universal rendering is very versatile and can fit almost any use case, and is especially appropriate for any content-oriented websites: **blogs, marketing websites, portfolios, e-commerce sites, and marketplaces.**
|
|
56
58
|
|
|
@@ -83,13 +85,13 @@ You can enable client-side only rendering with Nuxt in your `nuxt.config.ts`:
|
|
|
83
85
|
|
|
84
86
|
```ts [nuxt.config.ts]
|
|
85
87
|
export default defineNuxtConfig({
|
|
86
|
-
ssr: false
|
|
88
|
+
ssr: false,
|
|
87
89
|
})
|
|
88
90
|
```
|
|
89
91
|
|
|
90
92
|
::note
|
|
91
93
|
If you do use `ssr: false`, you should also place an HTML file in `~/spa-loading-template.html` with some HTML you would like to use to render a loading screen that will be rendered until your app is hydrated.
|
|
92
|
-
:read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
94
|
+
:read-more{title="SPA Loading Template" to="/docs/4.x/api/configuration/nuxt-config#spaloadingtemplate"}
|
|
93
95
|
::
|
|
94
96
|
|
|
95
97
|
:video-accordion{title="Watch a video from Alexander Lichter about Building a plain SPA with Nuxt" videoId="7Lr0QTP1Ro8"}
|
|
@@ -111,7 +113,7 @@ export default defineNuxtConfig({
|
|
|
111
113
|
hooks: {
|
|
112
114
|
'prerender:routes' ({ routes }) {
|
|
113
115
|
routes.clear() // Do not generate any routes (except the defaults)
|
|
114
|
-
}
|
|
116
|
+
},
|
|
115
117
|
},
|
|
116
118
|
})
|
|
117
119
|
```
|
|
@@ -133,14 +135,14 @@ export default defineNuxtConfig({
|
|
|
133
135
|
ssr: false,
|
|
134
136
|
nitro: {
|
|
135
137
|
hooks: {
|
|
136
|
-
'prerender:generate'(route) {
|
|
138
|
+
'prerender:generate' (route) {
|
|
137
139
|
const routesToSkip = ['/index.html', '/200.html', '/404.html']
|
|
138
140
|
if (routesToSkip.includes(route.route)) {
|
|
139
141
|
route.skip = true
|
|
140
142
|
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
144
146
|
})
|
|
145
147
|
```
|
|
146
148
|
|
|
@@ -172,8 +174,8 @@ export default defineNuxtConfig({
|
|
|
172
174
|
// Add cors headers on API routes
|
|
173
175
|
'/api/**': { cors: true },
|
|
174
176
|
// Redirects legacy urls
|
|
175
|
-
'/old-page': { redirect: '/new-page' }
|
|
176
|
-
}
|
|
177
|
+
'/old-page': { redirect: '/new-page' },
|
|
178
|
+
},
|
|
177
179
|
})
|
|
178
180
|
```
|
|
179
181
|
|
|
@@ -26,7 +26,7 @@ Key features include:
|
|
|
26
26
|
|
|
27
27
|
Check out [the h3 docs](https://github.com/h3js/h3) for more information.
|
|
28
28
|
|
|
29
|
-
::read-more{to="/docs/guide/directory-structure/server#server-routes"}
|
|
29
|
+
::read-more{to="/docs/4.x/guide/directory-structure/server#server-routes"}
|
|
30
30
|
Learn more about the API layer in the `server/` directory.
|
|
31
31
|
::
|
|
32
32
|
|
|
@@ -32,8 +32,8 @@ export default defineNuxtConfig({
|
|
|
32
32
|
['./modules/example', { token: '123' }],
|
|
33
33
|
|
|
34
34
|
// Inline module definition
|
|
35
|
-
async (inlineOptions, nuxt) => { }
|
|
36
|
-
]
|
|
35
|
+
async (inlineOptions, nuxt) => { },
|
|
36
|
+
],
|
|
37
37
|
})
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -45,4 +45,4 @@ Nuxt modules are now build-time-only, and the `buildModules` property used in Nu
|
|
|
45
45
|
|
|
46
46
|
Everyone has the opportunity to develop modules and we cannot wait to see what you will build.
|
|
47
47
|
|
|
48
|
-
:read-more{to="/docs/guide/going-further/modules" title="Module Author Guide"}
|
|
48
|
+
:read-more{to="/docs/4.x/guide/going-further/modules" title="Module Author Guide"}
|
|
@@ -111,7 +111,7 @@ const { named } = pkg;
|
|
|
111
111
|
|
|
112
112
|
## Troubleshooting ESM Issues
|
|
113
113
|
|
|
114
|
-
If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](/docs/guide/concepts/esm#library-author-guide) to support being imported by Node.
|
|
114
|
+
If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](/docs/4.x/guide/concepts/esm#library-author-guide) to support being imported by Node.
|
|
115
115
|
|
|
116
116
|
### Transpiling Libraries
|
|
117
117
|
|
|
@@ -120,8 +120,8 @@ In the meantime, you can tell Nuxt not to try to import these libraries by addin
|
|
|
120
120
|
```ts twoslash
|
|
121
121
|
export default defineNuxtConfig({
|
|
122
122
|
build: {
|
|
123
|
-
transpile: ['sample-library']
|
|
124
|
-
}
|
|
123
|
+
transpile: ['sample-library'],
|
|
124
|
+
},
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -134,8 +134,8 @@ In some cases, you may also need to manually alias the library to the CJS versio
|
|
|
134
134
|
```ts twoslash
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
alias: {
|
|
137
|
-
'sample-library': 'sample-library/dist/sample-library.cjs.js'
|
|
138
|
-
}
|
|
137
|
+
'sample-library': 'sample-library/dist/sample-library.cjs.js',
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -182,6 +182,8 @@ import('cjs-pkg').then(console.log) // [Module: null prototype] { default: { tes
|
|
|
182
182
|
|
|
183
183
|
In this case, we need to manually interop the default export:
|
|
184
184
|
|
|
185
|
+
<!-- eslint-disable import/no-named-default -->
|
|
186
|
+
|
|
185
187
|
```js
|
|
186
188
|
// Static import
|
|
187
189
|
import { default as pkg } from 'cjs-pkg'
|
|
@@ -219,16 +221,16 @@ The initial step from CJS to ESM is updating any usage of `require` to use `impo
|
|
|
219
221
|
|
|
220
222
|
::code-group
|
|
221
223
|
|
|
222
|
-
```
|
|
223
|
-
module.exports = ...
|
|
224
|
+
```ts [Before]
|
|
225
|
+
module.exports = function () { /* ... */ }
|
|
224
226
|
|
|
225
|
-
exports.hello =
|
|
227
|
+
exports.hello = 'world'
|
|
226
228
|
```
|
|
227
229
|
|
|
228
|
-
```
|
|
229
|
-
export default ...
|
|
230
|
+
```ts [After]
|
|
231
|
+
export default function () { /* ... */ }
|
|
230
232
|
|
|
231
|
-
export const hello =
|
|
233
|
+
export const hello = 'world'
|
|
232
234
|
```
|
|
233
235
|
|
|
234
236
|
::
|
|
@@ -242,7 +244,7 @@ const myLib = require('my-lib')
|
|
|
242
244
|
```js [After]
|
|
243
245
|
import myLib from 'my-lib'
|
|
244
246
|
// or
|
|
245
|
-
const
|
|
247
|
+
const dynamicMyLib = await import('my-lib').then(lib => lib.default || lib)
|
|
246
248
|
```
|
|
247
249
|
|
|
248
250
|
::
|
|
@@ -253,7 +255,7 @@ and should be replaced with `import()` and `import.meta.filename`.
|
|
|
253
255
|
::code-group
|
|
254
256
|
|
|
255
257
|
```js [Before]
|
|
256
|
-
|
|
258
|
+
const { join } = require('node:path')
|
|
257
259
|
|
|
258
260
|
const newDir = join(__dirname, 'new-dir')
|
|
259
261
|
```
|
|
@@ -282,7 +284,7 @@ const someFile = await resolvePath('my-lib', { url: import.meta.url })
|
|
|
282
284
|
|
|
283
285
|
### Best Practices
|
|
284
286
|
|
|
285
|
-
- Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](/docs/guide/concepts/esm#default-exports) section)
|
|
287
|
+
- Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](/docs/4.x/guide/concepts/esm#default-exports) section)
|
|
286
288
|
|
|
287
289
|
- Avoid depending on Node.js built-ins and CommonJS or Node.js-only dependencies as much as possible to make your library usable in Browsers and Edge Workers without needing Nitro polyfills.
|
|
288
290
|
|
|
@@ -40,8 +40,8 @@ To enable type-checking at build or development time, you can also use the [`typ
|
|
|
40
40
|
```ts twoslash [nuxt.config.ts]
|
|
41
41
|
export default defineNuxtConfig({
|
|
42
42
|
typescript: {
|
|
43
|
-
typeCheck: true
|
|
44
|
-
}
|
|
43
|
+
typeCheck: true,
|
|
44
|
+
},
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -133,7 +133,7 @@ If you are currently converting your codebase to TypeScript, you may want to tem
|
|
|
133
133
|
```ts twoslash [nuxt.config.ts]
|
|
134
134
|
export default defineNuxtConfig({
|
|
135
135
|
typescript: {
|
|
136
|
-
strict: false
|
|
137
|
-
}
|
|
136
|
+
strict: false,
|
|
137
|
+
},
|
|
138
138
|
})
|
|
139
139
|
```
|
|
@@ -16,7 +16,7 @@ You can create your own custom events using the `hook` method:
|
|
|
16
16
|
```ts
|
|
17
17
|
const nuxtApp = useNuxtApp()
|
|
18
18
|
|
|
19
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
19
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
20
20
|
console.log('A new user has registered!', payload)
|
|
21
21
|
})
|
|
22
22
|
```
|
|
@@ -37,7 +37,7 @@ You can also use the payload object to enable two-way communication between the
|
|
|
37
37
|
```ts
|
|
38
38
|
const nuxtApp = useNuxtApp()
|
|
39
39
|
|
|
40
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
40
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
41
41
|
payload.message = 'Welcome to our app!'
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -58,6 +58,6 @@ await nuxtApp.callHook('app:user:registered', {
|
|
|
58
58
|
You can inspect all events using the **Nuxt DevTools** Hooks panel.
|
|
59
59
|
::
|
|
60
60
|
|
|
61
|
-
::read-more{to="/docs/guide/going-further/hooks"}
|
|
61
|
+
::read-more{to="/docs/4.x/guide/going-further/hooks"}
|
|
62
62
|
Learn more about Nuxt's built-in hooks and how to extend them
|
|
63
63
|
::
|