@nuxt/docs 3.20.1 → 3.20.2
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 +1 -1
- package/1.getting-started/03.configuration.md +3 -3
- package/1.getting-started/04.views.md +5 -5
- package/1.getting-started/05.assets.md +7 -7
- package/1.getting-started/06.styling.md +3 -3
- package/1.getting-started/07.routing.md +5 -5
- package/1.getting-started/08.seo-meta.md +2 -2
- package/1.getting-started/09.transitions.md +6 -6
- package/1.getting-started/11.state-management.md +2 -2
- package/1.getting-started/12.error-handling.md +3 -3
- package/1.getting-started/14.layers.md +3 -3
- package/1.getting-started/16.deployment.md +1 -1
- package/1.getting-started/17.testing.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.nuxt.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/0.output.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.assets.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.components.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.composables.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.layouts.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.middleware.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.node_modules.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.pages.md +6 -6
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.plugins.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/1.utils.md +3 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +1 -1
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.app.md +2 -2
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.error.md +1 -3
- package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +1 -1
- package/2.directory-structure/index.md +61 -0
- package/{2.guide → 3.guide}/0.index.md +6 -9
- package/{2.guide/2.concepts → 3.guide/1.concepts}/1.auto-imports.md +4 -4
- package/{2.guide/2.concepts → 3.guide/1.concepts}/10.nuxt-lifecycle.md +3 -3
- package/{2.guide/2.concepts → 3.guide/1.concepts}/2.vuejs-development.md +3 -3
- package/{2.guide/2.concepts → 3.guide/1.concepts}/3.rendering.md +1 -1
- package/{2.guide/2.concepts → 3.guide/1.concepts}/4.server-engine.md +2 -2
- package/{2.guide/2.concepts → 3.guide/1.concepts}/5.modules.md +1 -1
- package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +2 -2
- package/{2.guide/4.recipes → 3.guide/3.recipes}/1.custom-routing.md +1 -1
- package/{2.guide/4.recipes → 3.guide/3.recipes}/2.vite-plugin.md +1 -1
- package/{2.guide/4.recipes → 3.guide/3.recipes}/3.custom-usefetch.md +1 -1
- package/{2.guide/3.going-further → 3.guide/4.going-further}/1.experimental-features.md +2 -2
- package/{2.guide/3.going-further → 3.guide/4.going-further}/1.internals.md +2 -2
- package/{2.guide/3.going-further → 3.guide/4.going-further}/10.runtime-config.md +1 -1
- package/{2.guide/3.going-further → 3.guide/4.going-further}/2.hooks.md +2 -2
- package/{2.guide/3.going-further → 3.guide/4.going-further}/3.modules.md +2 -2
- package/{2.guide/3.going-further → 3.guide/4.going-further}/6.nuxt-app.md +1 -1
- package/{2.guide/3.going-further → 3.guide/4.going-further}/7.layers.md +11 -11
- package/{3.api → 4.api}/1.components/12.nuxt-route-announcer.md +1 -1
- package/{3.api → 4.api}/1.components/2.nuxt-page.md +1 -1
- package/{3.api → 4.api}/1.components/3.nuxt-layout.md +2 -2
- package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +1 -1
- package/{3.api → 4.api}/2.composables/use-nuxt-app.md +4 -4
- package/{3.api → 4.api}/2.composables/use-response-header.md +1 -1
- package/{3.api → 4.api}/2.composables/use-route.md +1 -1
- package/{3.api → 4.api}/2.composables/use-router.md +1 -1
- package/{3.api → 4.api}/3.utils/$fetch.md +1 -1
- package/{3.api → 4.api}/3.utils/abort-navigation.md +1 -1
- package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
- package/{3.api → 4.api}/3.utils/define-nuxt-plugin.md +1 -1
- package/{3.api → 4.api}/3.utils/define-nuxt-route-middleware.md +1 -1
- package/{3.api → 4.api}/3.utils/define-page-meta.md +5 -5
- package/{3.api → 4.api}/3.utils/update-app-config.md +1 -1
- package/{3.api → 4.api}/4.commands/module.md +2 -2
- package/{3.api → 4.api}/4.commands/prepare.md +1 -1
- package/{3.api → 4.api}/4.commands/preview.md +1 -1
- package/{3.api → 4.api}/4.commands/typecheck.md +1 -1
- package/{3.api → 4.api}/6.advanced/1.hooks.md +1 -1
- package/5.community/6.roadmap.md +6 -6
- package/5.community/7.changelog.md +10 -0
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/4.plugins-and-middleware.md +2 -2
- package/7.migration/2.configuration.md +1 -1
- package/7.migration/3.auto-imports.md +1 -1
- package/7.migration/6.pages-and-layouts.md +4 -4
- package/package.json +1 -1
- /package/{2.guide/1.directory-structure → 2.directory-structure}/.navigation.yml +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/2.gitignore.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/3.app-config.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/3.package.md +0 -0
- /package/{2.guide/1.directory-structure → 2.directory-structure}/3.tsconfig.md +0 -0
- /package/{2.guide → 3.guide}/.navigation.yml +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/.navigation.yml +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +0 -0
- /package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/performance.md +0 -0
- /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/plugins.md +0 -0
- /package/{2.guide/4.recipes → 3.guide/3.recipes}/.navigation.yml +0 -0
- /package/{2.guide/4.recipes → 3.guide/3.recipes}/4.sessions-and-authentication.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/.navigation.yml +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/1.events.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/1.features.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/11.nightly-release-channel.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/4.kit.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/9.debugging.md +0 -0
- /package/{2.guide/3.going-further → 3.guide/4.going-further}/index.md +0 -0
- /package/{3.api → 4.api}/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/.navigation.yml +0 -0
- /package/{3.api → 4.api}/1.components/1.client-only.md +0 -0
- /package/{3.api → 4.api}/1.components/1.dev-only.md +0 -0
- /package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +0 -0
- /package/{3.api → 4.api}/1.components/10.nuxt-picture.md +0 -0
- /package/{3.api → 4.api}/1.components/11.teleports.md +0 -0
- /package/{3.api → 4.api}/1.components/13.nuxt-time.md +0 -0
- /package/{3.api → 4.api}/1.components/4.nuxt-link.md +0 -0
- /package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +0 -0
- /package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +0 -0
- /package/{3.api → 4.api}/1.components/8.nuxt-island.md +0 -0
- /package/{3.api → 4.api}/1.components/9.nuxt-img.md +0 -0
- /package/{3.api → 4.api}/2.composables/.navigation.yml +0 -0
- /package/{3.api → 4.api}/2.composables/on-prehydrate.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-app-config.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-async-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-cookie.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-error.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-fetch.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-head-safe.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-head.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-hydration.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-lazy-async-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-lazy-fetch.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-loading-indicator.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-preview-mode.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-event.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-fetch.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-header.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-headers.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-request-url.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-route-announcer.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-runtime-config.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-runtime-hook.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-seo-meta.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +0 -0
- /package/{3.api → 4.api}/2.composables/use-state.md +0 -0
- /package/{3.api → 4.api}/3.utils/.navigation.yml +0 -0
- /package/{3.api → 4.api}/3.utils/call-once.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-error.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/3.utils/clear-nuxt-state.md +0 -0
- /package/{3.api → 4.api}/3.utils/create-error.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-nuxt-component.md +0 -0
- /package/{3.api → 4.api}/3.utils/define-route-rules.md +0 -0
- /package/{3.api → 4.api}/3.utils/navigate-to.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-before-route-leave.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-before-route-update.md +0 -0
- /package/{3.api → 4.api}/3.utils/on-nuxt-ready.md +0 -0
- /package/{3.api → 4.api}/3.utils/prefetch-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/preload-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/preload-route-components.md +0 -0
- /package/{3.api → 4.api}/3.utils/prerender-routes.md +0 -0
- /package/{3.api → 4.api}/3.utils/refresh-cookie.md +0 -0
- /package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +0 -0
- /package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +0 -0
- /package/{3.api → 4.api}/3.utils/set-page-layout.md +0 -0
- /package/{3.api → 4.api}/3.utils/set-response-status.md +0 -0
- /package/{3.api → 4.api}/3.utils/show-error.md +0 -0
- /package/{3.api → 4.api}/4.commands/.navigation.yml +0 -0
- /package/{3.api → 4.api}/4.commands/add.md +0 -0
- /package/{3.api → 4.api}/4.commands/analyze.md +0 -0
- /package/{3.api → 4.api}/4.commands/build-module.md +0 -0
- /package/{3.api → 4.api}/4.commands/build.md +0 -0
- /package/{3.api → 4.api}/4.commands/cleanup.md +0 -0
- /package/{3.api → 4.api}/4.commands/dev.md +0 -0
- /package/{3.api → 4.api}/4.commands/devtools.md +0 -0
- /package/{3.api → 4.api}/4.commands/generate.md +0 -0
- /package/{3.api → 4.api}/4.commands/info.md +0 -0
- /package/{3.api → 4.api}/4.commands/init.md +0 -0
- /package/{3.api → 4.api}/4.commands/test.md +0 -0
- /package/{3.api → 4.api}/4.commands/upgrade.md +0 -0
- /package/{3.api → 4.api}/5.kit/.navigation.yml +0 -0
- /package/{3.api → 4.api}/5.kit/1.modules.md +0 -0
- /package/{3.api → 4.api}/5.kit/10.runtime-config.md +0 -0
- /package/{3.api → 4.api}/5.kit/10.templates.md +0 -0
- /package/{3.api → 4.api}/5.kit/11.nitro.md +0 -0
- /package/{3.api → 4.api}/5.kit/12.resolving.md +0 -0
- /package/{3.api → 4.api}/5.kit/13.logging.md +0 -0
- /package/{3.api → 4.api}/5.kit/14.builder.md +0 -0
- /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
- /package/{3.api → 4.api}/5.kit/16.layers.md +0 -0
- /package/{3.api → 4.api}/5.kit/2.programmatic.md +0 -0
- /package/{3.api → 4.api}/5.kit/3.compatibility.md +0 -0
- /package/{3.api → 4.api}/5.kit/4.autoimports.md +0 -0
- /package/{3.api → 4.api}/5.kit/5.components.md +0 -0
- /package/{3.api → 4.api}/5.kit/6.context.md +0 -0
- /package/{3.api → 4.api}/5.kit/7.pages.md +0 -0
- /package/{3.api → 4.api}/5.kit/8.layout.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.head.md +0 -0
- /package/{3.api → 4.api}/5.kit/9.plugins.md +0 -0
- /package/{3.api → 4.api}/6.advanced/.navigation.yml +0 -0
- /package/{3.api → 4.api}/6.advanced/2.import-meta.md +0 -0
- /package/{3.api → 4.api}/6.nuxt-config.md +0 -0
- /package/{3.api → 4.api}/index.md +0 -0
|
@@ -7,7 +7,7 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
7
7
|
|
|
8
8
|
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/3.x/api/nuxt-config#rootdir)) during the build phase.
|
|
9
9
|
|
|
10
|
-
It is subject to the same specification as [`.gitignore`](/docs/3.x/
|
|
10
|
+
It is subject to the same specification as [`.gitignore`](/docs/3.x/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
11
11
|
|
|
12
12
|
::tip
|
|
13
13
|
You can also configure [`ignoreOptions`](/docs/3.x/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/3.x/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/3.x/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
@@ -8,7 +8,7 @@ navigation.icon: i-vscode-icons-file-type-nuxt
|
|
|
8
8
|
The `.nuxtrc` file can be used to configure Nuxt with a flat syntax. It is based on [`unjs/rc9`](https://github.com/unjs/rc9).
|
|
9
9
|
|
|
10
10
|
::tip
|
|
11
|
-
For more advanced configurations, use [`nuxt.config`](/docs/3.x/
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/3.x/directory-structure/nuxt-config).
|
|
12
12
|
::
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -13,7 +13,7 @@ If you have a `pages/` directory, the `app.vue` file is optional. Nuxt will auto
|
|
|
13
13
|
|
|
14
14
|
### Minimal Usage
|
|
15
15
|
|
|
16
|
-
With Nuxt, the [`pages/`](/docs/3.x/
|
|
16
|
+
With Nuxt, the [`pages/`](/docs/3.x/directory-structure/pages) directory is optional. If it is not present, Nuxt will not include the [vue-router](https://router.vuejs.org) dependency. This is useful when building a landing page or an application that does not require routing.
|
|
17
17
|
|
|
18
18
|
```vue [app.vue]
|
|
19
19
|
<template>
|
|
@@ -25,7 +25,7 @@ With Nuxt, the [`pages/`](/docs/3.x/guide/directory-structure/pages) directory i
|
|
|
25
25
|
|
|
26
26
|
### Usage with Pages
|
|
27
27
|
|
|
28
|
-
When you have a [`pages/`](/docs/3.x/
|
|
28
|
+
When you have a [`pages/`](/docs/3.x/directory-structure/pages) directory, you need to use the [`<NuxtPage>`](/docs/3.x/api/components/nuxt-page) component to display the current page:
|
|
29
29
|
|
|
30
30
|
```vue [app.vue]
|
|
31
31
|
<template>
|
|
@@ -11,9 +11,7 @@ During the lifespan of your application, some errors may appear unexpectedly at
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
12
|
import type { NuxtError } from '#app'
|
|
13
13
|
|
|
14
|
-
const props = defineProps(
|
|
15
|
-
error: Object as () => NuxtError,
|
|
16
|
-
})
|
|
14
|
+
const props = defineProps<{ error: NuxtError }>()
|
|
17
15
|
</script>
|
|
18
16
|
|
|
19
17
|
<template>
|
|
@@ -31,4 +31,4 @@ export default defineNuxtConfig({
|
|
|
31
31
|
Discover all the available options in the **Nuxt configuration** documentation.
|
|
32
32
|
::
|
|
33
33
|
|
|
34
|
-
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/3.x/
|
|
34
|
+
To ensure your configuration is up to date, Nuxt will make a full restart when detecting changes in the main configuration file, the [`.env`](/docs/3.x/directory-structure/env), [`.nuxtignore`](/docs/3.x/directory-structure/nuxtignore) and [`.nuxtrc`](/docs/3.x/directory-structure/nuxtrc) dotfiles.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Nuxt Directory Structure'
|
|
3
|
+
description: 'Learn about the directory structure of a Nuxt application and how to use it.'
|
|
4
|
+
navigation: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Nuxt applications have a specific directory structure that is used to organize the code. This structure is designed to be easy to understand and to be used in a consistent way.
|
|
8
|
+
|
|
9
|
+
## Root Directory
|
|
10
|
+
|
|
11
|
+
The root directory of a Nuxt application is the directory that contains the `nuxt.config.ts` file. This file is used to configure the Nuxt application.
|
|
12
|
+
|
|
13
|
+
### App Directory & Files
|
|
14
|
+
|
|
15
|
+
The following directories are related to the universal Nuxt application:
|
|
16
|
+
- [`assets/`](/docs/3.x/directory-structure/assets): website's assets that the build tool (Vite or webpack) will process
|
|
17
|
+
- [`components/`](/docs/3.x/directory-structure/components): Vue components of the application
|
|
18
|
+
- [`composables/`](/docs/3.x/directory-structure/composables): add your Vue composables
|
|
19
|
+
- [`layouts/`](/docs/3.x/directory-structure/layouts): Vue components that wrap around your pages and avoid re-rendering between pages
|
|
20
|
+
- [`middleware/`](/docs/3.x/directory-structure/middleware): run code before navigating to a particular route
|
|
21
|
+
- [`pages/`](/docs/3.x/directory-structure/pages): file-based routing to create routes within your web application
|
|
22
|
+
- [`plugins/`](/docs/3.x/directory-structure/plugins): use Vue plugins and more at the creation of your Nuxt application
|
|
23
|
+
- [`utils/`](/docs/3.x/directory-structure/utils): add functions throughout your application that can be used in your components, composables, and pages.
|
|
24
|
+
|
|
25
|
+
This directory also includes specific files:
|
|
26
|
+
- [`app.config.ts`](/docs/3.x/directory-structure/app-config): a reactive configuration within your application
|
|
27
|
+
- [`app.vue`](/docs/3.x/directory-structure/app): the root component of your Nuxt application
|
|
28
|
+
- [`error.vue`](/docs/3.x/directory-structure/error): the error page of your Nuxt application
|
|
29
|
+
|
|
30
|
+
### Server Directory
|
|
31
|
+
|
|
32
|
+
The [`server/`](/docs/3.x/directory-structure/server) directory is the directory that contains the server-side code of the Nuxt application. It contains the following subdirectories:
|
|
33
|
+
- [`api/`](/docs/3.x/directory-structure/server#server-routes): contains the API routes of the application.
|
|
34
|
+
- [`routes/`](/docs/3.x/directory-structure/server#server-routes): contains the server routes of the application (e.g. dynamic `/sitemap.xml`).
|
|
35
|
+
- [`middleware/`](/docs/3.x/directory-structure/server#server-middleware): run code before a server route is processed
|
|
36
|
+
- [`plugins/`](/docs/3.x/directory-structure/server#server-plugins): use plugins and more at the creation of the Nuxt server
|
|
37
|
+
- [`utils/`](/docs/3.x/directory-structure/server#server-utilities): add functions throughout your application that can be used in your server code.
|
|
38
|
+
|
|
39
|
+
## Public Directory
|
|
40
|
+
|
|
41
|
+
The [`public/`](/docs/3.x/directory-structure/public) directory is the directory that contains the public files of the Nuxt application. Files contained within this directory are served at the root and are not modified by the build process.
|
|
42
|
+
|
|
43
|
+
This is suitable for files that have to keep their names (e.g. `robots.txt`) _or_ likely won't change (e.g. `favicon.ico`).
|
|
44
|
+
|
|
45
|
+
## Shared Directory
|
|
46
|
+
|
|
47
|
+
The [`shared/`](/docs/3.x/directory-structure/shared) directory is the directory that contains the shared code of the Nuxt application and Nuxt server. This code can be used in both the Vue app and the Nitro server.
|
|
48
|
+
|
|
49
|
+
## Content Directory
|
|
50
|
+
|
|
51
|
+
The [`content/`](/docs/3.x/directory-structure/content) directory is enabled by the [Nuxt Content](https://content.nuxt.com) module. It is used to create a file-based CMS for your application using Markdown files.
|
|
52
|
+
|
|
53
|
+
## Modules Directory
|
|
54
|
+
|
|
55
|
+
The [`modules/`](/docs/3.x/directory-structure/modules) directory is the directory that contains the local modules of the Nuxt application. Modules are used to extend the functionality of the Nuxt application.
|
|
56
|
+
|
|
57
|
+
## Nuxt Files
|
|
58
|
+
|
|
59
|
+
- [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) file is the main configuration file for the Nuxt application.
|
|
60
|
+
- [`.nuxtrc`](/docs/3.x/directory-structure/nuxtrc) file is another syntax for configuring the Nuxt application (useful for global configurations).
|
|
61
|
+
- [`.nuxtignore`](/docs/3.x/directory-structure/nuxtignore) file is used to ignore files in the root directory during the build phase.
|
|
@@ -7,19 +7,16 @@ surround: false
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
::card-group{class="sm:grid-cols-1"}
|
|
10
|
-
::card{icon="i-lucide-
|
|
11
|
-
Learn about Nuxt directory structure and what benefits each directory or file offers.
|
|
12
|
-
::
|
|
13
|
-
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
|
|
10
|
+
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/3.x/guide/concepts"}
|
|
14
11
|
Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
|
|
15
12
|
::
|
|
16
|
-
::card{icon="i-lucide-
|
|
17
|
-
|
|
13
|
+
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/3.x/guide/best-practices"}
|
|
14
|
+
Learn about best practices when developing with Nuxt
|
|
18
15
|
::
|
|
19
|
-
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/guide/recipes"}
|
|
16
|
+
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/3.x/guide/recipes"}
|
|
20
17
|
Find solutions to common problems and learn how to implement them in your Nuxt project.
|
|
21
18
|
::
|
|
22
|
-
::card{icon="i-lucide-
|
|
23
|
-
|
|
19
|
+
::card{icon="i-lucide-star" title="Going Further" to="/docs/3.x/guide/going-further"}
|
|
20
|
+
Master Nuxt with advanced concepts like experimental features, hooks, modules, and more.
|
|
24
21
|
::
|
|
25
22
|
::
|
|
@@ -11,7 +11,7 @@ const count = ref(1) // ref is auto-imported
|
|
|
11
11
|
</script>
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Thanks to its opinionated directory structure, Nuxt can auto-import your [`components/`](/docs/3.x/
|
|
14
|
+
Thanks to its opinionated directory structure, Nuxt can auto-import your [`components/`](/docs/3.x/directory-structure/components), [`composables/`](/docs/3.x/directory-structure/composables) and [`utils/`](/docs/3.x/directory-structure/utils).
|
|
15
15
|
|
|
16
16
|
Contrary to a classic global declaration, Nuxt preserves typings, IDEs completions and hints, and **only includes what is used in your production code**.
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ In the docs, every function that is not explicitly imported is auto-imported by
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
In the [`server`](/docs/3.x/
|
|
23
|
+
In the [`server`](/docs/3.x/directory-structure/server) directory, Nuxt auto-imports exported functions and variables from `server/utils/`.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
::note
|
|
@@ -101,8 +101,8 @@ export const useMyComposable = () => {
|
|
|
101
101
|
|
|
102
102
|
Nuxt directly auto-imports files created in defined directories:
|
|
103
103
|
|
|
104
|
-
- `components/` for [Vue components](/docs/3.x/
|
|
105
|
-
- `composables/` for [Vue composables](/docs/3.x/
|
|
104
|
+
- `components/` for [Vue components](/docs/3.x/directory-structure/components).
|
|
105
|
+
- `composables/` for [Vue composables](/docs/3.x/directory-structure/composables).
|
|
106
106
|
- `utils/` for helper functions and other utilities.
|
|
107
107
|
|
|
108
108
|
:link-example{to="/docs/examples/features/auto-imports"}
|
|
@@ -40,7 +40,7 @@ The Vue and Nuxt instances are created first. Afterward, Nuxt executes its serve
|
|
|
40
40
|
- Built-in plugins, such as Vue Router and `unhead`.
|
|
41
41
|
- Custom plugins located in the `plugins/` directory, including those without a suffix (e.g., `myPlugin.ts`) and those with the `.server` suffix (e.g., `myServerPlugin.server.ts`).
|
|
42
42
|
|
|
43
|
-
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/3.x/
|
|
43
|
+
Plugins execute in a specific order and may have dependencies on one another. For more details, including execution order and parallelism, refer to the [Plugins documentation](/docs/3.x/directory-structure/plugins).
|
|
44
44
|
|
|
45
45
|
::callout{icon="i-lucide-lightbulb"}
|
|
46
46
|
After this step, Nuxt calls the [`app:created`](/docs/3.x/api/advanced/hooks#app-hooks-runtime) hook, which can be used to execute additional logic.
|
|
@@ -70,7 +70,7 @@ In Nuxt, there are three types of middleware:
|
|
|
70
70
|
|
|
71
71
|
Nuxt executes all global middleware on the initial page load (both on server and client) and then again before any client-side navigation. Named and anonymous middleware are executed only on the routes specified in the middleware property of the page(route) meta defined in the corresponding page components.
|
|
72
72
|
|
|
73
|
-
For details about each type and examples, see the [Middleware documentation](/docs/3.x/
|
|
73
|
+
For details about each type and examples, see the [Middleware documentation](/docs/3.x/directory-structure/middleware).
|
|
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
|
|
|
@@ -134,7 +134,7 @@ Nuxt middleware runs on both the server and the client. If you want certain code
|
|
|
134
134
|
|
|
135
135
|
### Step 4: Mount Vue Application and Hydration
|
|
136
136
|
|
|
137
|
-
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/3.x/
|
|
137
|
+
Calling `app.mount('#__nuxt')` mounts the Vue application to the DOM. If the application uses SSR or SSG mode, Vue performs a hydration step to make the client-side application interactive. During hydration, Vue recreates the application (excluding [Server Components](/docs/3.x/directory-structure/components#server-components)), matches each component to its corresponding DOM nodes, and attaches DOM event listeners.
|
|
138
138
|
|
|
139
139
|
To ensure proper hydration, it's important to maintain consistency between the data on the server and the client. For API requests, it is recommended to use `useAsyncData`, `useFetch`, or other SSR-friendly composables. These methods ensure that the data fetched on the server side is reused during hydration, avoiding repeated requests. Any new requests should only be triggered after hydration, preventing hydration errors.
|
|
140
140
|
|
|
@@ -25,13 +25,13 @@ We chose to build Nuxt on top of Vue for these reasons:
|
|
|
25
25
|
|
|
26
26
|
### Auto-imports
|
|
27
27
|
|
|
28
|
-
Every Vue component created in the [`components/`](/docs/3.x/
|
|
28
|
+
Every Vue component created in the [`components/`](/docs/3.x/directory-structure/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
30
|
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
31
31
|
|
|
32
32
|
### Vue Router
|
|
33
33
|
|
|
34
|
-
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses a [`pages/`](/docs/3.x/
|
|
34
|
+
Most applications need multiple pages and a way to navigate between them. This is called **routing**. Nuxt uses a [`pages/`](/docs/3.x/directory-structure/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
36
|
:read-more{to="/docs/getting-started/routing"}
|
|
37
37
|
|
|
@@ -92,7 +92,7 @@ const increment = () => count.value++
|
|
|
92
92
|
The goal of Nuxt is to provide a great developer experience around the Composition API.
|
|
93
93
|
|
|
94
94
|
- Use auto-imported [Reactivity functions](https://vuejs.org/api/reactivity-core.html) from Vue and Nuxt [built-in composables](/docs/3.x/api/composables/use-async-data).
|
|
95
|
-
- Write your own auto-imported reusable functions in the [`composables/` directory](/docs/3.x/
|
|
95
|
+
- Write your own auto-imported reusable functions in the [`composables/` directory](/docs/3.x/directory-structure/composables).
|
|
96
96
|
|
|
97
97
|
### TypeScript Support
|
|
98
98
|
|
|
@@ -44,7 +44,7 @@ const handleClick = () => {
|
|
|
44
44
|
|
|
45
45
|
On the initial request, the `counter` ref is initialized in the server since it is rendered inside the `<p>` tag. The contents of `handleClick` is never executed here. During hydration in the browser, the `counter` ref is re-initialized. The `handleClick` finally binds itself to the button; Therefore it is reasonable to deduce that the body of `handleClick` will always run in a browser environment.
|
|
46
46
|
|
|
47
|
-
[Middlewares](/docs/3.x/
|
|
47
|
+
[Middlewares](/docs/3.x/directory-structure/middleware) and [pages](/docs/3.x/directory-structure/pages) run in the server and on the client during hydration. [Plugins](/docs/3.x/directory-structure/plugins) can be rendered on the server or client or both. [Components](/docs/3.x/directory-structure/components) can be forced to run on the client only as well. [Composables](/docs/3.x/directory-structure/composables) and [utilities](/docs/3.x/directory-structure/utils) are rendered based on the context of their usage.
|
|
48
48
|
|
|
49
49
|
**Benefits of server-side rendering:**
|
|
50
50
|
- **Performance**: Users can get immediate access to the page's content because browsers can display static content much faster than JavaScript-generated content. At the same time, Nuxt preserves the interactivity of a web application during the hydration process.
|
|
@@ -16,7 +16,7 @@ It is shipped with many features:
|
|
|
16
16
|
|
|
17
17
|
## API Layer
|
|
18
18
|
|
|
19
|
-
Server [API endpoints](/docs/3.x/
|
|
19
|
+
Server [API endpoints](/docs/3.x/directory-structure/server#api-routes) and [Middleware](/docs/3.x/directory-structure/server#server-middleware) are added by Nitro that internally uses [h3](https://github.com/h3js/h3).
|
|
20
20
|
|
|
21
21
|
Key features include:
|
|
22
22
|
|
|
@@ -53,7 +53,7 @@ Nitro produces a standalone server dist that is independent of `node_modules`.
|
|
|
53
53
|
|
|
54
54
|
The server in Nuxt 2 is not standalone and requires part of Nuxt core to be involved by running `nuxt start` (with the [`nuxt-start`](https://www.npmjs.com/package/nuxt-start) or [`nuxt`](https://www.npmjs.com/package/nuxt) distributions) or custom programmatic usage, which is fragile and prone to breakage and not suitable for serverless and service worker environments.
|
|
55
55
|
|
|
56
|
-
Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/3.x/
|
|
56
|
+
Nuxt generates this dist when running `nuxt build` into a [`.output`](/docs/3.x/directory-structure/output) directory.
|
|
57
57
|
|
|
58
58
|
The output contains runtime code to run your Nuxt server in any environment (including experimental browser service workers!) and serve your static files, making it a true hybrid framework for the JAMstack. In addition, Nuxt implements a native storage layer, supporting multi-source drivers and local assets.
|
|
59
59
|
|
|
@@ -17,7 +17,7 @@ Explore Nuxt Modules
|
|
|
17
17
|
|
|
18
18
|
## Add Nuxt Modules
|
|
19
19
|
|
|
20
|
-
Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/3.x/
|
|
20
|
+
Once you have installed the modules you can add them to your [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) file under the `modules` property. Module developers usually provide additional steps and details for usage.
|
|
21
21
|
|
|
22
22
|
```ts twoslash [nuxt.config.ts]
|
|
23
23
|
export default defineNuxtConfig({
|
|
@@ -63,14 +63,14 @@ This file contains the recommended basic TypeScript configuration for your proje
|
|
|
63
63
|
Consider using the `imports` section of [nuxt.config](/docs/3.x/api/nuxt-config#imports) to include directories beyond the default ones. This can be useful for auto-importing types which you're using across your app.
|
|
64
64
|
::
|
|
65
65
|
|
|
66
|
-
[Read more about how to extend this configuration](/docs/3.x/
|
|
66
|
+
[Read more about how to extend this configuration](/docs/3.x/directory-structure/tsconfig).
|
|
67
67
|
|
|
68
68
|
::tip{icon="i-lucide-video" to="https://youtu.be/umLI7SlPygY" target="_blank"}
|
|
69
69
|
Watch a video from Daniel Roe explaining built-in Nuxt aliases.
|
|
70
70
|
::
|
|
71
71
|
|
|
72
72
|
::note
|
|
73
|
-
Nitro also [auto-generates types](/docs/3.x/guide/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/3.x/
|
|
73
|
+
Nitro also [auto-generates types](/docs/3.x/guide/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/3.x/directory-structure/composables), plus other core functionality.
|
|
74
74
|
::
|
|
75
75
|
|
|
76
76
|
::note
|
|
@@ -5,7 +5,7 @@ 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 [pages directory](/docs/3.x/
|
|
8
|
+
In Nuxt, your routing is defined by the structure of your files inside the [pages directory](/docs/3.x/directory-structure/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
|
|
|
@@ -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/3.x/
|
|
31
|
+
Next, we need to import and add it to our [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config) file:
|
|
32
32
|
|
|
33
33
|
```ts [nuxt.config.ts]
|
|
34
34
|
import yaml from '@rollup/plugin-yaml'
|
|
@@ -12,7 +12,7 @@ However, Nuxt provides a way to create a custom fetcher for your API (or multipl
|
|
|
12
12
|
|
|
13
13
|
## Custom `$fetch`
|
|
14
14
|
|
|
15
|
-
Let's create a custom `$fetch` instance with a [Nuxt plugin](/docs/3.x/
|
|
15
|
+
Let's create a custom `$fetch` instance with a [Nuxt plugin](/docs/3.x/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).
|
|
@@ -113,7 +113,7 @@ This feature is only recommended for **static builds** with payload extraction,
|
|
|
113
113
|
|
|
114
114
|
Emits `app:chunkError` hook when there is an error loading vite/webpack chunks. Default behavior is to perform a reload of the new route on navigation to a new route when a chunk fails to load.
|
|
115
115
|
|
|
116
|
-
If you set this to `'automatic-immediate'` Nuxt will reload the current route immediately, instead of waiting for a navigation. This is useful for chunk errors that are not triggered by navigation, e.g., when your Nuxt app fails to load a [lazy component](/docs/3.x/
|
|
116
|
+
If you set this to `'automatic-immediate'` Nuxt will reload the current route immediately, instead of waiting for a navigation. This is useful for chunk errors that are not triggered by navigation, e.g., when your Nuxt app fails to load a [lazy component](/docs/3.x/directory-structure/components#dynamic-imports). A potential downside of this behavior is undesired reloads, e.g., when your app does not need the chunk that caused the error.
|
|
117
117
|
|
|
118
118
|
You can disable automatic handling by setting this to `false`, or handle chunk errors manually by setting it to `manual`.
|
|
119
119
|
|
|
@@ -513,7 +513,7 @@ export default defineNuxtConfig({
|
|
|
513
513
|
})
|
|
514
514
|
```
|
|
515
515
|
|
|
516
|
-
This allows modules to access additional metadata from the page metadata in the build context. If you are using this within a module, it's recommended also to [augment the `NuxtPage` types with your keys](/docs/3.x/
|
|
516
|
+
This allows modules to access additional metadata from the page metadata in the build context. If you are using this within a module, it's recommended also to [augment the `NuxtPage` types with your keys](/docs/3.x/directory-structure/pages#typing-custom-metadata).
|
|
517
517
|
|
|
518
518
|
## normalizeComponentNames
|
|
519
519
|
|
|
@@ -30,7 +30,7 @@ Global usage is possible for the browser but not on the server, to avoid sharing
|
|
|
30
30
|
|
|
31
31
|
Since [`useNuxtApp`](/docs/3.x/api/composables/use-nuxt-app) throws an exception if context is currently unavailable, if your composable does not always require `nuxtApp`, you can use [`tryUseNuxtApp`](/docs/3.x/api/composables/use-nuxt-app#tryusenuxtapp) instead, which will return `null` instead of throwing an exception.
|
|
32
32
|
|
|
33
|
-
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/3.x/
|
|
33
|
+
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins](/docs/3.x/directory-structure/plugins).
|
|
34
34
|
|
|
35
35
|
Check [Nuxt App](/docs/3.x/api/composables/use-nuxt-app) for more information about this interface.
|
|
36
36
|
|
|
@@ -76,6 +76,6 @@ Nuxt builds and bundles project using Node.js but also has a runtime side.
|
|
|
76
76
|
|
|
77
77
|
While both areas can be extended, that runtime context is isolated from build-time. Therefore, they are not supposed to share state, code, or context other than runtime configuration!
|
|
78
78
|
|
|
79
|
-
`nuxt.config` and [Nuxt Modules](/docs/3.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/3.x/
|
|
79
|
+
`nuxt.config` and [Nuxt Modules](/docs/3.x/guide/going-further/modules) can be used to extend the build context, and [Nuxt Plugins](/docs/3.x/directory-structure/plugins) can be used to extend runtime.
|
|
80
80
|
|
|
81
81
|
When building an application for production, `nuxt build` will generate a standalone build in the `.output` directory, independent of `nuxt.config` and [Nuxt modules](/docs/3.x/guide/going-further/modules).
|
|
@@ -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/3.x/
|
|
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/3.x/directory-structure/nuxt-config) file, using the [`runtimeConfig`](/docs/3.x/api/nuxt-config#runtimeconfig) option.
|
|
9
9
|
|
|
10
10
|
```ts [nuxt.config.ts]
|
|
11
11
|
export default defineNuxtConfig({
|
|
@@ -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/3.x/
|
|
42
|
+
App hooks can be mainly used by [Nuxt Plugins](/docs/3.x/directory-structure/plugins) to hook into rendering lifecycle but could also be used in Vue composables.
|
|
43
43
|
|
|
44
44
|
```ts [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/3.x/
|
|
58
|
+
These hooks are available for [server plugins](/docs/3.x/directory-structure/server#server-plugins) to hook into Nitro's runtime behavior.
|
|
59
59
|
|
|
60
60
|
```ts [~/server/plugins/test.ts]
|
|
61
61
|
export default defineNitroPlugin((nitroApp) => {
|
|
@@ -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/3.x/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/3.x/
|
|
120
|
+
- "local" modules, they exist within a Nuxt project itself, either [inlined in Nuxt config](/docs/3.x/api/nuxt-config#modules) or as part of [the `modules` directory](/docs/3.x/directory-structure/modules).
|
|
121
121
|
|
|
122
122
|
In either case, their anatomy is similar.
|
|
123
123
|
|
|
@@ -224,7 +224,7 @@ 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/3.x/
|
|
227
|
+
- [Nuxt plugins](/docs/3.x/directory-structure/plugins)
|
|
228
228
|
|
|
229
229
|
To the [server engine](/docs/3.x/guide/concepts/server-engine), Nitro:
|
|
230
230
|
- API routes
|
|
@@ -23,7 +23,7 @@ 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/3.x/
|
|
26
|
+
Currently, the Nuxt context is only accessible in [plugins](/docs/3.x/directory-structure/plugins), [Nuxt hooks](/docs/3.x/guide/going-further/hooks), [Nuxt middleware](/docs/3.x/directory-structure/middleware) (if wrapped in `defineNuxtRouteMiddleware`), and [setup functions](https://vuejs.org/api/composition-api-setup.html) (in pages and components).
|
|
27
27
|
|
|
28
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/3.x/api/composables/use-nuxt-app#runwithcontext).
|
|
29
29
|
|
|
@@ -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/3.x/
|
|
10
|
+
A minimal Nuxt layer directory should contain a [`nuxt.config.ts`](/docs/3.x/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
|
-
- [`components/*`](/docs/3.x/
|
|
19
|
-
- [`composables/*`](/docs/3.x/
|
|
20
|
-
- [`layouts/*`](/docs/3.x/
|
|
21
|
-
- [`middleware/*`](/docs/3.x/
|
|
22
|
-
- [`pages/*`](/docs/3.x/
|
|
23
|
-
- [`plugins/*`](/docs/3.x/
|
|
24
|
-
- [`server/*`](/docs/3.x/
|
|
25
|
-
- [`utils/*`](/docs/3.x/
|
|
26
|
-
- [`nuxt.config.ts`](/docs/3.x/
|
|
27
|
-
- [`app.config.ts`](/docs/3.x/
|
|
18
|
+
- [`components/*`](/docs/3.x/directory-structure/components) - Extend the default components
|
|
19
|
+
- [`composables/*`](/docs/3.x/directory-structure/composables) - Extend the default composables
|
|
20
|
+
- [`layouts/*`](/docs/3.x/directory-structure/layouts) - Extend the default layouts
|
|
21
|
+
- [`middleware/*`](/docs/3.x/directory-structure/middleware) - Extend the default middleware
|
|
22
|
+
- [`pages/*`](/docs/3.x/directory-structure/pages) - Extend the default pages
|
|
23
|
+
- [`plugins/*`](/docs/3.x/directory-structure/plugins) - Extend the default plugins
|
|
24
|
+
- [`server/*`](/docs/3.x/directory-structure/server) - Extend the default server endpoints & middleware
|
|
25
|
+
- [`utils/*`](/docs/3.x/directory-structure/utils) - Extend the default utils
|
|
26
|
+
- [`nuxt.config.ts`](/docs/3.x/directory-structure/nuxt-config)- Extend the default nuxt config
|
|
27
|
+
- [`app.config.ts`](/docs/3.x/directory-structure/app-config) - Extend the default app config
|
|
28
28
|
|
|
29
29
|
## Basic Example
|
|
30
30
|
|
|
@@ -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/3.x/
|
|
19
|
+
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/3.x/directory-structure/app) or [`layouts/`](/docs/3.x/directory-structure/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.vue]
|
|
22
22
|
<template>
|
|
@@ -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 [`pages/`](/docs/3.x/
|
|
11
|
+
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`pages/`](/docs/3.x/directory-structure/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.
|
|
@@ -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 [`layouts/`](/docs/3.x/
|
|
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 [`layouts/`](/docs/3.x/directory-structure/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 [`layouts/`](/docs/3.x/
|
|
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 [`layouts/`](/docs/3.x/directory-structure/layouts) directory.
|
|
59
59
|
- **type**: `string`
|
|
60
60
|
- **default**: `null`
|
|
61
61
|
|
|
@@ -10,7 +10,7 @@ links:
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/3.x/
|
|
13
|
+
Add `<NuxtLoadingIndicator/>` in your [`app.vue`](/docs/3.x/directory-structure/app) or [`layouts/`](/docs/3.x/directory-structure/layouts).
|
|
14
14
|
|
|
15
15
|
```vue [app.vue]
|
|
16
16
|
<template>
|
|
@@ -30,7 +30,7 @@ By default, the shared runtime context of Nuxt is namespaced under the [`buildId
|
|
|
30
30
|
|
|
31
31
|
### `provide (name, value)`
|
|
32
32
|
|
|
33
|
-
`nuxtApp` is a runtime context that you can extend using [Nuxt plugins](/docs/3.x/
|
|
33
|
+
`nuxtApp` is a runtime context that you can extend using [Nuxt plugins](/docs/3.x/directory-structure/plugins). Use the `provide` function to create Nuxt plugins to make values and helper methods available in your Nuxt application across all composables and components.
|
|
34
34
|
|
|
35
35
|
`provide` function accepts `name` and `value` parameters.
|
|
36
36
|
|
|
@@ -46,7 +46,7 @@ As you can see in the example above, `$hello` has become the new and custom part
|
|
|
46
46
|
|
|
47
47
|
### `hook(name, cb)`
|
|
48
48
|
|
|
49
|
-
Hooks available in `nuxtApp` allows you to customize the runtime aspects of your Nuxt application. You can use runtime hooks in Vue.js composables and [Nuxt plugins](/docs/3.x/
|
|
49
|
+
Hooks available in `nuxtApp` allows you to customize the runtime aspects of your Nuxt application. You can use runtime hooks in Vue.js composables and [Nuxt plugins](/docs/3.x/directory-structure/plugins) to hook into the rendering lifecycle.
|
|
50
50
|
|
|
51
51
|
`hook` function is useful for adding custom logic by hooking into the rendering lifecycle at a specific point. `hook` function is mostly used when creating Nuxt plugins.
|
|
52
52
|
|
|
@@ -84,8 +84,8 @@ await nuxtApp.callHook('my-plugin:init')
|
|
|
84
84
|
|
|
85
85
|
Some useful methods:
|
|
86
86
|
- [`component()`](https://vuejs.org/api/application.html#app-component) - Registers a global component if passing both a name string and a component definition, or retrieves an already registered one if only the name is passed.
|
|
87
|
-
- [`directive()`](https://vuejs.org/api/application.html#app-directive) - Registers a global custom directive if passing both a name string and a directive definition, or retrieves an already registered one if only the name is passed[(example)](/docs/3.x/
|
|
88
|
-
- [`use()`](https://vuejs.org/api/application.html#app-use) - Installs a **[Vue.js Plugin](https://vuejs.org/guide/reusability/plugins.html)** [(example)](/docs/3.x/
|
|
87
|
+
- [`directive()`](https://vuejs.org/api/application.html#app-directive) - Registers a global custom directive if passing both a name string and a directive definition, or retrieves an already registered one if only the name is passed[(example)](/docs/3.x/directory-structure/plugins#vue-directives).
|
|
88
|
+
- [`use()`](https://vuejs.org/api/application.html#app-use) - Installs a **[Vue.js Plugin](https://vuejs.org/guide/reusability/plugins.html)** [(example)](/docs/3.x/directory-structure/plugins#vue-plugins).
|
|
89
89
|
|
|
90
90
|
:read-more{icon="i-simple-icons-vuedotjs" to="https://vuejs.org/api/application.html#application-api"}
|
|
91
91
|
|
|
@@ -37,7 +37,7 @@ header.value = 'my-value'
|
|
|
37
37
|
</template>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/3.x/
|
|
40
|
+
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/3.x/directory-structure/middleware) to set a response header for all pages.
|
|
41
41
|
|
|
42
42
|
```ts [middleware/my-header-middleware.ts]
|
|
43
43
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
@@ -76,7 +76,7 @@ The `useRoute()` composable should only be used in the setup function of a Vue c
|
|
|
76
76
|
This applies to any composable that uses `useRoute()` internally too.
|
|
77
77
|
::
|
|
78
78
|
|
|
79
|
-
::read-more{to="/docs/3.x/
|
|
79
|
+
::read-more{to="/docs/3.x/directory-structure/app/middleware"}
|
|
80
80
|
Read more about accessing the route in the middleware section.
|
|
81
81
|
::
|
|
82
82
|
|
|
@@ -49,7 +49,7 @@ router.resolve({ name: 'home' })
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
::note
|
|
52
|
-
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/3.x/
|
|
52
|
+
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/3.x/directory-structure/plugins) while `router.push()` on the other hand, triggers a new navigation immediately and it is useful in pages, Vue components and composable.
|
|
53
53
|
::
|
|
54
54
|
|
|
55
55
|
## Based on History API
|
|
@@ -11,7 +11,7 @@ links:
|
|
|
11
11
|
Nuxt uses [ofetch](https://github.com/unjs/ofetch) to expose globally the `$fetch` helper for making HTTP requests within your Vue app or API routes.
|
|
12
12
|
|
|
13
13
|
::tip{icon="i-lucide-rocket"}
|
|
14
|
-
During server-side rendering, calling `$fetch` to fetch your internal [API routes](/docs/3.x/
|
|
14
|
+
During server-side rendering, calling `$fetch` to fetch your internal [API routes](/docs/3.x/directory-structure/server) will directly call the relevant function (emulating the request), **saving an additional API call**.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
17
|
::note{color="blue" icon="i-lucide-info"}
|
|
@@ -9,7 +9,7 @@ links:
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
::warning
|
|
12
|
-
`abortNavigation` is only usable inside a [route middleware handler](/docs/3.x/
|
|
12
|
+
`abortNavigation` is only usable inside a [route middleware handler](/docs/3.x/directory-structure/middleware).
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
## Type
|