NuxtN
Nuxt3y ago
5 replies
oemer

What is the suggested alternative to layout middlewares in Nuxt 3?

In Nuxt 2 it was possible to define middlewares on layouts, this is no longer supported with Nuxt 3.
I would like to avoid .global middleware, as these would be called on all pages, even if not needed?

<script lang="ts" setup>
//
definePageMeta({
  middleware: ["auth"], // definePageMeta() is a compiler-hint helper that is only usable inside the script block of a single file component which is also a page. Its arguments should be compiled away and passing it at runtime has no effect.
})
</script>
Was this page helpful?