Dealing with URIError in React Router v5 when manually inputting '%' in the URL

68 views Asked by At

I'm encountering an issue in my React app where manually inputting '%' in the URL (e.g., http://localhost:8207/%) results in a 400 Bad Request page with URIError: Failed to decode param.

I've tried adding console.logs at the top level of the app, but they are not executed so it looks like it doesn't even reach the code... Using react-router v5 but the same issue appears in an empty react-router v6 project, so the version is not the problem.

I've noticed that some large react sites like Twitter (https://twitter.com/%) also have this issue, while others like Dropbox (https://dropbox.com/%) and Netflix (https://netflix.com/%) seem to have resolved it.

How can I handle this scenario gracefully by redirecting to my not-found page instead of throwing an error?

0

There are 0 answers