[next/link] Using URL object with dynamic routes does not work
See original GitHub issueBug report
Describe the bug
The documentation for next/link
describes using an URL object for the href prop:
https://nextjs.org/docs/api-reference/next/link#with-url-object
However, it seems that for dynamic routes, the value of the slug
key from the query object just gets appended to the URL as a normal query parameter and the link ends up pointing to: /blog/[slug]?slug=my-post
This happens in both dev and production builds.
To Reproduce
- Go to https://github.com/mantysalo/next-link-issue
- Clone the repo
- Start dev server
- Observe the URL of the link
- See error
Expected behavior
With an URL object as such:
{
pathname: '/blog/[slug]',
query: { slug: 'my-post' },
}
I would expect the url to be: /blog/my-post
as it is stated in the documentation.
System information
- OS: macOS
- Version of Next.js: 9.5.3
- Version of Node.js: 12.16.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (5 by maintainers)
Top Results From Across the Web
NextLink Dynamic Route Not Working When In Dynamic Route
The username value from the route query is referenced in the useEffect fetching user data, it should be added to the useEffect hook's ......
Read more >Dynamic Routes - Next.js
Dynamic Routes are pages that allow you to add custom params to your URLs. ... Defining routes by using predefined paths is not...
Read more >Advanced Linking with the Next-Link - Topcoder
Using interpolation or a URL Object to create the link, on the other hand, can become extremely frequent and useful. The dynamic route...
Read more >Dealing with links in Next.js - LogRocket Blog
Before version 9, Next didn't support dynamic routing. This was a big issue, and I had been using next-router for dynamic routing. It...
Read more >A Beginner's guide to Dynamic Routing in Next.js - Marie Starck
But how does it work for dynamic routes? ... not very practical. I am going to create a separate posts object and use...
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
@pixelass This shouldn’t be an issue anymore, make sure to be on the latest Next.js version, and if there is a bug then please open a new issue with a reproduction 🙏
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.