DEV Community

Charles πŸ›°
Charles πŸ›°

Posted on

2 1

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)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay