matcher (middleware)
The config.matcher option exported from middleware.ts that lists which paths the middleware runs on.
In more detail
Entries are path patterns such as /admin/:path* or regular expressions, for example one that excludes _next/static, images and favicon.ico. Values must be constants so Next.js can read them at build time.
Example
export const config = { matcher: ['/admin/:path*'] };Related terms
- middleware.ts — A single file at the project root that runs code before matching requests are routed, to redirect, rewrite, set headers or check sessions.
- path parameter — A value embedded in the path of a URL, such as 42 in /users/42, which a router extracts by matching a pattern.
- regular expression — A pattern language for matching text, where characters such as ., *, ^ and $ have special meanings.
Taught in
- Edge Middleware: Auth Verification & Route Matchers — Next.js 15 & Modern App Router Architecture