0

This is how I use router.query to get hold of the token that I need so that the user can update one's password. But when I e.g. print it to my hidden, it removes e.g. + and / etc.

I have tried to use encodeURIComponent to be able to solve the problem but it seems that it does not help in any way.

Token in url: CfDJ8Pf5H7I0LCJKuxB2jm5JU0EGFK7KC45kBnwAkPgbAO2+kPijFxxb5CW6wyE/ft74if6V5ouwrHE8wK8Vz2ZTlc0s82XwwC9rZD4CvA5UQnv9eyL0UxdCqNEVjlusntVTn4d+41nLwlADsSqhLYajkRHwSHx8DhvJZa9OBGX9iYpR2EXnBOMa1EZcvvKDhEX+9+pgOtW8shPAo4p+F5nG0C+qnK4s5u/rO5vgA7SFhEkWS

When I get it into the content of the page, it looks like this. After it is displayed on the page.

CfDJ8Pf5H7I0LCJKuxB2jm5JU0EGFK7KC45kBnwAkPgbAO2 kPijFxxb5CW6wyE/ft74if6V5ouwrHE8wK8Vz2ZTlc0s82XwwC9rZD4CvA5UQnv9eyL0UxdCqNEVjlusntVTn4d 41nLwlADsSqhLYajkRHwSHx8DhvJZa9OBGX9iYpR2EXnBOMa1EZcvvKDhEX 9 pgOtW8shPAo4p F5nG0C qnK4s5u/rO5vgA7SFhEkWS

enter image description here

I have tried to do this:
encodeURIComponent(String(router.query["token"]))

And i have try

router.query["token"]

How can it be that you change the sign from + to between spaces or something completely different.

  • `...Tn4d 41nL...` there is space between `d` and `4` so you will see `space` as `%20` because browser encodes the url. So you can decode the string before printing on the screen. – Sedat Polat Jan 18 '23 at 16:03

1 Answers1

0

You can decode the encodded string before printing on the page.

const encoddedUri = encodeURI("https://example.com/asdasd asdasd");
console.log(`encoded URI: ${encoddedUri}`);
console.log(`Decoded URI: ${decodeURI(encoddedUri)}`);
Sedat Polat
  • 1,631
  • 2
  • 18
  • 28