next.js
866de416 - docs: documents middleware matcher (#40180)

Commit
3 years ago
docs: documents middleware matcher (#40180) ### ๐Ÿ“– What's in there? Middleware matchers are powerful, but very few people realized it, because they are not really documented. This PR tries to bring more clarity, and includes a more advanced example. The example shows how to exclude several pages (no `/static`, no `/public`), but also allow specific page in excluded paths (`/public/disclaimer`) ### ๐Ÿงช How to test? Run the example: `pnpm next dev examples/middleware-matcher`, then browse to http://localhost:3000 The first 3 links should not match, the last 3 ones should. Don't forget to clear your localhost cookies if you change the middleware code. ### ๐Ÿ†™ Note to reviewers Using session cookies to pass information from middleware to the rendered page is not great, because `document.cookie` is not available during SSR, and because cookies persist when refreshing the page (making it hard to try different matchers) However, I couldn't find a simpler way to convey the information from the middleware to the page, and I meant to have something visual. The other option is to use response headers and curl commands, but...
Author
Parents
Loading