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.
The useLocation hook accepts an optional options object.
import { useLocation } from '@tanstack/react-router'
function Component() {
const location = useLocation()
// ^ ParsedLocation
// OR
const pathname = useLocation({
select: (location) => location.pathname,
})
// ^ string
// ...
}
import { useLocation } from '@tanstack/react-router'
function Component() {
const location = useLocation()
// ^ ParsedLocation
// OR
const pathname = useLocation({
select: (location) => location.pathname,
})
// ^ string
// ...
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.