Replies: 2 comments 5 replies
-
Hey @isas5675 ! Try only with
I hope it helps you, greetings. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Try this, Example: const { pathToRegexp } = require("path-to-regexp");
const paths = [
"/",
"/about",
"/contact",
"/sales",
"/wrong",
"/wrong/welcome",
"/primary/bar",
"/secondary/foo",
"/favicon.ico",
"/_next/something",
"/a",
];
const matcher = pathToRegexp("/((?!about|contact|sales).{1,})");
paths.forEach((path) => {
console.log({ path, test: matcher.test(path) });
}); It outputs: { path: '/', test: false }
{ path: '/about', test: false }
{ path: '/contact', test: false }
{ path: '/sales', test: false }
{ path: '/wrong', test: true }
{ path: '/wrong/welcome', test: true }
{ path: '/primary/bar', test: true }
{ path: '/secondary/foo', test: true }
{ path: '/favicon.ico', test: true }
{ path: '/_next/something', test: true }
{ path: '/a', test: true } |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I have a middleware file in nextJS. I don't want the middleware to run on these 4 different paths (pages):
The middleware should run on every other path.
According to nextJS official docs, we can exclude a path like in the code below.
But how to mention home page as a path to exclude? The path is "/". But it is not accepting if I place this in the matcher.
The other 3 paths (about, contact, sales) are properly being excluded by the middleware.
Any idea on how to achieve this?
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions