Skip to main content

Summary

Returns a resolved Path 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 Path object with pathname, search, and hash
Supports relative paths with .. (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

Generating canonical URLs

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:

Notes

  • Always returns a complete Path object 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 pathname in to object uses fromPathname