Skip to content

Instantly share code, notes, and snippets.

@alexengrig
Last active March 5, 2019 12:40
Show Gist options
  • Save alexengrig/115f9d6ced316c1f1e7e2b65365a9640 to your computer and use it in GitHub Desktop.
Save alexengrig/115f9d6ced316c1f1e7e2b65365a9640 to your computer and use it in GitHub Desktop.
Fix react-router problem with encoding the percent character in url
import React from 'react';
import { Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';
function FixedRouter({ history = createBrowserHistory(), children }) {
const originalPush = history.push;
// monkey patching
history.push = (url, ...args) =>
originalPush(
url.replace(/%/g, percent => encodeURI(encodeURI(percent))),
...args
);
return (
<Router history={history}>
{children}
</Router>
);
}
export default FixedRouter;
@alexengrig
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment