2

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

1 Answer 1

2

%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,
  });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.