useNavigate
react-router

useNavigate

useNavigate(): NavigateFunction

Returns a function that lets you navigate programmatically in the browser in response to user interactions or effects.

import { useNavigate } from "react-router";

function SomeComponent() {
  let navigate = useNavigate();
  return (
    <button
      onClick={() => {
        navigate(-1);
      }}
    />
  );
}

It's often better to use redirect in actions and loaders than this hook.

Docs and examples CC 4.0