---
title: "Middleware"
description: "This example shows how to add route middleware with the middleware/ directory or with a plugin, and how to use them globally or per page."
canonical_url: "https://nuxt.com/docs/3.x/examples/routing/middleware"
---
# Middleware

> This example shows how to add route middleware with the middleware/ directory or with a plugin, and how to use them globally or per page.

<code-explorer default-value="middleware/redirect-me.ts" path="examples/routing/middleware">



</code-explorer>

<browser src="https://middleware.example.nuxt.space">



</browser>

<read-more to="https://nuxt.com/docs/3.x/guide/directory-structure/middleware">



</read-more>

---

- [Source](https://github.com/nuxt/examples/tree/main/examples/routing/middleware)


## Sitemap

See the full [sitemap](https://nuxt.com/sitemap.md) for all pages.
