Skip to main content

useHref

Resolves a URL against the current location.

Signature

Parameters

To
required
The path to resolve. Can be a string or a partial location object.
'route' | 'path'
Controls relative routing logic. Defaults to "route" so routing is relative to the route tree. Set to "path" to make relative routing operate against path segments.

Returns

string
The resolved href string that can be used in an anchor tag or for other purposes.

Usage

Basic usage

Resolve relative paths

With location object

Common Patterns

QR code generation

Social sharing

Canonical URLs

Copy to clipboard

Relative routing types

With basename

Type Safety

Important Notes

Must be inside Router

useHref must be called within a <Router> component context:
For in-app navigation, prefer <Link> over using useHref with <a> tags:
Use useHref when you need the URL string for purposes other than navigation (sharing, QR codes, etc.).