Home » vue » Nuxt add middleware to all pages

Nuxt add middleware to all pages

Posted by: admin November 26, 2021 Leave a comment

Questions:

Is there a way to add a middleware to all the pages in a Nuxt app?

Besides adding it to the layouts. Because it requires to remember that every new layout must have a middleware.

Answers:

Yes.

You can add it in nuxt.config.js

router: {
  middleware: ['your-global-middleware'],
},

This one will look for a middleware in your middleware directory, as for any regular middleware and apply it on all your app.