typescript react history go to previous page if exists code example
Example 1: react router last page
import { useHistory } from "react-router-dom";
function demo () {
let history = useHistory();
const goToPreviousPath = () => {
history.goBack()
}
return (
<div>
<Button
onClick={goToPreviousPath}
>
Back
</Button>
</div>
):
}
Example 2: how to go back in usinsg router hisotry
this.props.history.goBack(); //react-router (v4)