Skip to main content

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

To
required
The path to resolve. Can be a string or a partial Path object with pathname, search, and hash.
object
"route" | "path"
default:"\"route\""
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

Path
A Path object with the following properties:
string
The resolved pathname.
The search/query string (including the ? prefix).
string
The hash fragment (including the # prefix).

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 Path object instead of a string (unlike useHref)
  • The relative option 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