The useMatches hook returns all of the RouteMatch objects from the router regardless of its callers position in the React component tree.
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, ...]
// ...
}
import { useMatches } from '@tanstack/react-router'
function Component() {
const matches = useMatches()
// ^? [RouteMatch, RouteMatch, ...]
// ...
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.