0

I've got a query inception problem.

I want to add this url

let url = "https://example.com/?1sCmRaAAAA72SeRa7wRVoddtJBRw&3u2500&4u1500&5m1&2e1&key=somekey-5o-Wj4&callback=none&token=106953"

to window.location as a query.

window.location = `/find/?photo=${url}`;

The result is unfortunately:

photo=https://example.com/?1sCmRaAAAA72SeRa7wRVoddtJBRw

so the &s are missing to the query what is need to get the image.

Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68
  • Sorry for asking this question. I'm pretty sure that it has been answered, but I just can't get the name for this problem to find it. – Philipp Mochine Jun 24 '18 at 10:08
  • 1
    [Here](https://stackoverflow.com/questions/16622504/escaping-ampersand-in-url) is what you are looking for – Pavlo Jun 24 '18 at 10:10
  • The solution to avoid this problem, is to use the backslash escape character. The backslash \ escape character turns special characters into string characters Example : The sequence \" inserts a double quote in a string: – Shruthi Jun 24 '18 at 10:28
  • @Pavlo that was the tip! encodeURIComponent() works perfect – Philipp Mochine Jun 24 '18 at 11:45
  • @Shadrix `encodeUri` works on the entire string, so you don't have to do it manually for `&` – Pavlo Jun 24 '18 at 11:54

0 Answers0