setPageLayout allows you to dynamically change the layout of a page. It relies on access to the Nuxt context and therefore can only be called within the Nuxt context.export default defineNuxtRouteMiddleware((to) => {
// Set the layout on the route you are navigating _to_
setPageLayout('other')
})
You can pass props to the layout by providing an object as the second argument:
export default defineNuxtRouteMiddleware((to) => {
setPageLayout('admin', {
sidebar: true,
title: 'Dashboard',
})
})
The layout can then receive these props:
<script setup lang="ts">
const props = defineProps<{
sidebar?: boolean
title?: string
}>()
</script>
<template>
<div>
<aside v-if="sidebar">
Sidebar
</aside>
<main>
<h1>{{ title }}</h1>
<slot />
</main>
</div>
</template>