next.js
next.js copied to clipboard
Router push to other domain with same prefix
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
/bin/sh: 1: yarn: not found /bin/sh: 1: pnpm: not found
Operating System:
Platform: linux
Arch: x64
Version: #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022
Binaries:
Node: 16.14.2
npm: 8.5.0
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
warn - Latest canary version not detected, detected: "12.1.0", newest: "12.3.1-canary.3".
Please try the latest canary version (npm install next@canary
) to confirm the issue still exists before creating a new issue.
Read more - https://nextjs.org/docs/messages/opening-an-issue
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
NextJS router wrongly uses startsWith
to see whether a link is running on the same origin or not. This fails when your site is running on example.com, but you push to example.com.br for a Portugese version of your site.
Expected Behavior
Site is running on example.com, example.fr and example.com.br
Example.com calls router.push('https://example.fr')
, which works just fine.
Example.com calls router.push('https://example.com.br/portugese-page')
, which opens example.com/.br/portugese-page
instead.
Link to reproduction
https://github.com/ReinoutStevens/nextjs-router
To Reproduce
The minimal example illustrates the problem, but does not reproduce it on localhost as the port number is also taken into account ( and so you cant have localhost:3000 and localhost.com:3000 ).