Skip to main content

matchRoutes

declare function matchRoutes(manifest: RouteManifest, pathname: string): MatchResult;

type MatchResult = { type: 'match'; matchedRoutes: RouteMatchObject[]; language: string } | { type: 'redirect'; to: string };

Matches a RouteManifest against a pathname and returns the result as a value — either the matched route chain (with the resolved language) or a redirect target. Unlike the older createRouteMatches, it never throws to signal a redirect, so callers can branch without a try/catch.

import { createRouteManifest, matchRoutes } from '@archibald/core';

const manifest = createRouteManifest(children, { pathname });
const result = matchRoutes(manifest, pathname);

if (result.type === 'redirect') {
navigate(result.to, { replace: true });
} else {
render(result.matchedRoutes);
}

matchRoutes is a thin, non-throwing adapter over createRouteMatches and shares its exact matching and language-fixing behaviour. It powers the internal navigation hook as well as prefetching via useRoutePrefetch.