-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link and router query should automatically replace dynamic route parts #14959
Milestone
Comments
HitoriSensei
pushed a commit
to HitoriSensei/next.js
that referenced
this issue
Sep 26, 2020
This corrects/makes sure interpolating dynamic route values for `href` works correctly. This provides an alternative approach to building the `href` value with `next/link` so that you don't need to worry about encoding the params manually. Closes: vercel#13473 Closes: vercel#14959 Closes: vercel#16771
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Feature request
It would be great if the
Link
component was smart enough to replace dynamic route parts inpathname
automatically based on thequery
when using the url-object form ofhref
:Currently this renders
<a href="/posts/[id]?id=1&anotherParam=2">...</a>
which is functional but odd (also it breaks getServerSideProps et alparams
). So in order to make this work, I have to replace the dynamic parts inpathname
with matchingquery
params and stringify asearch
to construct anas
prop manually.The same issue concerns
router.push
androuter.replace
.Another example to illustrate the issue where it's quite tedious to construct the
as
prop would be to replace one or more query params of the current (unknown) route to link to another locale:Describe the solution you'd like
If this was handled out of the box, using
{ pathname: "/posts/[id]", query: { id: 1, anotherParam: 2 } }
would create the URL/posts/1?anotherParam=2
and the link would be<a href="/posts/1?anotherParam=2">...</a>
.I think adding this behavior would be a non-breaking change without any new API. It would be a big improvement over the current behavior. I also don't think that it would be at odds with a more sophisticated approach described in #8207
Describe alternatives you've considered
An alternative could be to explicitly add a
params
prop to the url object form, e.g.But I don't see the benefit of doing this.
P.S.: I already posted this suggestion in #8207 (comment) but as that RFC had a much bigger scope it probably wasn't the right place to discuss this.
The text was updated successfully, but these errors were encountered: