Nuxt 2 is reaching End-of-Life on June 30th, 2024.

setPageLayout

setPageLayout allows you to dynamically change the layout of a page.
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.
middleware/custom-layout.ts
export default defineNuxtRouteMiddleware((to) => {
  // Set the layout on the route you are navigating _to_
  setPageLayout('other')
})
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.