yarn add history
import createHistory from 'history/createBrowserHistory';
export const history = createHistory();
<Router history={history}>
above code has warning so I changed it to this:
import { createBrowserHistory } from 'history';
export const history = createBrowserHistory();
BrowserRouter does not refresh after pushing with history so we should not import BrowserRouter from react-router-dom. we can import Router liks this:
import {Router, Route, Switch} from 'react-router-dom';
so we can wrap all of it in this:
yarn add history
import { createBrowserHistory } from 'history';
export const history = createBrowserHistory();
<Router history={history}>