DEV Community

Charles 🛰
Charles 🛰

Posted on

How to navigate to the previos page with react-router v6

If found an approach that i do not like that much but it works

So if you want to return to the previous page using react router v6 you can do the following

import { useNavigate } from 'react-router-dom';

const Component = () => {
   const navigate = useNavigate()
  return(
   <div>
     <button onClick={() => navigate(-1)}
   </div>
)
}
Enter fullscreen mode Exit fullscreen mode

Hope someone found it helpful.

Lautaro

Top comments (0)