@nuxt/docs-nightly 4.4.0-29552640.096fa1dc → 4.4.0-29553843.0c5869c2

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.
@@ -168,6 +168,65 @@ This is useful when you want to manage layouts centrally in your configuration r
168
168
 
169
169
  :link-example{to="/docs/4.x/examples/features/layouts"}
170
170
 
171
+ ## Passing Props to Layouts
172
+
173
+ You can pass props to layouts in several ways.
174
+
175
+ ### Via `definePageMeta`
176
+
177
+ Use the object syntax for the `layout` property to pass props directly from your page:
178
+
179
+ ::code-group
180
+
181
+ ```vue [app/pages/dashboard.vue]
182
+ <script setup lang="ts">
183
+ definePageMeta({
184
+ layout: {
185
+ name: 'panel',
186
+ props: {
187
+ sidebar: true,
188
+ title: 'Dashboard',
189
+ },
190
+ },
191
+ })
192
+ </script>
193
+ ```
194
+
195
+ ```vue [app/layouts/panel.vue]
196
+ <script setup lang="ts">
197
+ const props = defineProps<{
198
+ sidebar?: boolean
199
+ title?: string
200
+ }>()
201
+ </script>
202
+
203
+ <template>
204
+ <div>
205
+ <aside v-if="sidebar">
206
+ Sidebar
207
+ </aside>
208
+ <main>
209
+ <h1>{{ title }}</h1>
210
+ <slot />
211
+ </main>
212
+ </div>
213
+ </template>
214
+ ```
215
+
216
+ ::
217
+
218
+ ::tip
219
+ Props are fully typed based on your layout's `defineProps`. You'll get autocomplete and type-checking in your editor.
220
+ ::
221
+
222
+ ### Via `setPageLayout`
223
+
224
+ You can also pass props when changing the layout dynamically with [`setPageLayout`](/docs/4.x/api/utils/set-page-layout):
225
+
226
+ ```ts
227
+ setPageLayout('panel', { sidebar: true, title: 'Dashboard' })
228
+ ```
229
+
171
230
  ## Overriding a Layout on a Per-page Basis
172
231
 
173
232
  If you are using pages, you can take full control by setting `layout: false` and then using the `<NuxtLayout>` component within the page.
@@ -86,6 +86,35 @@ console.log(layoutCustomProps.title) // I am a custom layout
86
86
  </script>
87
87
  ```
88
88
 
89
+ ## Layout Props from Page Meta
90
+
91
+ When using [`definePageMeta`](/docs/4.x/api/utils/define-page-meta) with the object syntax for `layout`, props are automatically passed to the layout component. The layout can receive them with `defineProps`:
92
+
93
+ ```vue [app/pages/dashboard.vue]
94
+ <script setup lang="ts">
95
+ definePageMeta({
96
+ layout: {
97
+ name: 'admin',
98
+ props: {
99
+ sidebar: true,
100
+ },
101
+ },
102
+ })
103
+ </script>
104
+ ```
105
+
106
+ ```vue [app/layouts/admin.vue]
107
+ <script setup lang="ts">
108
+ const props = defineProps<{
109
+ sidebar?: boolean
110
+ }>()
111
+ </script>
112
+ ```
113
+
114
+ ::read-more{to="/docs/4.x/directory-structure/app/layouts#passing-props-to-layouts"}
115
+ Read more about passing props to layouts.
116
+ ::
117
+
89
118
  ## Transitions
90
119
 
91
120
  `<NuxtLayout />` renders incoming content via `<slot />`, which is then wrapped around Vue’s `<Transition />` component to activate layout transition. For this to work as expected, it is recommended that `<NuxtLayout />` is **not** the root element of the page component.
@@ -38,7 +38,7 @@ interface PageMeta {
38
38
  viewTransition?: ViewTransitionPageOptions['enabled'] | ViewTransitionPageOptions
39
39
  key?: false | string | ((route: RouteLocationNormalizedLoaded) => string)
40
40
  keepalive?: boolean | KeepAliveProps
41
- layout?: false | LayoutKey | Ref<LayoutKey> | ComputedRef<LayoutKey>
41
+ layout?: false | LayoutKey | Ref<LayoutKey> | ComputedRef<LayoutKey> | { name?: LayoutKey | false, props?: Record<string, unknown> /* or the selected layout's props */ }
42
42
  middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>
43
43
  scrollToTop?: boolean | ((to: RouteLocationNormalizedLoaded, from: RouteLocationNormalizedLoaded) => boolean)
44
44
  [key: string]: unknown
@@ -97,10 +97,12 @@ interface PageMeta {
97
97
 
98
98
  **`layout`**
99
99
 
100
- - **Type**: `false` | `LayoutKey` | `Ref<LayoutKey>` | `ComputedRef<LayoutKey>`
100
+ - **Type**: `false` | `LayoutKey` | `Ref<LayoutKey>` | `ComputedRef<LayoutKey>` | `{ name?: LayoutKey | false; props?: Record<string, unknown> /* or the selected layout's props */ }`
101
101
 
102
102
  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.
103
103
 
104
+ You can also pass an object with `name` and `props` to pass typed props to your layout component. When your layout defines props with `defineProps`, they will be fully typed in `definePageMeta`.
105
+
104
106
  **`layoutTransition`**
105
107
 
106
108
  - **Type**: `boolean` | [`TransitionProps`](https://vuejs.org/api/built-in-components#transition)
@@ -245,3 +247,52 @@ definePageMeta({
245
247
  })
246
248
  </script>
247
249
  ```
250
+
251
+ ### Passing Props to a Layout
252
+
253
+ You can pass props to a layout by using the object syntax for `layout`. If your layout defines props with `defineProps`, the props will be fully typed.
254
+
255
+ ::code-group
256
+
257
+ ```vue [app/pages/dashboard.vue]
258
+ <script setup lang="ts">
259
+ definePageMeta({
260
+ layout: {
261
+ name: 'panel',
262
+ props: {
263
+ sidebar: true,
264
+ title: 'Dashboard',
265
+ },
266
+ },
267
+ })
268
+ </script>
269
+ ```
270
+
271
+ ```vue [app/layouts/panel.vue]
272
+ <script setup lang="ts">
273
+ const props = defineProps<{
274
+ sidebar?: boolean
275
+ title?: string
276
+ }>()
277
+ </script>
278
+
279
+ <template>
280
+ <div>
281
+ <aside v-if="sidebar">
282
+ Sidebar
283
+ </aside>
284
+ <main>
285
+ <h1>{{ title }}</h1>
286
+ <slot />
287
+ </main>
288
+ </div>
289
+ </template>
290
+ ```
291
+
292
+ ::
293
+
294
+ ::tip
295
+ Layout props set via `definePageMeta` are fully typed based on the layout's `defineProps`. You'll get autocomplete and type-checking in your editor.
296
+ ::
297
+
298
+ :read-more{to="/docs/4.x/directory-structure/app/layouts#passing-props-to-layouts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.4.0-29552640.096fa1dc",
3
+ "version": "4.4.0-29553843.0c5869c2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",