@nuxt/docs 3.19.2 → 3.19.3
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/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +41 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- 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 +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- 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 +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +1 -1
- 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 +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- 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/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +2 -1
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.runtime-config.md +1 -1
- 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 +13 -13
- package/3.api/5.kit/5.components.md +7 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -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/getting-started/installation#play-online).
|
|
15
|
+
If you want to play around with Nuxt in your browser, you can [try it out in one of our online sandboxes](/docs/3.x/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 [`pages/` directory](/docs/guide/directory-structure/pages). This can make it easier to organize your application and avoid the need for manual route configuration.
|
|
22
|
+
- **File-based routing:** define routes based on the structure of your [`pages/` directory](/docs/3.x/guide/directory-structure/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.
|
|
@@ -31,6 +31,7 @@ Or follow the steps below to set up a new Nuxt project on your computer.
|
|
|
31
31
|
- **Node.js**: Make sure to use an even numbered version (18, 20, etc)
|
|
32
32
|
- **Nuxtr**: Install the community-developed [Nuxtr extension](https://marketplace.visualstudio.com/items?itemName=Nuxtr.nuxtr-vscode)
|
|
33
33
|
- **WSL**: If you are using Windows and experience slow HMR, you may want to try using [WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/install) which may solve some performance issues.
|
|
34
|
+
- **Windows slow DNS resolution** - instead of using `localhost:3000` for local dev server on Windows, use `127.0.0.1` for much faster loading experience on browsers.
|
|
34
35
|
::
|
|
35
36
|
::
|
|
36
37
|
|
|
@@ -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/guide/directory-structure/nuxt-config) file can override or extend this default configuration.
|
|
7
|
+
By default, Nuxt is configured to cover most use cases. The [`nuxt.config.ts`](/docs/3.x/guide/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/guide/directory-structure/nuxt-config) file is located at the root of a Nuxt project and can override or extend the application's behavior.
|
|
11
|
+
The [`nuxt.config.ts`](/docs/3.x/guide/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
|
|
|
@@ -36,16 +36,16 @@ You can configure fully typed, per-environment overrides in your nuxt.config
|
|
|
36
36
|
export default defineNuxtConfig({
|
|
37
37
|
$production: {
|
|
38
38
|
routeRules: {
|
|
39
|
-
'/**': { isr: true }
|
|
40
|
-
}
|
|
39
|
+
'/**': { isr: true },
|
|
40
|
+
},
|
|
41
41
|
},
|
|
42
42
|
$development: {
|
|
43
43
|
//
|
|
44
44
|
},
|
|
45
45
|
$env: {
|
|
46
46
|
staging: {
|
|
47
|
-
//
|
|
48
|
-
}
|
|
47
|
+
//
|
|
48
|
+
},
|
|
49
49
|
},
|
|
50
50
|
})
|
|
51
51
|
```
|
|
@@ -75,9 +75,9 @@ export default defineNuxtConfig({
|
|
|
75
75
|
apiSecret: '123',
|
|
76
76
|
// Keys within public are also exposed client-side
|
|
77
77
|
public: {
|
|
78
|
-
apiBase: '/api'
|
|
79
|
-
}
|
|
80
|
-
}
|
|
78
|
+
apiBase: '/api',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
@@ -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/api/composables/use-runtime-config) composable.
|
|
91
|
+
These variables are exposed to the rest of your application using the [`useRuntimeConfig()`](/docs/3.x/api/composables/use-runtime-config) composable.
|
|
92
92
|
|
|
93
93
|
```vue [pages/index.vue]
|
|
94
94
|
<script setup lang="ts">
|
|
@@ -110,13 +110,13 @@ export default defineAppConfig({
|
|
|
110
110
|
theme: {
|
|
111
111
|
dark: true,
|
|
112
112
|
colors: {
|
|
113
|
-
primary: '#ff0000'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
113
|
+
primary: '#ff0000',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
116
|
})
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
119
|
+
These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/3.x/api/composables/use-app-config) composable.
|
|
120
120
|
|
|
121
121
|
```vue [pages/index.vue]
|
|
122
122
|
<script setup lang="ts">
|
|
@@ -145,20 +145,20 @@ Non primitive JS types | ❌ No | ✅ Yes
|
|
|
145
145
|
|
|
146
146
|
## External Configuration Files
|
|
147
147
|
|
|
148
|
-
Nuxt uses [`nuxt.config.ts`](/docs/guide/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.
|
|
148
|
+
Nuxt uses [`nuxt.config.ts`](/docs/3.x/guide/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/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`
|
|
152
|
+
[Nitro](https://nitro.build) | ~~`nitro.config.ts`~~ | Use [`nitro`](/docs/3.x/api/nuxt-config#nitro) key in `nuxt.config`
|
|
153
|
+
[PostCSS](https://postcss.org) | ~~`postcss.config.js`~~ | Use [`postcss`](/docs/3.x/api/nuxt-config#postcss) key in `nuxt.config`
|
|
154
|
+
[Vite](https://vite.dev) | ~~`vite.config.ts`~~ | Use [`vite`](/docs/3.x/api/nuxt-config#vite) key in `nuxt.config`
|
|
155
|
+
[webpack](https://webpack.js.org) | ~~`webpack.config.ts`~~ | Use [`webpack`](/docs/3.x/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/guide/concepts/typescript#nuxttsconfigjson)
|
|
161
|
+
[TypeScript](https://www.typescriptlang.org) | `tsconfig.json` | [More Info](/docs/3.x/guide/concepts/typescript#nuxttsconfigjson)
|
|
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/en/configuration.html)
|
|
164
164
|
[Stylelint](https://stylelint.io) | `stylelint.config.js` | [More Info](https://stylelint.io/user-guide/configure)
|
|
@@ -178,12 +178,12 @@ If you need to pass options to `@vitejs/plugin-vue` or `@vitejs/plugin-vue-jsx`,
|
|
|
178
178
|
export default defineNuxtConfig({
|
|
179
179
|
vite: {
|
|
180
180
|
vue: {
|
|
181
|
-
customElement: true
|
|
181
|
+
customElement: true,
|
|
182
182
|
},
|
|
183
183
|
vueJsx: {
|
|
184
|
-
mergeProps: true
|
|
185
|
-
}
|
|
186
|
-
}
|
|
184
|
+
mergeProps: true,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
187
|
})
|
|
188
188
|
```
|
|
189
189
|
|
|
@@ -199,9 +199,9 @@ export default defineNuxtConfig({
|
|
|
199
199
|
loaders: {
|
|
200
200
|
vue: {
|
|
201
201
|
hotReload: true,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
205
|
})
|
|
206
206
|
```
|
|
207
207
|
|
|
@@ -214,8 +214,8 @@ You may need to enable experimental features in Vue, such as `propsDestructure`.
|
|
|
214
214
|
```ts twoslash [nuxt.config.ts]
|
|
215
215
|
export default defineNuxtConfig({
|
|
216
216
|
vue: {
|
|
217
|
-
propsDestructure: true
|
|
218
|
-
}
|
|
217
|
+
propsDestructure: true,
|
|
218
|
+
},
|
|
219
219
|
})
|
|
220
220
|
```
|
|
221
221
|
|
|
@@ -13,7 +13,7 @@ By default, Nuxt will treat this file as the **entrypoint** and render its conte
|
|
|
13
13
|
```vue [app.vue]
|
|
14
14
|
<template>
|
|
15
15
|
<div>
|
|
16
|
-
|
|
16
|
+
<h1>Welcome to the homepage</h1>
|
|
17
17
|
</div>
|
|
18
18
|
</template>
|
|
19
19
|
```
|
|
@@ -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 [`components/`](/docs/guide/directory-structure/components) directory, and they will be automatically available across your application without having to explicitly import them.
|
|
29
|
+
Most components are reusable pieces of the user interface, like buttons and menus. In Nuxt, you can create these components in the [`components/`](/docs/3.x/guide/directory-structure/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 [`pages/`](/docs/guide/directory-structure/pages) directory represents a different route displaying its content.
|
|
58
|
+
Pages represent views for each specific route pattern. Every file in the [`pages/`](/docs/3.x/guide/directory-structure/pages) directory represents a different route displaying its content.
|
|
59
59
|
|
|
60
|
-
To use pages, create `pages/index.vue` file and add `<NuxtPage />` component to the [`app.vue`](/docs/guide/directory-structure/app) (or remove `app.vue` for default entry). You can now create more pages and their corresponding routes by adding new files in the [`pages/`](/docs/guide/directory-structure/pages) directory.
|
|
60
|
+
To use pages, create `pages/index.vue` file and add `<NuxtPage />` component to the [`app.vue`](/docs/3.x/guide/directory-structure/app) (or remove `app.vue` for default entry). You can now create more pages and their corresponding routes by adding new files in the [`pages/`](/docs/3.x/guide/directory-structure/pages) directory.
|
|
61
61
|
|
|
62
62
|
::code-group
|
|
63
63
|
|
|
@@ -91,7 +91,7 @@ To use pages, create `pages/index.vue` file and add `<NuxtPage />` component to
|
|
|
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 `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.vue`](/docs/guide/directory-structure/app) with [`<NuxtPage />`](/docs/api/components/nuxt-page) instead.
|
|
94
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/3.x/guide/directory-structure/app) with [`<NuxtPage />`](/docs/3.x/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.v
|
|
|
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/guide/directory-structure/layouts).
|
|
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/3.x/guide/directory-structure/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/getting-started/seo-meta).
|
|
145
|
+
If you only need to modify the `<head>`, you can refer to the [SEO and meta section](/docs/3.x/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.
|
|
@@ -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/guide/directory-structure/public) directory content is served at the server root as-is.
|
|
10
|
-
- The [`assets/`](/docs/guide/directory-structure/assets) directory contains by convention every asset that you want the build tool (Vite or webpack) to process.
|
|
9
|
+
- The [`public/`](/docs/3.x/guide/directory-structure/public) directory content is served at the server root as-is.
|
|
10
|
+
- The [`assets/`](/docs/3.x/guide/directory-structure/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/guide/directory-structure/public) directory is used as a public server for static assets publicly available at a defined URL of your application.
|
|
14
|
+
The [`public/`](/docs/3.x/guide/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/guide/directory-structure/public) directory from your application's code or from a browser by the root URL `/`.
|
|
16
|
+
You can get a file in the [`public/`](/docs/3.x/guide/directory-structure/public) directory from your application's code or from a browser by the root URL `/`.
|
|
17
17
|
|
|
18
18
|
### Example
|
|
19
19
|
|
|
@@ -21,7 +21,10 @@ For example, referencing an image file in the `public/img/` directory, available
|
|
|
21
21
|
|
|
22
22
|
```vue [app.vue]
|
|
23
23
|
<template>
|
|
24
|
-
<img
|
|
24
|
+
<img
|
|
25
|
+
src="/img/nuxt.png"
|
|
26
|
+
alt="Discover Nuxt"
|
|
27
|
+
>
|
|
25
28
|
</template>
|
|
26
29
|
```
|
|
27
30
|
|
|
@@ -29,9 +32,9 @@ For example, referencing an image file in the `public/img/` directory, available
|
|
|
29
32
|
|
|
30
33
|
Nuxt uses [Vite](https://vite.dev/guide/assets.html) (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).
|
|
31
34
|
|
|
32
|
-
By convention, Nuxt uses the [`assets/`](/docs/guide/directory-structure/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.
|
|
35
|
+
By convention, Nuxt uses the [`assets/`](/docs/3.x/guide/directory-structure/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.
|
|
33
36
|
|
|
34
|
-
In your application's code, you can reference a file located in the [`assets/`](/docs/guide/directory-structure/assets) directory by using the `~/assets/` path.
|
|
37
|
+
In your application's code, you can reference a file located in the [`assets/`](/docs/3.x/guide/directory-structure/assets) directory by using the `~/assets/` path.
|
|
35
38
|
|
|
36
39
|
### Example
|
|
37
40
|
|
|
@@ -39,10 +42,13 @@ For example, referencing an image file that will be processed if a build tool is
|
|
|
39
42
|
|
|
40
43
|
```vue [app.vue]
|
|
41
44
|
<template>
|
|
42
|
-
<img
|
|
45
|
+
<img
|
|
46
|
+
src="~/assets/img/nuxt.png"
|
|
47
|
+
alt="Discover Nuxt"
|
|
48
|
+
>
|
|
43
49
|
</template>
|
|
44
50
|
```
|
|
45
51
|
|
|
46
52
|
::note
|
|
47
|
-
Nuxt won't serve files in the [`assets/`](/docs/guide/directory-structure/assets) directory at a static URL like `/assets/my-file.png`. If you need a static URL, use the [`public/`](#public-directory) directory.
|
|
53
|
+
Nuxt won't serve files in the [`assets/`](/docs/3.x/guide/directory-structure/assets) directory at a static URL like `/assets/my-file.png`. If you need a static URL, use the [`public/`](#public-directory) directory.
|
|
48
54
|
::
|
|
@@ -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 [`assets/` directory](/docs/guide/directory-structure/assets).
|
|
12
|
+
If you're writing local stylesheets, the natural place to put them is the [`assets/` directory](/docs/3.x/guide/directory-structure/assets).
|
|
13
13
|
|
|
14
14
|
### Importing Within Components
|
|
15
15
|
|
|
@@ -37,11 +37,11 @@ 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 [`assets/` directory](/docs/guide/directory-structure/assets). You can then reference its path and Nuxt will include it to all the pages of your application.
|
|
40
|
+
The natural place for your stylesheets is the [`assets/` directory](/docs/3.x/guide/directory-structure/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({
|
|
44
|
-
css: ['~/assets/css/main.css']
|
|
44
|
+
css: ['~/assets/css/main.css'],
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -113,7 +113,7 @@ The package can also be referenced as a string in the css property of your Nuxt
|
|
|
113
113
|
|
|
114
114
|
```ts [nuxt.config.ts]
|
|
115
115
|
export default defineNuxtConfig({
|
|
116
|
-
css: ['animate.css']
|
|
116
|
+
css: ['animate.css'],
|
|
117
117
|
})
|
|
118
118
|
```
|
|
119
119
|
|
|
@@ -121,15 +121,15 @@ export default defineNuxtConfig({
|
|
|
121
121
|
|
|
122
122
|
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.
|
|
123
123
|
|
|
124
|
-
You can manipulate the head with the [`app.head`](/docs/api/nuxt-config#head) property of your Nuxt configuration:
|
|
124
|
+
You can manipulate the head with the [`app.head`](/docs/3.x/api/nuxt-config#head) property of your Nuxt configuration:
|
|
125
125
|
|
|
126
126
|
```ts twoslash [nuxt.config.ts]
|
|
127
127
|
export default defineNuxtConfig({
|
|
128
128
|
app: {
|
|
129
129
|
head: {
|
|
130
|
-
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
130
|
+
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
133
|
})
|
|
134
134
|
```
|
|
135
135
|
|
|
@@ -141,7 +141,7 @@ You can use the useHead composable to dynamically set a value in your head in yo
|
|
|
141
141
|
|
|
142
142
|
```ts twoslash
|
|
143
143
|
useHead({
|
|
144
|
-
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }]
|
|
144
|
+
link: [{ rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css' }],
|
|
145
145
|
})
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -196,7 +196,7 @@ Alternatively, you can use the `css` property of your Nuxt configuration.
|
|
|
196
196
|
|
|
197
197
|
```ts twoslash [nuxt.config.ts]
|
|
198
198
|
export default defineNuxtConfig({
|
|
199
|
-
css: ['~/assets/scss/main.scss']
|
|
199
|
+
css: ['~/assets/scss/main.scss'],
|
|
200
200
|
})
|
|
201
201
|
```
|
|
202
202
|
|
|
@@ -232,11 +232,11 @@ export default defineNuxtConfig({
|
|
|
232
232
|
css: {
|
|
233
233
|
preprocessorOptions: {
|
|
234
234
|
scss: {
|
|
235
|
-
additionalData: '@use "~/assets/_colors.scss" as *;'
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
235
|
+
additionalData: '@use "~/assets/_colors.scss" as *;',
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
240
|
})
|
|
241
241
|
```
|
|
242
242
|
|
|
@@ -246,11 +246,11 @@ export default defineNuxtConfig({
|
|
|
246
246
|
css: {
|
|
247
247
|
preprocessorOptions: {
|
|
248
248
|
sass: {
|
|
249
|
-
additionalData: '@use "~/assets/_colors.sass" as *\n'
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
249
|
+
additionalData: '@use "~/assets/_colors.sass" as *\n',
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
254
|
})
|
|
255
255
|
```
|
|
256
256
|
|
|
@@ -265,13 +265,12 @@ Vite has made available an [experimental option](https://vite.dev/config/shared-
|
|
|
265
265
|
You can enable this in your `nuxt.config`:
|
|
266
266
|
|
|
267
267
|
```ts
|
|
268
|
-
|
|
269
268
|
export default defineNuxtConfig({
|
|
270
269
|
vite: {
|
|
271
270
|
css: {
|
|
272
|
-
preprocessorMaxWorkers: true // number of CPUs minus 1
|
|
273
|
-
}
|
|
274
|
-
}
|
|
271
|
+
preprocessorMaxWorkers: true, // number of CPUs minus 1
|
|
272
|
+
},
|
|
273
|
+
},
|
|
275
274
|
})
|
|
276
275
|
```
|
|
277
276
|
|
|
@@ -296,14 +295,17 @@ You can leverage Vue SFC features to style your components with class and style
|
|
|
296
295
|
const isActive = ref(true)
|
|
297
296
|
const hasError = ref(false)
|
|
298
297
|
const classObject = reactive({
|
|
299
|
-
active: true,
|
|
300
|
-
'text-danger': false
|
|
298
|
+
'active': true,
|
|
299
|
+
'text-danger': false,
|
|
301
300
|
})
|
|
302
301
|
</script>
|
|
303
302
|
|
|
304
303
|
<template>
|
|
305
|
-
<div
|
|
306
|
-
|
|
304
|
+
<div
|
|
305
|
+
class="static"
|
|
306
|
+
:class="{ 'active': isActive, 'text-danger': hasError }"
|
|
307
|
+
/>
|
|
308
|
+
<div :class="classObject" />
|
|
307
309
|
</template>
|
|
308
310
|
```
|
|
309
311
|
|
|
@@ -313,13 +315,13 @@ const isActive = ref(true)
|
|
|
313
315
|
const error = ref(null)
|
|
314
316
|
|
|
315
317
|
const classObject = computed(() => ({
|
|
316
|
-
active: isActive.value && !error.value,
|
|
317
|
-
'text-danger': error.value && error.value.type === 'fatal'
|
|
318
|
+
'active': isActive.value && !error.value,
|
|
319
|
+
'text-danger': error.value && error.value.type === 'fatal',
|
|
318
320
|
}))
|
|
319
321
|
</script>
|
|
320
322
|
|
|
321
323
|
<template>
|
|
322
|
-
<div :class="classObject"
|
|
324
|
+
<div :class="classObject" />
|
|
323
325
|
</template>
|
|
324
326
|
```
|
|
325
327
|
|
|
@@ -330,7 +332,7 @@ const errorClass = ref('text-danger')
|
|
|
330
332
|
</script>
|
|
331
333
|
|
|
332
334
|
<template>
|
|
333
|
-
<div :class="[{ active: isActive }, errorClass]"
|
|
335
|
+
<div :class="[{ active: isActive }, errorClass]" />
|
|
334
336
|
</template>
|
|
335
337
|
```
|
|
336
338
|
|
|
@@ -342,9 +344,9 @@ const styleObject = reactive({ color: 'red', fontSize: '13px' })
|
|
|
342
344
|
</script>
|
|
343
345
|
|
|
344
346
|
<template>
|
|
345
|
-
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"
|
|
346
|
-
<div :style="[baseStyles, overridingStyles]"
|
|
347
|
-
<div :style="styleObject"
|
|
347
|
+
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }" />
|
|
348
|
+
<div :style="[baseStyles, overridingStyles]" />
|
|
349
|
+
<div :style="styleObject" />
|
|
348
350
|
</template>
|
|
349
351
|
```
|
|
350
352
|
|
|
@@ -359,11 +361,13 @@ The binding will be dynamic, meaning that if the variable value changes, the sty
|
|
|
359
361
|
|
|
360
362
|
```vue
|
|
361
363
|
<script setup lang="ts">
|
|
362
|
-
const color = ref(
|
|
364
|
+
const color = ref('red')
|
|
363
365
|
</script>
|
|
364
366
|
|
|
365
367
|
<template>
|
|
366
|
-
<div class="text">
|
|
368
|
+
<div class="text">
|
|
369
|
+
hello
|
|
370
|
+
</div>
|
|
367
371
|
</template>
|
|
368
372
|
|
|
369
373
|
<style>
|
|
@@ -379,7 +383,9 @@ The scoped attribute allows you to style components in isolation. The styles dec
|
|
|
379
383
|
|
|
380
384
|
```vue
|
|
381
385
|
<template>
|
|
382
|
-
<div class="example">
|
|
386
|
+
<div class="example">
|
|
387
|
+
hi
|
|
388
|
+
</div>
|
|
383
389
|
</template>
|
|
384
390
|
|
|
385
391
|
<style scoped>
|
|
@@ -395,7 +401,9 @@ You can use [CSS Modules](https://github.com/css-modules/css-modules) with the m
|
|
|
395
401
|
|
|
396
402
|
```vue
|
|
397
403
|
<template>
|
|
398
|
-
<p :class="$style.red">
|
|
404
|
+
<p :class="$style.red">
|
|
405
|
+
This should be red
|
|
406
|
+
</p>
|
|
399
407
|
</template>
|
|
400
408
|
|
|
401
409
|
<style module>
|
|
@@ -449,9 +457,9 @@ export default defineNuxtConfig({
|
|
|
449
457
|
postcss: {
|
|
450
458
|
plugins: {
|
|
451
459
|
'postcss-nested': {},
|
|
452
|
-
'postcss-custom-media': {}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
460
|
+
'postcss-custom-media': {},
|
|
461
|
+
},
|
|
462
|
+
},
|
|
455
463
|
})
|
|
456
464
|
```
|
|
457
465
|
|
|
@@ -507,7 +515,7 @@ Here are a few modules to help you get started:
|
|
|
507
515
|
- [Nuxt UI](https://ui.nuxt.com): A UI Library for Modern Web Apps
|
|
508
516
|
- [Panda CSS](https://panda-css.com/docs/installation/nuxt): CSS-in-JS engine that generates atomic CSS at build time
|
|
509
517
|
|
|
510
|
-
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/guide/directory-structure/plugins) and/or [make your own module](/docs/guide/going-further/modules). Share them with the [community](/modules) if you do!
|
|
518
|
+
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/3.x/guide/directory-structure/plugins) and/or [make your own module](/docs/3.x/guide/going-further/modules). Share them with the [community](/modules) if you do!
|
|
511
519
|
|
|
512
520
|
### Easily Load Webfonts
|
|
513
521
|
|
|
@@ -519,7 +527,7 @@ If you are using [UnoCSS](https://unocss.dev/integrations/nuxt), note that it co
|
|
|
519
527
|
|
|
520
528
|
### Transitions
|
|
521
529
|
|
|
522
|
-
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).
|
|
530
|
+
Nuxt comes with the same `<Transition>` element that Vue has, and also has support for the experimental [View Transitions API](/docs/3.x/getting-started/transitions#view-transitions-api-experimental).
|
|
523
531
|
|
|
524
532
|
:read-more{to="/docs/getting-started/transitions"}
|
|
525
533
|
|
|
@@ -556,7 +564,9 @@ export default defineNuxtConfig({
|
|
|
556
564
|
// start from the end of the array and go to the beginning
|
|
557
565
|
for (let i = css.length - 1; i >= 0; i--) {
|
|
558
566
|
// if it starts with 'entry', remove it from the list
|
|
559
|
-
if (css[i].startsWith('entry'))
|
|
567
|
+
if (css[i].startsWith('entry')) {
|
|
568
|
+
css.splice(i, 1)
|
|
569
|
+
}
|
|
560
570
|
}
|
|
561
571
|
}
|
|
562
572
|
},
|
|
@@ -4,11 +4,11 @@ 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 [`pages/`](/docs/guide/directory-structure/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.
|
|
7
|
+
One core feature of Nuxt is the file system router. Every Vue file inside the [`pages/`](/docs/3.x/guide/directory-structure/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
|
## Pages
|
|
10
10
|
|
|
11
|
-
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`pages/` directory](/docs/guide/directory-structure/pages), based on their filename.
|
|
11
|
+
Nuxt routing is based on [vue-router](https://router.vuejs.org) and generates the routes from every component created in the [`pages/` directory](/docs/3.x/guide/directory-structure/pages), based on their filename.
|
|
12
12
|
|
|
13
13
|
This file system routing uses naming conventions to create dynamic and nested routes:
|
|
14
14
|
|
|
@@ -47,9 +47,9 @@ This file system routing uses naming conventions to create dynamic and nested ro
|
|
|
47
47
|
|
|
48
48
|
## Navigation
|
|
49
49
|
|
|
50
|
-
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.
|
|
50
|
+
The [`<NuxtLink>`](/docs/3.x/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.
|
|
51
51
|
|
|
52
|
-
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.
|
|
52
|
+
When a [`<NuxtLink>`](/docs/3.x/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.
|
|
53
53
|
|
|
54
54
|
```vue [pages/index.vue]
|
|
55
55
|
<template>
|
|
@@ -69,7 +69,7 @@ When a [`<NuxtLink>`](/docs/api/components/nuxt-link) enters the viewport on the
|
|
|
69
69
|
|
|
70
70
|
## Route Parameters
|
|
71
71
|
|
|
72
|
-
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.
|
|
72
|
+
The [`useRoute()`](/docs/3.x/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.
|
|
73
73
|
|
|
74
74
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
75
75
|
<script setup lang="ts">
|
|
@@ -93,15 +93,15 @@ Route middleware runs within the Vue part of your Nuxt app. Despite the similar
|
|
|
93
93
|
There are three kinds of route middleware:
|
|
94
94
|
|
|
95
95
|
1. Anonymous (or inline) route middleware, which are defined directly in the pages where they are used.
|
|
96
|
-
2. Named route middleware, which are placed in the [`middleware/`](/docs/guide/directory-structure/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`.)
|
|
97
|
-
3. Global route middleware, which are placed in the [`middleware/`](/docs/guide/directory-structure/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
96
|
+
2. Named route middleware, which are placed in the [`middleware/`](/docs/3.x/guide/directory-structure/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`.)
|
|
97
|
+
3. Global route middleware, which are placed in the [`middleware/`](/docs/3.x/guide/directory-structure/middleware) directory (with a `.global` suffix) and will be automatically run on every route change.
|
|
98
98
|
|
|
99
99
|
Example of an `auth` middleware protecting the `/dashboard` page:
|
|
100
100
|
|
|
101
101
|
::code-group
|
|
102
102
|
|
|
103
103
|
```ts twoslash [middleware/auth.ts]
|
|
104
|
-
function isAuthenticated(): boolean { return false }
|
|
104
|
+
function isAuthenticated (): boolean { return false }
|
|
105
105
|
// ---cut---
|
|
106
106
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
107
107
|
// isAuthenticated() is an example method verifying if a user is authenticated
|
|
@@ -114,7 +114,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|
|
114
114
|
```vue twoslash [pages/dashboard.vue]
|
|
115
115
|
<script setup lang="ts">
|
|
116
116
|
definePageMeta({
|
|
117
|
-
middleware: 'auth'
|
|
117
|
+
middleware: 'auth',
|
|
118
118
|
})
|
|
119
119
|
</script>
|
|
120
120
|
|
|
@@ -129,7 +129,7 @@ definePageMeta({
|
|
|
129
129
|
|
|
130
130
|
## Route Validation
|
|
131
131
|
|
|
132
|
-
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/api/utils/define-page-meta) in each page you wish to validate.
|
|
132
|
+
Nuxt offers route validation via the `validate` property in [`definePageMeta()`](/docs/3.x/api/utils/define-page-meta) in each page you wish to validate.
|
|
133
133
|
|
|
134
134
|
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 `statusCode`/`statusMessage` to customize the error returned.
|
|
135
135
|
|
|
@@ -138,10 +138,10 @@ If you have a more complex use case, then you can use anonymous route middleware
|
|
|
138
138
|
```vue twoslash [pages/posts/[id\\].vue]
|
|
139
139
|
<script setup lang="ts">
|
|
140
140
|
definePageMeta({
|
|
141
|
-
validate
|
|
141
|
+
validate (route) {
|
|
142
142
|
// Check if the id is made up of digits
|
|
143
143
|
return typeof route.params.id === 'string' && /^\d+$/.test(route.params.id)
|
|
144
|
-
}
|
|
144
|
+
},
|
|
145
145
|
})
|
|
146
146
|
</script>
|
|
147
147
|
```
|