import { useHistory } from "react-router-dom"; function demo () { let history = useHistory(); const goToPreviousPath = () => { history.goBack() } return ( <div> <Button onClick={goToPreviousPath} > Back </Button> </div> ): }