Unverified Commit 00bcd551 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update middleware matcher docs to mention has matching (#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: 's avatarZack Tanner <zacktanner@gmail.com>
parent f25ae9a0
...@@ -97,7 +97,7 @@ export const config = { ...@@ -97,7 +97,7 @@ export const config = {
} }
``` ```
You can also ignore prefetches (from `next/link`) that don't need to go through the Middleware using the `missing` array: You can also bypass Middleware for certain requests by using the `missing` or `has` arrays, or a combination of both:
```js filename="middleware.js" ```js filename="middleware.js"
export const config = { export const config = {
...@@ -116,6 +116,20 @@ export const config = { ...@@ -116,6 +116,20 @@ export const config = {
{ type: 'header', key: 'purpose', value: 'prefetch' }, { type: 'header', key: 'purpose', value: 'prefetch' },
], ],
}, },
{
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
has: [
{ type: 'header', key: 'next-router-prefetch' },
{ type: 'header', key: 'purpose', value: 'prefetch' },
],
},
{
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
has: [{ type: 'header', key: 'x-present' }],
missing: [{ type: 'header', key: 'x-missing', value: 'prefetch' }],
},
], ],
} }
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment