Jose Simancas
Jose Simancas

Reputation: 19

How to change email string format, to a url format in reactjs?

i am trying to make work a GET method endpoint, in a proyect with react, where i need to send a email as parameter in the url, but it fails becouse is not in the correct format, example:

i am sending it, with axios library, like this:

const config = { url: ${url}/auth/forgot-password?username=${credentials}, headers, };

and its sending it like this: /auth/[email protected] but it works if i fix manualy the email format like this: /auth/forgot-password?username=jsimancas%40gmail.com

i mean i need to change the @ for a %40 to make it works. Does exist a method in react to fix the email format in a URL???

thanks in advance.

Upvotes: 0

Views: 632

Answers (2)

Jose Simancas
Jose Simancas

Reputation: 19

The encodeURIComponent() just worked perfect!!

Thanks to Derek Pollard for the answer! :)

Upvotes: 0

kyounghwan01
kyounghwan01

Reputation: 91

try this code

let email = '[email protected]'
console.log(email.replace('@', '%40'))

Upvotes: 1

Related Questions