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

next/link with rewrites works different in preview and local environment #54963

Closed
1 task done
mrzmyr opened this issue Sep 4, 2023 · 3 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. stale The issue has not seen recent activity.

Comments

@mrzmyr
Copy link

mrzmyr commented Sep 4, 2023

Link to the code that reproduces this issue or a replay of the bug

https://github.com/mrzmyr/link-to-rewrite-reproduction

To Reproduce

Localhost

CleanShot 2023-09-04 at 10 23 21

https://localhost:3000/example

Preview

CleanShot 2023-09-04 at 10 24 17

https://link-to-rewrite-reproduction-mrzmyr.vercel.app/example

Current vs. Expected behavior

Current

Given the next.config.js

  rewrites: () => [
    {
      source: "/",
      destination: "/en",
    },
  ],

and a link <Link href="/">Go Home</Link>, the redirect on preview deployments sets the slug to ["index"] and to (the correct rewrite) ["en"] on local deployments.

Expected

Given the next.config.js

  rewrites: () => [
    {
      source: "/",
      destination: "/en",
    },
  ],

and a link <Link href="/">Go Home</Link>, the redirect on preview deployments sets the same slug ["en"]on local and preview deployments.

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.4.0: Mon Mar  6 20:59:58 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6020
    Binaries:
      Node: 19.9.0
      npm: 9.6.3
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.15
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

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

App Router, Routing (next/router, next/navigation, next/link)

Additional context

No response

@mrzmyr mrzmyr added the bug Issue was opened via the bug report template. label Sep 4, 2023
@github-actions github-actions bot added the Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. label Sep 4, 2023
@mrzmyr mrzmyr changed the title next/link works different between preview and local environment next/link with rewrites works different in preview and local environment Sep 4, 2023
@mrzmyr mrzmyr changed the title next/link with rewrites works different in preview and local environment next/link with rewrites works different in preview and local environment Sep 4, 2023
@jaredwiener
Copy link

Having a similar issue.

I have a default route -- similar to app/[id]/page.js -- for user profiles, but also have some rewrites for other pages.

In preview (and not locally) -- it loads the routes in a different order depending on the source of the request.

On the server -- i.e. first load -- it checks the rewrites in next.config.js first.
On the client -- when using <Link> -- it seems to load the default route first.

@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 Mar 16, 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 Mar 23, 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. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

3 participants