The useMatches hook returns the router's complete presented array of RouteMatch objects regardless of its caller's position in the component tree. The array can include still-loading descendants or matches below a pending/error/not-found render boundary.
Tip
If you only want the parent or child matches, then you can use the useParentMatches or the useChildMatches based on the selection you need.
The useMatches hook accepts a single optional argument, an options object.
import { useMatches } from '@tanstack/react-router'
function Component() {
const matches = useMatches()
// ^? [RouteMatch, RouteMatch, ...]
// ...
}