Rewrites don't work if a middleware.ts file is present #51923
Labels
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Runtime
Related to Node.js or Edge Runtime with Next.js.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 Binaries: Node: 16.19.1 npm: 8.19.3 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 13.4.6 eslint-config-next: 13.4.6 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/Reinano/custom-next
To Reproduce
1.next build && next start
2.Go to main page then click any link (about-1 or about-2).
3.Check router.query.slug
4. U'll be able to see empty router.query (useRouter)
Describe the Bug
I use rewrites and in the case when there is a middleware.ts file in the root of the project, then rewrites with a dynamic slug stop working.
I have rewrites like this:
const nextConfig = { reactStrictMode: true, async rewrites() { return [ { source: '/es-es/(quenes-somos)/:slug', destination: '/about/:slug', locale: false, }, ] } }
If i go to production build and start it. Next dev is ok.
After following the link
<Link href='/es-es/quenes-somos/about-1'>about-1 </Link>
from the main page to the about/[slug] dynamic page, I won't get router.query.slug.If u reload the page u can get router.query.slug
Router.query.slug available from getServerSideProps, but not in client side.
Expected Behavior
Would like to have access to router.query.slug from useRouter()
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: