Documentación offline Nuxt main

setPageLayout

main Documentación oficial Licencia MITDescargado el 2026-08-02

::important setPageLayout allows you to dynamically change the layout of a page. It relies on access to the Nuxt context and therefore can only be called within the Nuxt context. ::

```ts [app/middleware/custom-layout.ts] export default defineNuxtRouteMiddleware((to) => { // Set the layout on the route you are navigating to setPageLayout('other') })

## Passing Props to Layouts :badge[v4.3]{color="info" size="xs" class="align-middle"}

You can pass props to the layout by providing an object as the second argument:

```ts [app/middleware/admin-layout.ts]
export default defineNuxtRouteMiddleware((to) => {
  setPageLayout('admin', {
    sidebar: true,
    title: 'Dashboard',
  })
})

The layout can then receive these props:

```vue [app/layouts/admin.vue]

```

::note If you choose to set the layout dynamically on the server side, you must do so before the layout is rendered by Vue (that is, within a plugin or route middleware) to avoid a hydration mismatch. ::