router-query/repository-context/docs/router/api/router/useLocationHook.md
Version 663282b0ebbc.bb1 · MIT. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.
← Return to resource and package checksum
id: useLocationHook title: useLocation hook
The useLocation method is a hook that returns the current location object. This hook is useful for when you want to perform some side effect whenever the current location changes.
useLocation options
The useLocation hook accepts an optional options object.
opts.select option
- Type:
(state: ParsedLocationType) => TSelected - Optional
- If supplied, this function will be called with the
locationobject and the return value will be returned fromuseLocation.
useLocation returns
- The current
locationobject orTSelectedif aselectfunction is provided.
Examples
import { useLocation } from '@tanstack/react-router'
function Component() {
const location = useLocation()
// ^ ParsedLocation
// OR
const pathname = useLocation({
select: (location) => location.pathname,
})
// ^ string
// ...
}