Next.js Discord

Discord Forum

Problem with middleware matcher config

Answered
Tan posted this in #help-forum
Open in Discord
Avatar
TanOP
Hey guys, i'm facing a problem on middleware.ts file

`source` does not start with / for route {"source":"/((?!login).*)"}


Here is my config in middleware.ts based on src directory

export const config = {
  matcher: [
    "/((?!login).*)", // Exclude only /login route
  ],
};


i just want to include all routes excepts /login route but i can't

Even if I try this:

export const config = {
  matcher: ["/dashboard"],
};

✓ Starting...
`source` does not start with / for route {"source":"/dashboard"}


Error: Invalid middleware found


OR THIS

export const config = {
  matcher: "/dashboard",
};
Answered by Tan
I have upgraded next js version in 15 and I don't have the problem anymore
Thank you
View full answer

7 Replies

Avatar
try this @Tan
export const config = {
  matcher: [
    "/((?!^/login$).*)", // Exclude the exact /login route
  ],
};
Avatar
did you try ⬆️ ? @Tan
Avatar
TanOP
I will try tonight and let you know
Thanks for the answer
If that’s the solution I will mark the answer as valid 🙂
Avatar
TanOP
Image
Avatar
TanOP
Up please
Avatar
Can you provide a min repro repo?
Avatar
TanOP
I have upgraded next js version in 15 and I don't have the problem anymore
Thank you
Answer