useRouterState

useRouterState

Summary

A unified hook for reading router state: current (active) and in-flight (pending) locations, search params, params, matches, and navigation type.

import { unstable_useRouterState as useRouterState } from "react-router";

let { active, pending } = useRouterState();
active.params; // params from the leaf match
pending?.location.pathname; // populated during in-flight navigations

Signature

function useRouterState(): unstable_RouterState

Returns

The current router state with active and pending variants

Docs and examples CC 4.0
Edit