next/link prefixing urls with / only on client side
See original GitHub issueBug report
Describe the bug
With the latest next.js version (10.0.3), I noticed a new warning in my console, without changing anything at the code. When using next/link a slash / get’s prefixed to the url on client side but not on server. I had no errors on 10.0.1.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Clone any next.js example repo (for ex.: using-router-app)
- Modify your index.js page to this:
import Link from "next/link";
export default function Home() {
return (
<div>
<Link href={`test`}>
<a>test</a>
</Link>
</div>
);
}
- Check the console
react-dom.development.js:88 Warning: Prop `href` did not match. Server: "test" Client: "/test"
in a (at pages/index.js:7)
in Link (at pages/index.js:6)
in div (at pages/index.js:5)
in Home (created by App)
in App
in ErrorBoundary (created by ReactDevOverlay)
in ReactDevOverlay (created by Container)
in Container (created by AppContainer)
in AppContainer
in Root
Expected behavior
Prefix the url on client and server side, or don’t prefix it at all.
Screenshots
System information
- OS: Windows 10
- Browser Chrome
- Version of Next.js: v10.0.3
- Version of Node.js: v14.15.1
- Deployment: yarn dev
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Developers - next/link prefixing urls with / only on client side -
3), I noticed a new warning in my console, without changing anything at the code. When using next/link a slash / get's prefixed...
Read more >Advanced Linking with the Next-Link
Client -side transitions between routes may be made easier with the Link component imported from the next/link module.
Read more >Client-Side Routing In Next.js
The next/link API # · Routes With Dynamic Segments # · Use-cases For The passHref Prop # · URL Objects #.
Read more >Next.js - Error: only absolute urls are supported
As the error states, you will have to use an absolute URL for the fetch you're making. I'm assuming it has something to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fix proposal
Currently I have tried by making removing the trailing slash in the client side. Now at both Server and Client the href will be ‘about’ and ‘about’ respectively. Not sure whether correct or not. pull request
next-server/lib/router/router.ts
I am experiencing a similar issue after adding
i18n
/Internationalized Routing
to mynext.config.js
file. Note, that without adding that, this error does not occur. Thei18n
section of mynext.config.js
file:Below is the error I receive. Note that I am developing on
http://localhost
, but for some reason next.js is forcinghttps
on the server:Next version: 10.0.8