Mutliple ways to navigate between pages in react using react router.
- React Router v6
useNavigate hook can be used.
import { useNavigate } from "react-router-dom" const Component = () => { let navigate = useNavigate(); navigate("/pathname", state: { someData }); }
- React Router v5
useHistory hook can be used.
import { useHistory } from "react-router-dom" const Component = () => { let history = useHistory(); history.push("/pathname"); }