Skip to main content

useCreateRouteMatches

info

The hook is used internally.

declare function useCreateRouteMatches(children: ReactNode, rootFallback: NonNullable<ReactNode> | null = null): RouteMatchObject[] | null;

type RouteMatchObject = Omit<RouteProps, 'children'> & {
children?: RouteMatchObject[];
fallback?: NonNullable<ReactNode> | null;
params: Params;
pathname: string;
pathnameBase?: string;
pattern: URLPattern;
segments: string[];
prefetch?: PrefetchFunction;
};

The useCreateRouteMatches hook resolves provided children (<Route /> components) against current path, returns array of matched Route components.

Fixes the language in the current pathname as well.

During Server-Side Rendering (SSR), it also triggers the prefetch functions for all matched routes.

The hook has 3 possible outcomes:

  • Returns matched Routes and sets the language to App Client;
  • In case of a fixed pathname (wrong/missing language or fix for the routePrefix) performs redirect;
  • Throws error when unexpected case happened.