router-query/repository-context/docs/router/api/router/useParentMatchesHook.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: useParentMatchesHook title: useParentMatches hook
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.
The result is derived from the router's current match presentation. During a navigation that may still be the previous presentation; after pending UI is published it is the destination's complete structurally matched lane.
useParentMatches options
The useParentMatches hook accepts an optional options object.
opts.select option
- Optional
(matches: RouteMatch[]) => TSelected- If supplied, this function will be called with the route matches and the return value will be returned from
useParentMatches. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
opts.structuralSharing option
- Type:
boolean - Optional
- Configures whether structural sharing is enabled for the value returned by
select. - See the Render Optimizations guide for more information.
useParentMatches returns
- If a
selectfunction is provided, the return value of theselectfunction. - If no
selectfunction is provided, an array ofRouteMatchobjects.
Examples
import { useParentMatches } from '@tanstack/react-router'
function Component() {
const parentMatches = useParentMatches()
// ^ [RouteMatch, RouteMatch, ...]
}