useNavigate

useNavigate

Summary

Reference Documentation ↗

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 ActionFunction and LoaderFunction than this hook.

Signature

useNavigate(): NavigateFunction
Docs and examples CC 4.0