@nuxt/docs 0.0.0 → 3.17.1

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.
Files changed (224) hide show
  1. package/.navigation.yml +2 -0
  2. package/1.getting-started/.navigation.yml +3 -0
  3. package/1.getting-started/01.introduction.md +81 -0
  4. package/1.getting-started/02.installation.md +109 -0
  5. package/1.getting-started/03.configuration.md +226 -0
  6. package/1.getting-started/04.views.md +163 -0
  7. package/1.getting-started/05.assets.md +48 -0
  8. package/1.getting-started/06.styling.md +565 -0
  9. package/1.getting-started/07.routing.md +149 -0
  10. package/1.getting-started/08.seo-meta.md +360 -0
  11. package/1.getting-started/09.transitions.md +473 -0
  12. package/1.getting-started/10.data-fetching.md +795 -0
  13. package/1.getting-started/11.state-management.md +223 -0
  14. package/1.getting-started/12.error-handling.md +233 -0
  15. package/1.getting-started/13.server.md +94 -0
  16. package/1.getting-started/14.layers.md +92 -0
  17. package/1.getting-started/15.prerendering.md +194 -0
  18. package/1.getting-started/16.deployment.md +130 -0
  19. package/1.getting-started/17.testing.md +728 -0
  20. package/1.getting-started/18.upgrade.md +997 -0
  21. package/2.guide/.navigation.yml +2 -0
  22. package/2.guide/0.index.md +22 -0
  23. package/2.guide/1.concepts/.navigation.yml +3 -0
  24. package/2.guide/1.concepts/1.auto-imports.md +205 -0
  25. package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
  26. package/2.guide/1.concepts/2.vuejs-development.md +103 -0
  27. package/2.guide/1.concepts/3.rendering.md +255 -0
  28. package/2.guide/1.concepts/4.server-engine.md +62 -0
  29. package/2.guide/1.concepts/5.modules.md +48 -0
  30. package/2.guide/1.concepts/7.esm.md +299 -0
  31. package/2.guide/1.concepts/8.typescript.md +97 -0
  32. package/2.guide/1.concepts/9.code-style.md +22 -0
  33. package/2.guide/2.directory-structure/.navigation.yml +3 -0
  34. package/2.guide/2.directory-structure/0.nuxt.md +20 -0
  35. package/2.guide/2.directory-structure/0.output.md +18 -0
  36. package/2.guide/2.directory-structure/1.assets.md +16 -0
  37. package/2.guide/2.directory-structure/1.components.md +608 -0
  38. package/2.guide/2.directory-structure/1.composables.md +121 -0
  39. package/2.guide/2.directory-structure/1.content.md +64 -0
  40. package/2.guide/2.directory-structure/1.layouts.md +180 -0
  41. package/2.guide/2.directory-structure/1.middleware.md +209 -0
  42. package/2.guide/2.directory-structure/1.modules.md +66 -0
  43. package/2.guide/2.directory-structure/1.node_modules.md +12 -0
  44. package/2.guide/2.directory-structure/1.pages.md +440 -0
  45. package/2.guide/2.directory-structure/1.plugins.md +299 -0
  46. package/2.guide/2.directory-structure/1.public.md +27 -0
  47. package/2.guide/2.directory-structure/1.server.md +546 -0
  48. package/2.guide/2.directory-structure/1.shared.md +104 -0
  49. package/2.guide/2.directory-structure/1.utils.md +49 -0
  50. package/2.guide/2.directory-structure/2.env.md +75 -0
  51. package/2.guide/2.directory-structure/2.gitignore.md +37 -0
  52. package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
  53. package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
  54. package/2.guide/2.directory-structure/3.app-config.md +177 -0
  55. package/2.guide/2.directory-structure/3.app.md +72 -0
  56. package/2.guide/2.directory-structure/3.error.md +55 -0
  57. package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
  58. package/2.guide/2.directory-structure/3.package.md +32 -0
  59. package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
  60. package/2.guide/3.going-further/.navigation.yml +3 -0
  61. package/2.guide/3.going-further/1.experimental-features.md +689 -0
  62. package/2.guide/3.going-further/1.features.md +103 -0
  63. package/2.guide/3.going-further/1.internals.md +81 -0
  64. package/2.guide/3.going-further/10.runtime-config.md +174 -0
  65. package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
  66. package/2.guide/3.going-further/2.hooks.md +98 -0
  67. package/2.guide/3.going-further/3.modules.md +811 -0
  68. package/2.guide/3.going-further/4.kit.md +51 -0
  69. package/2.guide/3.going-further/6.nuxt-app.md +64 -0
  70. package/2.guide/3.going-further/7.layers.md +227 -0
  71. package/2.guide/3.going-further/9.debugging.md +115 -0
  72. package/2.guide/3.going-further/index.md +4 -0
  73. package/2.guide/4.recipes/.navigation.yml +3 -0
  74. package/2.guide/4.recipes/1.custom-routing.md +181 -0
  75. package/2.guide/4.recipes/2.vite-plugin.md +65 -0
  76. package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
  77. package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
  78. package/3.api/.navigation.yml +3 -0
  79. package/3.api/1.components/.navigation.yml +3 -0
  80. package/3.api/1.components/1.client-only.md +76 -0
  81. package/3.api/1.components/1.dev-only.md +51 -0
  82. package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
  83. package/3.api/1.components/10.nuxt-picture.md +27 -0
  84. package/3.api/1.components/11.teleports.md +40 -0
  85. package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
  86. package/3.api/1.components/13.nuxt-time.md +173 -0
  87. package/3.api/1.components/2.nuxt-page.md +154 -0
  88. package/3.api/1.components/3.nuxt-layout.md +156 -0
  89. package/3.api/1.components/4.nuxt-link.md +322 -0
  90. package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
  91. package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
  92. package/3.api/1.components/7.nuxt-welcome.md +25 -0
  93. package/3.api/1.components/8.nuxt-island.md +70 -0
  94. package/3.api/1.components/9.nuxt-img.md +43 -0
  95. package/3.api/2.composables/.navigation.yml +3 -0
  96. package/3.api/2.composables/on-prehydrate.md +60 -0
  97. package/3.api/2.composables/use-app-config.md +19 -0
  98. package/3.api/2.composables/use-async-data.md +212 -0
  99. package/3.api/2.composables/use-cookie.md +233 -0
  100. package/3.api/2.composables/use-error.md +32 -0
  101. package/3.api/2.composables/use-fetch.md +217 -0
  102. package/3.api/2.composables/use-head-safe.md +55 -0
  103. package/3.api/2.composables/use-head.md +69 -0
  104. package/3.api/2.composables/use-hydration.md +68 -0
  105. package/3.api/2.composables/use-lazy-async-data.md +47 -0
  106. package/3.api/2.composables/use-lazy-fetch.md +55 -0
  107. package/3.api/2.composables/use-loading-indicator.md +77 -0
  108. package/3.api/2.composables/use-nuxt-app.md +294 -0
  109. package/3.api/2.composables/use-nuxt-data.md +112 -0
  110. package/3.api/2.composables/use-preview-mode.md +118 -0
  111. package/3.api/2.composables/use-request-event.md +23 -0
  112. package/3.api/2.composables/use-request-fetch.md +52 -0
  113. package/3.api/2.composables/use-request-header.md +34 -0
  114. package/3.api/2.composables/use-request-headers.md +37 -0
  115. package/3.api/2.composables/use-request-url.md +41 -0
  116. package/3.api/2.composables/use-response-header.md +48 -0
  117. package/3.api/2.composables/use-route-announcer.md +60 -0
  118. package/3.api/2.composables/use-route.md +52 -0
  119. package/3.api/2.composables/use-router.md +92 -0
  120. package/3.api/2.composables/use-runtime-config.md +142 -0
  121. package/3.api/2.composables/use-runtime-hook.md +43 -0
  122. package/3.api/2.composables/use-seo-meta.md +80 -0
  123. package/3.api/2.composables/use-server-seo-meta.md +27 -0
  124. package/3.api/2.composables/use-state.md +48 -0
  125. package/3.api/3.utils/$fetch.md +98 -0
  126. package/3.api/3.utils/.navigation.yml +3 -0
  127. package/3.api/3.utils/abort-navigation.md +73 -0
  128. package/3.api/3.utils/add-route-middleware.md +88 -0
  129. package/3.api/3.utils/call-once.md +92 -0
  130. package/3.api/3.utils/clear-error.md +29 -0
  131. package/3.api/3.utils/clear-nuxt-data.md +23 -0
  132. package/3.api/3.utils/clear-nuxt-state.md +23 -0
  133. package/3.api/3.utils/create-error.md +55 -0
  134. package/3.api/3.utils/define-nuxt-component.md +53 -0
  135. package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
  136. package/3.api/3.utils/define-page-meta.md +234 -0
  137. package/3.api/3.utils/define-route-rules.md +52 -0
  138. package/3.api/3.utils/navigate-to.md +230 -0
  139. package/3.api/3.utils/on-before-route-leave.md +11 -0
  140. package/3.api/3.utils/on-before-route-update.md +11 -0
  141. package/3.api/3.utils/on-nuxt-ready.md +25 -0
  142. package/3.api/3.utils/prefetch-components.md +28 -0
  143. package/3.api/3.utils/preload-components.md +23 -0
  144. package/3.api/3.utils/preload-route-components.md +41 -0
  145. package/3.api/3.utils/prerender-routes.md +46 -0
  146. package/3.api/3.utils/refresh-cookie.md +46 -0
  147. package/3.api/3.utils/refresh-nuxt-data.md +91 -0
  148. package/3.api/3.utils/reload-nuxt-app.md +74 -0
  149. package/3.api/3.utils/set-page-layout.md +24 -0
  150. package/3.api/3.utils/set-response-status.md +36 -0
  151. package/3.api/3.utils/show-error.md +31 -0
  152. package/3.api/3.utils/update-app-config.md +27 -0
  153. package/3.api/4.commands/.navigation.yml +3 -0
  154. package/3.api/4.commands/add.md +112 -0
  155. package/3.api/4.commands/analyze.md +41 -0
  156. package/3.api/4.commands/build-module.md +42 -0
  157. package/3.api/4.commands/build.md +46 -0
  158. package/3.api/4.commands/cleanup.md +38 -0
  159. package/3.api/4.commands/dev.md +59 -0
  160. package/3.api/4.commands/devtools.md +38 -0
  161. package/3.api/4.commands/generate.md +41 -0
  162. package/3.api/4.commands/info.md +33 -0
  163. package/3.api/4.commands/init.md +46 -0
  164. package/3.api/4.commands/module.md +84 -0
  165. package/3.api/4.commands/prepare.md +36 -0
  166. package/3.api/4.commands/preview.md +43 -0
  167. package/3.api/4.commands/typecheck.md +42 -0
  168. package/3.api/4.commands/upgrade.md +37 -0
  169. package/3.api/5.kit/.navigation.yml +3 -0
  170. package/3.api/5.kit/1.modules.md +172 -0
  171. package/3.api/5.kit/10.runtime-config.md +27 -0
  172. package/3.api/5.kit/10.templates.md +283 -0
  173. package/3.api/5.kit/11.nitro.md +409 -0
  174. package/3.api/5.kit/12.resolving.md +268 -0
  175. package/3.api/5.kit/13.logging.md +65 -0
  176. package/3.api/5.kit/14.builder.md +491 -0
  177. package/3.api/5.kit/15.examples.md +41 -0
  178. package/3.api/5.kit/2.programmatic.md +125 -0
  179. package/3.api/5.kit/3.compatibility.md +230 -0
  180. package/3.api/5.kit/4.autoimports.md +144 -0
  181. package/3.api/5.kit/5.components.md +127 -0
  182. package/3.api/5.kit/6.context.md +130 -0
  183. package/3.api/5.kit/7.pages.md +295 -0
  184. package/3.api/5.kit/8.layout.md +80 -0
  185. package/3.api/5.kit/9.plugins.md +263 -0
  186. package/3.api/6.advanced/.navigation.yml +1 -0
  187. package/3.api/6.advanced/1.hooks.md +105 -0
  188. package/3.api/6.advanced/2.import-meta.md +60 -0
  189. package/3.api/6.nuxt-config.md +12 -0
  190. package/3.api/index.md +31 -0
  191. package/5.community/.navigation.yml +3 -0
  192. package/5.community/2.getting-help.md +48 -0
  193. package/5.community/3.reporting-bugs.md +50 -0
  194. package/5.community/4.contribution.md +205 -0
  195. package/5.community/5.framework-contribution.md +142 -0
  196. package/5.community/6.roadmap.md +79 -0
  197. package/5.community/7.changelog.md +92 -0
  198. package/6.bridge/.navigation.yml +3 -0
  199. package/6.bridge/1.overview.md +137 -0
  200. package/6.bridge/10.configuration.md +96 -0
  201. package/6.bridge/2.typescript.md +46 -0
  202. package/6.bridge/3.bridge-composition-api.md +132 -0
  203. package/6.bridge/4.plugins-and-middleware.md +65 -0
  204. package/6.bridge/5.nuxt3-compatible-api.md +204 -0
  205. package/6.bridge/6.meta.md +117 -0
  206. package/6.bridge/7.runtime-config.md +38 -0
  207. package/6.bridge/8.nitro.md +102 -0
  208. package/6.bridge/9.vite.md +37 -0
  209. package/7.migration/.navigation.yml +3 -0
  210. package/7.migration/1.overview.md +24 -0
  211. package/7.migration/10.bundling.md +28 -0
  212. package/7.migration/11.server.md +17 -0
  213. package/7.migration/2.configuration.md +240 -0
  214. package/7.migration/20.module-authors.md +94 -0
  215. package/7.migration/3.auto-imports.md +18 -0
  216. package/7.migration/4.meta.md +127 -0
  217. package/7.migration/5.plugins-and-middleware.md +80 -0
  218. package/7.migration/6.pages-and-layouts.md +233 -0
  219. package/7.migration/7.component-options.md +156 -0
  220. package/7.migration/8.runtime-config.md +58 -0
  221. package/LICENSE +21 -0
  222. package/README.md +11 -0
  223. package/package.json +16 -4
  224. package/dist/.gitkeep +0 -0
@@ -0,0 +1,234 @@
1
+ ---
2
+ title: 'definePageMeta'
3
+ description: 'Define metadata for your page components.'
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/pages/runtime/composables.ts
8
+ size: xs
9
+ ---
10
+
11
+ `definePageMeta` is a compiler macro that you can use to set metadata for your **page** components located in the [`pages/`](/docs/guide/directory-structure/pages) directory (unless [set otherwise](/docs/api/nuxt-config#pages)). This way you can set custom metadata for each static or dynamic route of your Nuxt application.
12
+
13
+ ```vue [pages/some-page.vue]
14
+ <script setup lang="ts">
15
+ definePageMeta({
16
+ layout: 'default'
17
+ })
18
+ </script>
19
+ ```
20
+
21
+ :read-more{to="/docs/guide/directory-structure/pages#page-metadata"}
22
+
23
+ ## Type
24
+
25
+ ```ts
26
+ definePageMeta(meta: PageMeta) => void
27
+
28
+ interface PageMeta {
29
+ validate?: (route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>
30
+ redirect?: RouteRecordRedirectOption
31
+ name?: string
32
+ path?: string
33
+ props?: RouteRecordRaw['props']
34
+ alias?: string | string[]
35
+ pageTransition?: boolean | TransitionProps
36
+ layoutTransition?: boolean | TransitionProps
37
+ viewTransition?: boolean | 'always'
38
+ key?: false | string | ((route: RouteLocationNormalizedLoaded) => string)
39
+ keepalive?: boolean | KeepAliveProps
40
+ layout?: false | LayoutKey | Ref<LayoutKey> | ComputedRef<LayoutKey>
41
+ middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>
42
+ scrollToTop?: boolean | ((to: RouteLocationNormalizedLoaded, from: RouteLocationNormalizedLoaded) => boolean)
43
+ [key: string]: unknown
44
+ }
45
+ ```
46
+
47
+ ## Parameters
48
+
49
+ ### `meta`
50
+
51
+ - **Type**: `PageMeta`
52
+
53
+ An object accepting the following page metadata:
54
+
55
+ **`name`**
56
+
57
+ - **Type**: `string`
58
+
59
+ You may define a name for this page's route. By default, name is generated based on path inside the [`pages/` directory](/docs/guide/directory-structure/pages).
60
+
61
+ **`path`**
62
+
63
+ - **Type**: `string`
64
+
65
+ You may define a [custom regular expression](#using-a-custom-regular-expression) if you have a more complex pattern than can be expressed with the file name.
66
+
67
+ **`props`**
68
+
69
+ - **Type**: [`RouteRecordRaw['props']`](https://router.vuejs.org/guide/essentials/passing-props)
70
+
71
+ Allows accessing the route `params` as props passed to the page component.
72
+
73
+ **`alias`**
74
+
75
+ - **Type**: `string | string[]`
76
+
77
+ Aliases for the record. Allows defining extra paths that will behave like a copy of the record. Allows having paths shorthands like `/users/:id` and `/u/:id`. All `alias` and `path` values must share the same params.
78
+
79
+ **`keepalive`**
80
+
81
+ - **Type**: `boolean` | [`KeepAliveProps`](https://vuejs.org/api/built-in-components.html#keepalive)
82
+
83
+ Set to `true` when you want to preserve page state across route changes or use the [`KeepAliveProps`](https://vuejs.org/api/built-in-components.html#keepalive) for a fine-grained control.
84
+
85
+ **`key`**
86
+
87
+ - **Type**: `false` | `string` | `((route: RouteLocationNormalizedLoaded) => string)`
88
+
89
+ Set `key` value when you need more control over when the `<NuxtPage>` component is re-rendered.
90
+
91
+ **`layout`**
92
+
93
+ - **Type**: `false` | `LayoutKey` | `Ref<LayoutKey>` | `ComputedRef<LayoutKey>`
94
+
95
+ Set a static or dynamic name of the layout for each route. This can be set to `false` in case the default layout needs to be disabled.
96
+
97
+ **`layoutTransition`**
98
+
99
+ - **Type**: `boolean` | [`TransitionProps`](https://vuejs.org/api/built-in-components.html#transition)
100
+
101
+ Set name of the transition to apply for current layout. You can also set this value to `false` to disable the layout transition.
102
+
103
+ **`middleware`**
104
+
105
+ - **Type**: `MiddlewareKey` | [`NavigationGuard`](https://router.vuejs.org/api/interfaces/NavigationGuard.html#navigationguard) | `Array<MiddlewareKey | NavigationGuard>`
106
+
107
+ Define anonymous or named middleware directly within `definePageMeta`. Learn more about [route middleware](/docs/guide/directory-structure/middleware).
108
+
109
+ **`pageTransition`**
110
+
111
+ - **Type**: `boolean` | [`TransitionProps`](https://vuejs.org/api/built-in-components.html#transition)
112
+
113
+ Set name of the transition to apply for current page. You can also set this value to `false` to disable the page transition.
114
+
115
+ **`viewTransition`**
116
+
117
+ - **Type**: `boolean | 'always'`
118
+
119
+ **Experimental feature, only available when [enabled in your nuxt.config file](/docs/getting-started/transitions#view-transitions-api-experimental)**</br>
120
+ Enable/disable View Transitions for the current page.
121
+ If set to true, Nuxt will not apply the transition if the users browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition.
122
+
123
+ **`redirect`**
124
+
125
+ - **Type**: [`RouteRecordRedirectOption`](https://router.vuejs.org/guide/essentials/redirect-and-alias.html#redirect-and-alias)
126
+
127
+ Where to redirect if the route is directly matched. The redirection happens before any navigation guard and triggers a new navigation with the new target location.
128
+
129
+ **`validate`**
130
+
131
+ - **Type**: `(route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>`
132
+
133
+ Validate whether a given route can validly be rendered with this page. Return true if it is valid, or false if not. If another match can't be found, this will mean a 404. You can also directly return an object with `statusCode`/`statusMessage` to respond immediately with an error (other matches will not be checked).
134
+
135
+ **`scrollToTop`**
136
+
137
+ - **Type**: `boolean | (to: RouteLocationNormalized, from: RouteLocationNormalized) => boolean`
138
+
139
+ Tell Nuxt to scroll to the top before rendering the page or not. If you want to overwrite the default scroll behavior of Nuxt, you can do so in `~/app/router.options.ts` (see [custom routing](/docs/guide/recipes/custom-routing#using-approuteroptions)) for more info.
140
+
141
+ **`[key: string]`**
142
+
143
+ - **Type**: `any`
144
+
145
+ Apart from the above properties, you can also set **custom** metadata. You may wish to do so in a type-safe way by [augmenting the type of the `meta` object](/docs/guide/directory-structure/pages/#typing-custom-metadata).
146
+
147
+ ## Examples
148
+
149
+ ### Basic Usage
150
+
151
+ The example below demonstrates:
152
+
153
+ - how `key` can be a function that returns a value;
154
+ - how `keepalive` property makes sure that the `<modal>` component is not cached when switching between multiple components;
155
+ - adding `pageType` as a custom property:
156
+
157
+ ```vue [pages/some-page.vue]
158
+ <script setup lang="ts">
159
+ definePageMeta({
160
+ key: (route) => route.fullPath,
161
+
162
+ keepalive: {
163
+ exclude: ['modal']
164
+ },
165
+
166
+ pageType: 'Checkout'
167
+ })
168
+ </script>
169
+ ```
170
+
171
+ ### Defining Middleware
172
+
173
+ The example below shows how the middleware can be defined using a `function` directly within the `definePageMeta` or set as a `string` that matches the middleware file name located in the `middleware/` directory:
174
+
175
+ ```vue [pages/some-page.vue]
176
+ <script setup lang="ts">
177
+ definePageMeta({
178
+ // define middleware as a function
179
+ middleware: [
180
+ function (to, from) {
181
+ const auth = useState('auth')
182
+
183
+ if (!auth.value.authenticated) {
184
+ return navigateTo('/login')
185
+ }
186
+
187
+ if (to.path !== '/checkout') {
188
+ return navigateTo('/checkout')
189
+ }
190
+ }
191
+ ],
192
+
193
+ // ... or a string
194
+ middleware: 'auth'
195
+
196
+ // ... or multiple strings
197
+ middleware: ['auth', 'another-named-middleware']
198
+ })
199
+ </script>
200
+ ```
201
+
202
+ ### Using a Custom Regular Expression
203
+
204
+ A custom regular expression is a good way to resolve conflicts between overlapping routes, for instance:
205
+
206
+ The two routes "/test-category" and "/1234-post" match both `[postId]-[postSlug].vue` and `[categorySlug].vue` page routes.
207
+
208
+ To make sure that we are only matching digits (`\d+`) for `postId` in the `[postId]-[postSlug]` route, we can add the following to the `[postId]-[postSlug].vue` page template:
209
+
210
+ ```vue [pages/[postId\\]-[postSlug\\].vue]
211
+ <script setup lang="ts">
212
+ definePageMeta({
213
+ path: '/:postId(\\d+)-:postSlug'
214
+ })
215
+ </script>
216
+ ```
217
+
218
+ For more examples see [Vue Router's Matching Syntax](https://router.vuejs.org/guide/essentials/route-matching-syntax.html).
219
+
220
+ ### Defining Layout
221
+
222
+ You can define the layout that matches the layout's file name located (by default) in the [`layouts/` directory](/docs/guide/directory-structure/layouts). You can also disable the layout by setting the `layout` to `false`:
223
+
224
+ ```vue [pages/some-page.vue]
225
+ <script setup lang="ts">
226
+ definePageMeta({
227
+ // set custom layout
228
+ layout: 'admin'
229
+
230
+ // ... or disable a default layout
231
+ layout: false
232
+ })
233
+ </script>
234
+ ```
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: 'defineRouteRules'
3
+ description: 'Define route rules for hybrid rendering at the page level.'
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/pages/runtime/composables.ts
8
+ size: xs
9
+ ---
10
+
11
+ ::read-more{to="/docs/guide/going-further/experimental-features#inlinerouterules" icon="i-lucide-star"}
12
+ This feature is experimental and in order to use it you must enable the `experimental.inlineRouteRules` option in your `nuxt.config`.
13
+ ::
14
+
15
+ ## Usage
16
+
17
+ ```vue [pages/index.vue]
18
+ <script setup lang="ts">
19
+ defineRouteRules({
20
+ prerender: true
21
+ })
22
+ </script>
23
+
24
+ <template>
25
+ <h1>Hello world!</h1>
26
+ </template>
27
+ ```
28
+
29
+ Will be translated to:
30
+
31
+ ```ts [nuxt.config.ts]
32
+ export default defineNuxtConfig({
33
+ routeRules: {
34
+ '/': { prerender: true }
35
+ }
36
+ })
37
+ ```
38
+
39
+ ::note
40
+ When running [`nuxt build`](/docs/api/commands/build), the home page will be pre-rendered in `.output/public/index.html` and statically served.
41
+ ::
42
+
43
+ ## Notes
44
+
45
+ - A rule defined in `~/pages/foo/bar.vue` will be applied to `/foo/bar` requests.
46
+ - A rule in `~/pages/foo/[id].vue` will be applied to `/foo/**` requests.
47
+
48
+ For more control, such as if you are using a custom `path` or `alias` set in the page's [`definePageMeta`](/docs/api/utils/define-page-meta), you should set `routeRules` directly within your `nuxt.config`.
49
+
50
+ ::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering" icon="i-lucide-medal"}
51
+ Read more about the `routeRules`.
52
+ ::
@@ -0,0 +1,230 @@
1
+ ---
2
+ title: "navigateTo"
3
+ description: navigateTo is a helper function that programmatically navigates users.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
8
+ size: xs
9
+ ---
10
+
11
+ ## Usage
12
+
13
+ `navigateTo` is available on both server side and client side. It can be used within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context), or directly, to perform page navigation.
14
+
15
+ ::warning
16
+ Make sure to always use `await` or `return` on result of `navigateTo` when calling it.
17
+ ::
18
+
19
+ ::note
20
+ `navigateTo` cannot be used within Nitro routes. To perform a server-side redirect in Nitro routes, use [`sendRedirect`](https://h3.unjs.io/utils/response#sendredirectevent-location-code) instead.
21
+ ::
22
+
23
+ ### Within a Vue Component
24
+
25
+ ```vue
26
+ <script setup lang="ts">
27
+ // passing 'to' as a string
28
+ await navigateTo('/search')
29
+
30
+ // ... or as a route object
31
+ await navigateTo({ path: '/search' })
32
+
33
+ // ... or as a route object with query parameters
34
+ await navigateTo({
35
+ path: '/search',
36
+ query: {
37
+ page: 1,
38
+ sort: 'asc'
39
+ }
40
+ })
41
+ </script>
42
+ ```
43
+
44
+ ### Within Route Middleware
45
+
46
+ ```ts
47
+ export default defineNuxtRouteMiddleware((to, from) => {
48
+ if (to.path !== '/search') {
49
+ // setting the redirect code to '301 Moved Permanently'
50
+ return navigateTo('/search', { redirectCode: 301 })
51
+ }
52
+ })
53
+ ```
54
+
55
+ When using `navigateTo` within route middleware, you must **return its result** to ensure the middleware execution flow works correctly.
56
+
57
+ For example, the following implementation **will not work as expected**:
58
+
59
+ ```ts
60
+ export default defineNuxtRouteMiddleware((to, from) => {
61
+ if (to.path !== '/search') {
62
+ // ❌ This will not work as expected
63
+ navigateTo('/search', { redirectCode: 301 })
64
+ return
65
+ }
66
+ })
67
+ ```
68
+
69
+ In this case, `navigateTo` will be executed but not returned, which may lead to unexpected behavior.
70
+
71
+ :read-more{to="/docs/guide/directory-structure/middleware"}
72
+
73
+ ### Navigating to an External URL
74
+
75
+ The `external` parameter in `navigateTo` influences how navigating to URLs is handled:
76
+
77
+ - **Without `external: true`**:
78
+ - Internal URLs navigate as expected.
79
+ - External URLs throw an error.
80
+
81
+ - **With `external: true`**:
82
+ - Internal URLs navigate with a full-page reload.
83
+ - External URLs navigate as expected.
84
+
85
+ #### Example
86
+
87
+ ```vue
88
+ <script setup lang="ts">
89
+ // will throw an error;
90
+ // navigating to an external URL is not allowed by default
91
+ await navigateTo('https://nuxt.com')
92
+
93
+ // will redirect successfully with the 'external' parameter set to 'true'
94
+ await navigateTo('https://nuxt.com', {
95
+ external: true
96
+ })
97
+ </script>
98
+ ```
99
+
100
+ ### Opening a Page in a New Tab
101
+
102
+ ```vue
103
+ <script setup lang="ts">
104
+ // will open 'https://nuxt.com' in a new tab
105
+ await navigateTo('https://nuxt.com', {
106
+ open: {
107
+ target: '_blank',
108
+ windowFeatures: {
109
+ width: 500,
110
+ height: 500
111
+ }
112
+ }
113
+ })
114
+ </script>
115
+ ```
116
+
117
+ ## Type
118
+
119
+ ```ts
120
+ function navigateTo(
121
+ to: RouteLocationRaw | undefined | null,
122
+ options?: NavigateToOptions
123
+ ) => Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw
124
+
125
+ interface NavigateToOptions {
126
+ replace?: boolean
127
+ redirectCode?: number
128
+ external?: boolean
129
+ open?: OpenOptions
130
+ }
131
+
132
+ type OpenOptions = {
133
+ target: string
134
+ windowFeatures?: OpenWindowFeatures
135
+ }
136
+
137
+ type OpenWindowFeatures = {
138
+ popup?: boolean
139
+ noopener?: boolean
140
+ noreferrer?: boolean
141
+ } & XOR<{ width?: number }, { innerWidth?: number }>
142
+ & XOR<{ height?: number }, { innerHeight?: number }>
143
+ & XOR<{ left?: number }, { screenX?: number }>
144
+ & XOR<{ top?: number }, { screenY?: number }>
145
+ ```
146
+
147
+ ## Parameters
148
+
149
+ ### `to`
150
+
151
+ **Type**: [`RouteLocationRaw`](https://router.vuejs.org/api/interfaces/RouteLocationOptions.html#Interface-RouteLocationOptions) | `undefined` | `null`
152
+
153
+ **Default**: `'/'`
154
+
155
+ `to` can be a plain string or a route object to redirect to. When passed as `undefined` or `null`, it will default to `'/'`.
156
+
157
+ #### Example
158
+
159
+ ```ts
160
+ // Passing the URL directly will redirect to the '/blog' page
161
+ await navigateTo('/blog')
162
+
163
+ // Using the route object, will redirect to the route with the name 'blog'
164
+ await navigateTo({ name: 'blog' })
165
+
166
+ // Redirects to the 'product' route while passing a parameter (id = 1) using the route object.
167
+ await navigateTo({ name: 'product', params: { id: 1 } })
168
+ ```
169
+
170
+ ### `options` (optional)
171
+
172
+ **Type**: `NavigateToOptions`
173
+
174
+ An object accepting the following properties:
175
+
176
+ - `replace`
177
+
178
+ - **Type**: `boolean`
179
+ - **Default**: `false`
180
+ - By default, `navigateTo` pushes the given route into the Vue Router's instance on the client side.
181
+
182
+ This behavior can be changed by setting `replace` to `true`, to indicate that given route should be replaced.
183
+
184
+ - `redirectCode`
185
+
186
+ - **Type**: `number`
187
+ - **Default**: `302`
188
+
189
+ - `navigateTo` redirects to the given path and sets the redirect code to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) by default when the redirection takes place on the server side.
190
+
191
+ This default behavior can be modified by providing different `redirectCode`. Commonly, [`301 Moved Permanently`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) can be used for permanent redirections.
192
+
193
+ - `external`
194
+
195
+ - **Type**: `boolean`
196
+ - **Default**: `false`
197
+
198
+ - Allows navigating to an external URL when set to `true`. Otherwise, `navigateTo` will throw an error, as external navigation is not allowed by default.
199
+
200
+ - `open`
201
+
202
+ - **Type**: `OpenOptions`
203
+ - Allows navigating to the URL using the [open()](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) method of the window. This option is only applicable on the client side and will be ignored on the server side.
204
+
205
+ An object accepting the following properties:
206
+
207
+ - `target`
208
+
209
+ - **Type**: `string`
210
+ - **Default**: `'_blank'`
211
+
212
+ - A string, without whitespace, specifying the name of the browsing context the resource is being loaded into.
213
+
214
+ - `windowFeatures`
215
+
216
+ - **Type**: `OpenWindowFeatures`
217
+
218
+ - An object accepting the following properties:
219
+
220
+ | Property | Type | Description |
221
+ |----------|---------|--------------|
222
+ | `popup` | `boolean` | Requests a minimal popup window instead of a new tab, with UI features decided by the browser. |
223
+ | `width` or `innerWidth` | `number` | Specifies the content area's width (minimum 100 pixels), including scrollbars. |
224
+ | `height` or `innerHeight` | `number` | Specifies the content area's height (minimum 100 pixels), including scrollbars. |
225
+ | `left` or `screenX` | `number` | Sets the horizontal position of the new window relative to the left edge of the screen. |
226
+ | `top` or `screenY` | `number` | Sets the vertical position of the new window relative to the top edge of the screen. |
227
+ | `noopener` | `boolean` | Prevents the new window from accessing the originating window via `window.opener`. |
228
+ | `noreferrer` | `boolean` | Prevents the Referer header from being sent and implicitly enables `noopener`. |
229
+
230
+ Refer to the [documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures) for more detailed information on the **windowFeatures** properties.
@@ -0,0 +1,11 @@
1
+ ---
2
+ title: "onBeforeRouteLeave"
3
+ description: The onBeforeRouteLeave composable allows registering a route guard within a component.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
8
+ size: xs
9
+ ---
10
+
11
+ :read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/#onBeforeRouteLeave" title="Vue Router Docs" target="_blank"}
@@ -0,0 +1,11 @@
1
+ ---
2
+ title: "onBeforeRouteUpdate"
3
+ description: The onBeforeRouteUpdate composable allows registering a route guard within a component.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
8
+ size: xs
9
+ ---
10
+
11
+ :read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/#onBeforeRouteUpdate" title="Vue Router Docs" target="_blank"}
@@ -0,0 +1,25 @@
1
+ ---
2
+ title: "onNuxtReady"
3
+ description: The onNuxtReady composable allows running a callback after your app has finished initializing.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ready.ts
8
+ size: xs
9
+ ---
10
+
11
+ ::important
12
+ `onNuxtReady` only runs on the client-side. :br
13
+ It is ideal for running code that should not block the initial rendering of your app.
14
+ ::
15
+
16
+ ```ts [plugins/ready.client.ts]
17
+ export default defineNuxtPlugin(() => {
18
+ onNuxtReady(async () => {
19
+ const myAnalyticsLibrary = await import('my-big-analytics-library')
20
+ // do something with myAnalyticsLibrary
21
+ })
22
+ })
23
+ ```
24
+
25
+ It is 'safe' to run even after your app has initialized. In this case, then the code will be registered to run in the next idle callback.
@@ -0,0 +1,28 @@
1
+ ---
2
+ title: 'prefetchComponents'
3
+ description: Nuxt provides utilities to give you control over prefetching components.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/preload.ts
8
+ size: xs
9
+ ---
10
+
11
+
12
+ Prefetching component downloads the code in the background, this is based on the assumption that the component will likely be used for rendering, enabling the component to load instantly if and when the user requests it. The component is downloaded and cached for anticipated future use without the user making an explicit request for it.
13
+
14
+ Use `prefetchComponents` to manually prefetch individual components that have been registered globally in your Nuxt app. By default Nuxt registers these as async components. You must use the Pascal-cased version of the component name.
15
+
16
+ ```ts
17
+ await prefetchComponents('MyGlobalComponent')
18
+
19
+ await prefetchComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
20
+ ```
21
+
22
+ ::note
23
+ Current implementation behaves exactly the same as [`preloadComponents`](/docs/api/utils/preload-components) by preloading components instead of just prefetching we are working to improve this behavior.
24
+ ::
25
+
26
+ ::note
27
+ On server, `prefetchComponents` will have no effect.
28
+ ::
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: 'preloadComponents'
3
+ description: Nuxt provides utilities to give you control over preloading components.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/preload.ts
8
+ size: xs
9
+ ---
10
+
11
+ Preloading components loads components that your page will need very soon, which you want to start loading early in rendering lifecycle. This ensures they are available earlier and are less likely to block the page's render, improving performance.
12
+
13
+ Use `preloadComponents` to manually preload individual components that have been registered globally in your Nuxt app. By default Nuxt registers these as async components. You must use the Pascal-cased version of the component name.
14
+
15
+ ```js
16
+ await preloadComponents('MyGlobalComponent')
17
+
18
+ await preloadComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
19
+ ```
20
+
21
+ ::note
22
+ On server, `preloadComponents` will have no effect.
23
+ ::
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: 'preloadRouteComponents'
3
+ description: preloadRouteComponents allows you to manually preload individual pages in your Nuxt app.
4
+ links:
5
+ - label: Source
6
+ icon: i-simple-icons-github
7
+ to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/preload.ts
8
+ size: xs
9
+ ---
10
+
11
+ Preloading routes loads the components of a given route that the user might navigate to in future. This ensures that the components are available earlier and less likely to block the navigation, improving performance.
12
+
13
+ ::tip{icon="i-lucide-rocket"}
14
+ Nuxt already automatically preloads the necessary routes if you're using the `NuxtLink` component.
15
+ ::
16
+
17
+ :read-more{to="/docs/api/components/nuxt-link"}
18
+
19
+ ## Example
20
+
21
+ Preload a route when using `navigateTo`.
22
+
23
+ ```ts
24
+ // we don't await this async function, to avoid blocking rendering
25
+ // this component's setup function
26
+ preloadRouteComponents('/dashboard')
27
+
28
+ const submit = async () => {
29
+ const results = await $fetch('/api/authentication')
30
+
31
+ if (results.token) {
32
+ await navigateTo('/dashboard')
33
+ }
34
+ }
35
+ ```
36
+
37
+ :read-more{to="/docs/api/utils/navigate-to"}
38
+
39
+ ::note
40
+ On server, `preloadRouteComponents` will have no effect.
41
+ ::