Summary
Returns a resolvedPath object relative to the given pathname. Handles relative navigation like .. and . similar to how file system paths work.
Useful for programmatically resolving paths before navigation or for building URLs.
Signature
Parameters
To
required
The path to resolve. Can be:
- A string path (e.g.,
"../users","/dashboard") - A partial
Pathobject withpathname,search, andhash
.. (parent) and . (current).string
default:"/"
The pathname to resolve from. Acts as the “current location” for relative path resolution.
Path Object
Returns
Path
A
Path object with resolved pathname, search, and hash properties.Examples
Absolute paths
Relative paths
Parent directory navigation
With search and hash
Complex relative paths
Common Use Cases
Building navigation URLs
Resolving links before navigation
Generating canonical URLs
Breadcrumb navigation
Validating relative paths
Path Resolution Rules
Absolute paths
Paths starting with/ are absolute and ignore fromPathname:
Relative paths
Paths without leading/ are relative to fromPathname:
Parent directory (..)
Each.. goes up one directory level:
Current directory (.)
Stays at the current level:Empty paths
Search and Hash Handling
Search params are preserved
Hash fragments are preserved
Combined
Edge Cases
Too many parent references
Trailing slashes
Empty pathname
Type Safety
TypeScript ensures proper types:Performance
Path resolution is a synchronous, fast operation suitable for use in render functions:Related Functions
generatePath- Generate paths with parametersmatchPath- Match paths against patternsuseResolvedPath- Hook version with route context
Notes
- Always returns a complete
Pathobject with all three properties - Search params should include the leading
? - Hash fragments should include the leading
# - Root path is
/and cannot be navigated above - Relative paths are resolved similar to file system paths
- Empty
pathnameintoobject usesfromPathname