Route Rule Layouts
Assign layouts to whole route trees from one place, without scattering definePageMeta across every page.
What's new#
Nuxt 4.3 lets you set a page's layout from route rules using the new appLayout property. No more opening every page just to tell it which layout to use.
Why you'd care#
Picture an admin panel with twenty pages, all needing the admin layout. Until now, that meant twenty copies of the same definePageMeta({ layout: 'admin' }). Miss one and you get a broken-looking page. appLayout moves that decision to a single, declarative place.
Before#
Every page carried its own layout declaration:
<script setup lang="ts">
definePageMeta({ layout: 'admin' })
</script>
Repeat that in admin/settings.vue, admin/billing.vue, admin/logs.vue… you get the idea.
After#
Declare it once, for the whole tree, in nuxt.config.ts:
export default defineNuxtConfig({
routeRules: {
'/admin/**': { appLayout: 'admin' },
'/dashboard/**': { appLayout: 'dashboard' },
'/auth/**': { appLayout: 'minimal' }
}
})
Every page under /admin now uses the admin layout — and you never touched the page files.
Do it yourself#
- Make sure you have a layout at
layouts/admin.vue. - Open
nuxt.config.tsand add arouteRulesentry mapping'/admin/**'to{ appLayout: 'admin' }. - Create a page at
pages/admin/index.vuewith nodefinePageMetalayout call. - Run the dev server and visit
/admin. Confirm the admin layout renders. - Add a second page under
/adminand confirm it inherits the layout too.
A page-level definePageMeta({ layout }) still wins if you need to override a single route inside the tree.
Gotchas#
- Route rules match by path pattern — double-check your glob (
/admin/**vs/admin/*).**matches nested segments;*matches only one. - This is server-driven config. After editing
nuxt.config.ts, restart the dev server if the change doesn't pick up.
Recap#
Layouts are now a route-tree concern you can declare centrally with appLayout in routeRules. Reach for it whenever a whole section shares a layout.