On early versions we can go back to previous route using history.
history.goBack()
How I can achieve that with v6 of react-router-dom?
Try this approach
import { useNavigate } from 'react-router-dom'; function YourApp() { const navigate = useNavigate(); return ( <> <button onClick={() => navigate(-1)}>go back</button> </> ); }
1.4m articles
1.4m replys
5 comments
57.0k users