Skip to content

Commit 00bcd55

Browse files
ijjkztanner
andauthored
Update middleware matcher docs to mention has matching (vercel#63533)
Looks like we were only documenting the `missing` matcher use case although `has` is also supported and we weren't mentioning they can combined as well. x-ref: [slack thread](https://vercel.slack.com/archives/C06LDQYNPV0/p1710704436247789) Closes NEXT-2883 --------- Co-authored-by: Zack Tanner <zacktanner@gmail.com>
1 parent f25ae9a commit 00bcd55

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

docs/02-app/01-building-your-application/01-routing/13-middleware.mdx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const config = {
9797
}
9898
```
9999

100-
You can also ignore prefetches (from `next/link`) that don't need to go through the Middleware using the `missing` array:
100+
You can also bypass Middleware for certain requests by using the `missing` or `has` arrays, or a combination of both:
101101

102102
```js filename="middleware.js"
103103
export const config = {
@@ -116,6 +116,20 @@ export const config = {
116116
{ type: 'header', key: 'purpose', value: 'prefetch' },
117117
],
118118
},
119+
120+
{
121+
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
122+
has: [
123+
{ type: 'header', key: 'next-router-prefetch' },
124+
{ type: 'header', key: 'purpose', value: 'prefetch' },
125+
],
126+
},
127+
128+
{
129+
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
130+
has: [{ type: 'header', key: 'x-present' }],
131+
missing: [{ type: 'header', key: 'x-missing', value: 'prefetch' }],
132+
},
119133
],
120134
}
121135
```

0 commit comments

Comments
 (0)