2021-10-11 12:57:54 +00:00
---
icon: IconDirectory
title: 'layouts'
head.title: Layouts directory
---
2021-06-08 21:44:30 +00:00
2021-10-11 12:57:54 +00:00
# Layouts directory
2021-06-30 16:32:22 +00:00
Nuxt provides a customizable layouts framework you can use throughout your application, ideal for extracting common UI or code patterns into reusable layout components.
2021-11-21 12:31:44 +00:00
Page layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. If you create a `layouts/default.vue` this will be used for all pages in your app. Other layouts are used by setting a `layout` property as part of your component's options.
2021-06-30 16:32:22 +00:00
2021-11-21 12:31:44 +00:00
If you only have a single layout in your application, you can alternatively use [app.vue ](/docs/directory-structure/app ).
2021-06-30 16:32:22 +00:00
2021-10-29 11:26:01 +00:00
## Example: a custom layout
2021-06-30 16:32:22 +00:00
```bash
-| layouts/
---| custom.vue
```
In your layout files, you'll need to use `<slot />` to define where the page content of your layout will be loaded. For example:
```vue
< template >
< div >
Some shared layout content:
< slot / >
< / div >
< / template >
```
Given the example above, you can use a custom layout like this:
```vue
< script >
2022-01-17 18:27:23 +00:00
// This will also work in `<script setup>`
definePageMeta({
2021-06-30 16:32:22 +00:00
layout: "custom",
2022-01-17 18:27:23 +00:00
});
2021-06-30 16:32:22 +00:00
< / script >
```
2022-01-17 18:27:23 +00:00
::alert{type=info}
Learn more about [defining page meta ](/docs/directory-structure/pages#page-metadata ).
::
2021-10-29 11:26:01 +00:00
## Example: using with slots
2021-06-30 16:32:22 +00:00
2022-01-17 18:27:23 +00:00
You can also take full control (for example, with slots) by using the `<NuxtLayout>` component (which is globally available throughout your application) by setting `layout: false` .
2021-06-30 16:32:22 +00:00
```vue
< template >
< NuxtLayout name = "custom" >
< template #header > Some header template content. </ template >
The rest of the page
< / NuxtLayout >
< / template >
2022-01-17 18:27:23 +00:00
< script setup >
definePageMeta({
2021-06-30 16:32:22 +00:00
layout: false,
2022-01-17 18:27:23 +00:00
});
2021-06-30 16:32:22 +00:00
< / script >
```
2021-10-21 10:14:40 +00:00
2022-01-17 18:27:23 +00:00
## Example: changing the layout
2021-10-21 10:14:40 +00:00
2022-01-17 18:27:23 +00:00
You can also use a ref or computed property for your layout.
2021-10-21 10:14:40 +00:00
```vue
< template >
< div >
2022-01-17 18:27:23 +00:00
< button @click =" enableCustomLayout " > Update layout</ button >
2021-10-21 10:14:40 +00:00
< / div >
< / template >
< script setup >
2022-01-17 18:27:23 +00:00
const route = useRoute()
function enableCustomLayout () {
2022-01-26 11:56:24 +00:00
route.meta.layout = "custom"
2022-01-17 18:27:23 +00:00
}
definePageMeta({
2022-01-26 11:56:24 +00:00
layout: false,
2022-01-17 18:27:23 +00:00
});
2021-10-21 10:14:40 +00:00
< / script >
```