In React Router v5, you can programmatically navigate to a different route using the useHistory hook:
import { useHistory } from 'react-router-dom';
const MyComponent = () => {
  const history = useHistory();
  const navigate = () => {
    history.push('/new-route');
  };
  return <button onClick={navigate}>Go</button>;
};