Demo
File Location
project/
├── middleware.ts   ← runs on matched routes
├── app/
│   └── ...
Basic Example
middleware.tstsx
Common Patterns

Auth Check

Redirect unauthenticated users to login

Geo Redirect

Route users to country-specific pages

A/B Testing

Rewrite to different page variants

Headers

Add security or custom headers

Matcher