You are browsing Nuxt 2 docs. Go to Nuxt 3 docs, or learn more about Nuxt 2 Long Term Support.

Router Middleware

Using router middleware to set a class to the body so we can then style differently depending on the route


In this example:

store/class.js sets a class to the body.

middleware/class.js uses router middleware to set a class before we enter the route.

components/Navigation.vue changes the font size for the route with the name of router-middleware.

nuxt.config.js contains the router property to activate the middleware.

Loading Sandbox...