useCurrentMatches
useCurrentMatches returns the route matches for the current location.
Import
import { useCurrentMatches } from "@solidjs/router";Type
interface RouteMatch extends PathMatch { route: RouteDescription;}
function useCurrentMatches(): () => RouteMatch[];Parameters
useCurrentMatches takes no arguments.
Return value
- Type:
() => RouteMatch[]
Returns the route matches accessor.
Behavior
- Matches are computed from route branches and the current pathname, after applying
transformUrlwhen configured. - The accessor updates when the current location changes.
Examples
Basic usage
import { createMemo } from "solid-js";import { useCurrentMatches } from "@solidjs/router";
function Breadcrumbs() { const matches = useCurrentMatches(); const breadcrumbs = createMemo(() => matches().map((match) => match.route.info?.breadcrumb) );
return <>{breadcrumbs().join(" / ")}</>;}