Skip to main content
useLocation is a React hook that returns the current location object, which contains information about the current URL including pathname, search parameters, hash, and navigation state. It’s re-exported from react-router v7.
Always import useLocation from @tailor-platform/app-shell, not from react-router directly. AppShell manages its own router instance, and importing from the wrong package will cause the hook to return incorrect values.

Usage

Signature

Examples

Access Current Path

Access Query Parameters

Track Navigation State

Access state passed from the previous page:

Conditional Rendering Based on Path

Highlight Active Navigation Items

Sync UI with URL

Analytics and Tracking

Scroll Restoration

Working with Search Parameters

Using URLSearchParams

Updating Query Parameters

Comparison with Other Hooks

Common Patterns

Create a Custom Hook for Query Params

Preserve Query Params on Navigation

See Also