---
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/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{path="examples/routing/middleware" default-value="middleware/redirect-me.ts"}
::

::browser{src="https://middleware.example.nuxt.space"}
::

::read-more{to="https://nuxt.com/docs/guide/directory-structure/middleware"}
::

---

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


## Sitemap

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