If you're creating a hyperlink with query params, and those param values
can have plus signs, it's important to encode them values. We do this with
encodeURIComponent
:
const email = `[email protected]`
const loginLink = `https://example.com/login?email=${encodeURIComponent(email)}`
window.open(loginLink)
If you skip this step and try to read the query parameters received by
'example.com' your email param value may be interpreted as with spaces instead
of pluses, i.e. jake [email protected]
. Per the docs:
Within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must be encoded. This method was used to make query URIs easier to pass in systems which did not allow spaces.