2022-10-06 09:15:30 +00:00
---
2023-10-18 10:59:43 +00:00
title: 'setPageLayout'
2022-10-06 09:15:30 +00:00
description: setPageLayout allows you to dynamically change the layout of a page.
2023-10-18 10:59:43 +00:00
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
size: xs
2022-10-06 09:15:30 +00:00
---
2022-08-31 08:02:48 +00:00
2023-10-18 10:59:43 +00:00
::callout
`setPageLayout` relies on access to the Nuxt context and can only be called within components' setup functions, plugins, and route middleware.
::
2022-08-31 08:02:48 +00:00
2023-10-18 10:59:43 +00:00
```ts [middleware/custom-layout.ts]
2022-08-31 08:02:48 +00:00
export default defineNuxtRouteMiddleware((to) => {
// Set the layout on the route you are navigating _to_
setPageLayout('other')
})
```
2023-10-18 10:59:43 +00:00
::callout
2022-08-31 08:02:48 +00:00
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.
::