mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 14:45:15 +00:00
f26a801775
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
25 lines
819 B
Markdown
25 lines
819 B
Markdown
---
|
|
title: 'setPageLayout'
|
|
description: setPageLayout allows you to dynamically change the layout of a page.
|
|
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
|
|
---
|
|
|
|
::callout
|
|
`setPageLayout` relies on access to the Nuxt context and can only be called within components' setup functions, plugins, and route middleware.
|
|
::
|
|
|
|
```ts [middleware/custom-layout.ts]
|
|
export default defineNuxtRouteMiddleware((to) => {
|
|
// Set the layout on the route you are navigating _to_
|
|
setPageLayout('other')
|
|
})
|
|
```
|
|
|
|
::callout
|
|
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.
|
|
::
|