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.

Router push with URL object doesn't replace path parameter by the query property value

See original GitHub issue

Bug report

Description

The router doesn’t be replacing the first parameter from the pathname by the property value defined in query object

Example

If I have the following pages directory tree /pages/posts/[postId]/edit and use router push with the following parameters

{
    pathname: '/posts/[postId]/edit',
    query: { postId: 1 }
}

It’s ok, the router sends to the browser the following path /posts/1/edit

But, if I have a pages directory tree like /pages/posts/[postId]/comments/[commentId] and use router push with the following parameters

{
    pathname: '/posts/[postId]/comments/5',
    query: { postId: 1 }
}

The router sends to the browser the following path /posts/[postId]/comments/5?postId=1. The router doesn’t replace the parameter postId by the query property value.

My Next.js version is 10.0.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ijjkcommented, Oct 28, 2020

@souzantero happy to help, I’m gonna close this since it seems to be resolved.

0reactions
power-f-GODcommented, Jan 12, 2022

Hi, @ijjk . I get this error whenever I use href directly without interpolation. According to the examples in the link you sent above, it’s supposed to work, but this error ensues every time:

Unhandled Runtime Error
Error: The provided `href` (/orders/[order_id]) value is missing query values (order_id) to be interpolated properly. Read more: https://nextjs.org/docs/messages/href-interpolation-failed

I’m passing href directly like so…

<Link href={`/orders/some_uuid`}>Order</Link>

…and then it throws the unhandled runtime error above.

Kindly, what am I doing wrong here? And how do I fix?

Thanks for your swift response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

$router.push({query: this.myarray}) not updating the URL · ...
replace ({ query: {} }) ! Replacing to existing name or path works, query doesn't. What am I doing wrong, guys? I want...
Read more >
How to use router.push for same path, different query ...
That's because it's not different from your current path. If the value of type is different it won't give you NavigationDuplicated error.
Read more >
Routing in Vue3: Navigating the Options
To start out, you'll need to create an array of objects that describe each route. A route typically has a name, a path,...
Read more >
Location
A service that applications can use to interact with a browser's URL. ... unknown : The current value of the history.state object. ......
Read more >
Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
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