Hooks

useRoutes

Warning: This is may change before v1 is released

Creates a <Router /> with all provided routes, represented as an array of objects.

useRoutes(
[
{ path: "/", element: <Home /> },
{ path: "/about", element: <About /> },
{ path: "/articles", element: <Articles /> },
],
<FourOhFour />
);

useParams

Returns an object with key/value pairs associated with matched params.

// On route "/user/:name"
const { name } = useParams();

useNavigate

Returns a navigate function that enables programmatical navigation.

const navigate = useNavigate();

useLocation

Note: This is mostly provided for compatibility, you should be able to use window.location directly.

Returns the current location object properties.

const { pathname, hash, origin, ...rest } = useLocation();