The useParentMatches hook returns all of the parent RouteMatch objects from the root down to the immediate parent of the current match in context. It does not include the current match, which can be obtained using the useMatch hook.
Important
If the router has pending matches and they are showing their pending component fallbacks, router.state.pendingMatches will used instead of router.state.matches.
The useParentMatches hook accepts an optional options object.
import { useParentMatches } from '@tanstack/react-router'
function Component() {
const parentMatches = useParentMatches()
// ^ [RouteMatch, RouteMatch, ...]
}
import { useParentMatches } from '@tanstack/react-router'
function Component() {
const parentMatches = useParentMatches()
// ^ [RouteMatch, RouteMatch, ...]
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.