New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Middleware in a [dynamic] route subdirectory runs against parent urls #35629
Comments
This has recently been fixed in #32601. Please give |
Hi, I believe this has been fixed. but with that case adding |
The fix has been reverted as it seemed to break in certain cases. I'm reopening because this needs further investigation. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi there! Precisely because of this kind of issues we have changed the way you define middleware. Before we were allowing it to define it aside with pages which created the mental model that a middleware would trigger when a page renders but making it work like that is very tricky. Instead now you can define a single middleware and decide the matcher that you will use to trigger it. You can also define multiple patterns and branch in the middleware execution. This makes the model much simpler and familiar as you define matchers in the same way you do for configuration headers, rewrites and redirects. Therefore I'm closing this issue! |
Thanks, @javivelasco :) For future readers, here's the details: https://nextjs.org/docs/messages/middleware-upgrade-guide#no-nested-middleware |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
With a page structure like:
And a
pages/[customer]/_middleware
file containing:I would expect
_middleware
to only apply to pages that resolve within that subdirectory, however it gets applied to every request:Expected Behavior
I would expect the middleware not to be invoked on an unmatched route.
To Reproduce
See above description with a trivial example.
The text was updated successfully, but these errors were encountered: