Solved!
import { createHistory } from 'history';
const history = useRouterHistory(createHistory)();
Object.assign(history, {
goSmartBack: () => {
if (window.history.length >= 1 && window.history.length <= 2) {
history.push('/');
} else {
history.goBack();
}
},
});
Most helpful comment
Solved!