Nuxt 2 Bridge: How to set a middleware on a page?

644 views Asked by At

In Nuxt 3 page middleware is set by definePageMeta, however this is not available in Nuxt 2 Bridge.

1

There are 1 answers

0
thisismydesign On

In Nuxt 2 Bridge middlewares are still set the old non-composition way. This can be used next to the composition API:

<template>
  <div />
</template>

<script setup lang="ts">
onMounted(() => {
  useNuxtApp().nuxt2Context.$auth.login()
})
</script>

<script lang="ts">
export default {
  middleware: ['auth'],
}
</script>