Skip to content

404 page not returned on dynamic pages when middleware is added (Pages directory) #58392

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

Closed
1 task done
khalilp5 opened this issue Nov 13, 2023 · 2 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.

Comments

@khalilp5
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/beautiful-dawn-7r9q24

To Reproduce

  1. Visit the provided reproduction link.
  2. Navigate to any todo on the index page after the 5th ID.
  3. It should route to the 404 page.
  4. Rename the middleware2.ts file to middleware.ts.
  5. Repeat Step 2.
  6. This will result in an application error.

Current vs. Expected behavior

Current Behaviour:

  • With Middleware dynamic not found pages throws application error

Expected Behaviour:

  • With Middleware dynamic not found page should navigate to 404 page

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

NA

Which area(s) are affected? (Select all that apply)

Middleware / Edge (API routes, runtime)

Additional context

Since Next 12, I have been experiencing issues with routing to the 404 page on dynamic pages when using middleware. I am attempting to render 404 pages when a path does not exist. However, when I enable middleware, it throws an application error instead of routing to 404. Interestingly, when I remove the middleware, the routing works as expected.

export async function middleware(request: NextRequest) {
  return NextResponse.next();
}
@khalilp5 khalilp5 added the bug Issue was opened via the bug report template. label Nov 13, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Nov 13, 2023
@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label May 11, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants