Skip to content

useNavigateTo

useNavigateTo(): (path: string, options?: NavigateOptions) => void

Thin, typed wrapper around useNavigate() that accepts a resolved path (the output of .build()) along with the usual navigation options.

tsx
import { useNavigateTo } from "react-routes-forge/hooks";
import { PATHS } from "./paths";

function Component() {
  const navigateTo = useNavigateTo();

  return (
    <button onClick={() => navigateTo(PATHS.USERS.EDIT.build({ id: 42 }))}>
      Edit
    </button>
  );
}

navigateTo(PATHS.HOME, { replace: true });
navigateTo(PATHS.USERS.ROOT, { state: { from: "settings" } });

Released under the MIT License.