useResolvedPath
Resolves the pathname of the given to value against the current location. Similar to useHref, but returns a Path object instead of a string.
Parameters
The path to resolve. Can be a string or a partial
Path object with pathname, search, and hash.Defaults to
"route" so routing is relative to the route tree.Set to "path" to make relative routing operate against path segments instead."route"- Relative to the route hierarchy"path"- Relative to the URL path
Return Value
Type Declaration
Usage Examples
Basic Path Resolution
Relative Path Resolution
Resolving Path Objects
Route vs Path Relative
Common Patterns
Building Complex URLs
Checking Active Paths
Prefetching Resources
Form Actions
Generating Breadcrumbs
Conditional Navigation
Advanced Usage
Resolving Against Different Base Paths
Type-Safe Path Resolution
Comparison with useHref
Notes
- Returns a
Pathobject instead of a string (unlikeuseHref) - The
relativeoption defaults to"route"for route-based resolution - Must be used within a
<Router>component - Available in all React Router modes (Declarative, Data, and Framework)
- The pathname is resolved against the current location
- If a basename is configured in the router, it’s handled automatically
Related
useHref- Similar hook that returns a stringuseLocation- Get the current locationuseNavigate- Navigate programmaticallymatchPath- Match a path pattern