Skip to content

Commit

Permalink
fix(react-router): restore previous matchRoutes signature
Browse files Browse the repository at this point in the history
fixes #2164
  • Loading branch information
schiller-manuel committed Aug 21, 2024
1 parent cf70c67 commit cd0e3ac
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
AnyContext,
AnyRoute,
AnyRouteWithContext,
AnySearchSchema,
BeforeLoadContextOptions,
ErrorRouteComponent,
LoaderFnContext,
Expand Down Expand Up @@ -588,6 +589,8 @@ export function createRouter<
>(options)
}

type MatchRoutesOpts = { preload?: boolean; throwOnError?: boolean }

export class Router<
in out TRouteTree extends AnyRoute,
in out TTrailingSlashOption extends TrailingSlashOption,
Expand Down Expand Up @@ -950,10 +953,51 @@ export class Router<
return this.routesById as Record<string, AnyRoute>
}

matchRoutes = (
/**
@deprecated use the following signature instead
```ts
matchRoutes (
next: ParsedLocation,
opts?: { preload?: boolean; throwOnError?: boolean },
): Array<AnyRouteMatch>;
```
*/
public matchRoutes(
pathname: string,
locationSearch: AnySearchSchema,
opts?: MatchRoutesOpts,
): Array<AnyRouteMatch>
public matchRoutes(
next: ParsedLocation,
opts?: MatchRoutesOpts,
): Array<AnyRouteMatch>

public matchRoutes(
pathnameOrNext: string | ParsedLocation,
locationSearchOrOpts?:
| AnySearchSchema
| { preload?: boolean; throwOnError?: boolean },
opts?: { preload?: boolean; throwOnError?: boolean },
) {
if (typeof pathnameOrNext === 'string') {
// Return an array of AnyRouteMatch
return this.matchRoutesInternal(
{
pathname: pathnameOrNext,
search: locationSearchOrOpts,
} as ParsedLocation,
opts,
)
}
else {
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts)
}
}

private matchRoutesInternal(
next: ParsedLocation,
opts?: { preload?: boolean; throwOnError?: boolean },
): Array<AnyRouteMatch> => {
): Array<AnyRouteMatch> {
let routeParams: Record<string, string> = {}

const foundRoute = this.flatRoutes.find((route) => {
Expand Down

0 comments on commit cd0e3ac

Please sign in to comment.