Reputation: 4192
I want to add data in url params after clicking on a button in next.js
function send() {
router.push(
{ pathname: "/", query: { n: "firstparam,secondparam" } },
undefined,
{
shallow: true
}
);
}
After clicnking, i get in the url:
site/?n=firstparam%2Csecondparam
So, nextjs instead of the ,
, adds %2C
. How to avoid all these signs and to get a valid url without using replace()?
like:site/?n=firstparam,secondparam
demo: https://codesandbox.io/s/vibrant-sinoussi-d9z77?file=/pages/index.js
Upvotes: 2
Views: 4302
Reputation: 35553
%2C
is the url encoding of ,
, what Next.js does is the proper thing to do, since ,
is not a valid character.
console.log(encodeURIComponent(','))
You can try to pass the url as string.
function send() {
router.push('/?n=firstparam,secondparam', undefined, {
shallow: true,
});
}
Upvotes: 2