Enable Layouts
Layouts are enabled by adding<NuxtLayout> to your app.vue:
app/app.vue
- Set a
layoutproperty in your page withdefinePageMeta. - Set the
nameprop of<NuxtLayout>. - Set the
appLayoutproperty in route rules.
The layout name is normalized to kebab-case, so
someLayout becomes some-layout.If no layout is specified,
app/layouts/default.vue will be used.If you only have a single layout in your application, we recommend using
app.vue instead.Unlike other components, your layouts must have a single root element to allow Nuxt to apply transitions between layout changes - and this root element cannot be a
<slot />.Default Layout
Add a~/layouts/default.vue:
app/layouts/default.vue
<slot /> component.
Named Layout
custom layout in your page:
pages/about.vue
name property of <NuxtLayout>:
app/app.vue
| File | Layout Name |
|---|---|
~/layouts/desktop/default.vue | desktop-default |
~/layouts/desktop-base/base.vue | desktop-base |
~/layouts/desktop/index.vue | desktop |
Changing the Layout Dynamically
You can also use thesetPageLayout helper to change the layout dynamically:
appLayout property in route rules:
nuxt.config.ts
Overriding a Layout on a Per-page Basis
If you are using pages, you can take full control by settinglayout: false and then using the <NuxtLayout> component within the page.
If you use
<NuxtLayout> within your pages, make sure it is not the root element (or disable layout/page transitions).