I'm having an issue with react router encoding spaces but not ampersands. So localhost:8080/you & me
is encoded to be localhost:8080/you%20&%20me
instead of localhost:8080/you%20%26%20me
and I'm using a wonky hack to decode then re-encode everything. I was wondering if anyone can remend a better solution.
I'm having an issue with react router encoding spaces but not ampersands. So localhost:8080/you & me
is encoded to be localhost:8080/you%20&%20me
instead of localhost:8080/you%20%26%20me
and I'm using a wonky hack to decode then re-encode everything. I was wondering if anyone can remend a better solution.
you-me
) instead, but not sure if it's possible for you.
– Emile Bergeron
Commented
Jul 9, 2019 at 19:58
some.api/my/get/route?page=2&rows=20
The ?
and =
and &
are reserved for url parameters. You should rethink how to define your routes where you dont need special characters (non alphanumeric).
– John Ruddell
Commented
Jul 9, 2019 at 20:24
push
function is oblivious about the rules and escaping and normalization of URLs. I have seen cases where I "fixed" the URL to be properly encoded, and it broke the router - I had to make it wrong to make it work.
– doug65536
Commented
Mar 25 at 20:36
Do not use non-alphanumeric characters in the URL. Some characters like &
, /
, ?
, and =
have special meanings in URLs. Even though react-router
does not throw an error when you create a route ponent with a &
in the url, as you have noticed, you'll end up with wonky behavior. It's best practice to avoid strange edge cases. You can read more about allowed characters in a url here.
As a workaround, you can achieve nearly the same URL with localhost:8080/you-and-me
. This is a safe url without spaces and special characters. It's also human readable, which anything with spaces wouldn't be easily readable as it would be encoded.