Skip to content
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

Rewrites don't work if a middleware.ts file is present #51923

Open
1 task done
Reinano opened this issue Jun 28, 2023 · 3 comments
Open
1 task done

Rewrites don't work if a middleware.ts file is present #51923

Reinano opened this issue Jun 28, 2023 · 3 comments
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.

Comments

@Reinano
Copy link

Reinano commented Jun 28, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js 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

@Reinano Reinano added the bug Issue was opened via the bug report template. label Jun 28, 2023
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Jun 28, 2023
@paulvanbrenk
Copy link

paulvanbrenk commented Jun 28, 2023

The problem is the locales, probably the same as this. It looks like Vercel doesn't care about i18n

#49883

@JesseKoldewijn
Copy link
Contributor

Agreed, there seemed to be an issue with localization in general when combining config rewrites with middleware as far as I've last noticed. But don't quote me on that

@samik3k
Copy link

samik3k commented Jul 6, 2023

Btw, it's working fine in development, but fails in production build :(

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. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants