---
title: "中间件"
description: "本示例展示如何通过 middleware/ 目录或插件添加路由中间件，以及如何在全局或按页面使用它们。"
canonical_url: "https://nuxt.zhcndoc.com/docs/examples/routing/middleware"
---
# 中间件

> 本示例展示如何通过 middleware/ 目录或插件添加路由中间件，以及如何在全局或按页面使用它们。

::code-explorer{path="examples/routing/middleware" default-value="middleware/redirect-me.ts"}
::

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

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

---

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


## Sitemap

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