I need to set a number of URL parameters, which also need to include a special character $
Currently I am using .set()
to create and set these parameter values:
const myUrl = new URL("http://www.example.com/?");
let params = new URLSearchParams();
params.set('$param1', '60');
params.set('$param2', '100');
I understand that I need to use encodeURI()
to ensure that I get $
in the URL and not %24
- but at what stage do I do this?
If I do this when I stringify and add the params to the URL they have already been converted.
myUrl.search = encodeURI(params.toString());
// Outputs: http://www.example.com/?%24param1=60&%24param2=100
// Desired: http://www.example.com/?$param1=60&$param2=100