question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[next/link] Using URL object with dynamic routes does not work

See original GitHub issue

Bug 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

  1. Go to https://github.com/mantysalo/next-link-issue
  2. Clone the repo
  3. Start dev server
  4. Observe the URL of the link
  5. 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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lfadescommented, Oct 20, 2020

@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 🙏

0reactions
balazsorban44commented, Jan 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found