diff --git a/packages/react-router/index.ts b/packages/react-router/index.ts index 993dc1f048..db98fbade5 100644 --- a/packages/react-router/index.ts +++ b/packages/react-router/index.ts @@ -78,6 +78,8 @@ export type { NavigateOptions, Navigator, NonIndexRouteObject, + PatchRoutesOnNavigationFunction, + PatchRoutesOnNavigationFunctionArgs, RouteMatch, RouteObject, } from "./lib/context"; @@ -93,7 +95,6 @@ export type { RouterProps, RouterProviderProps, RoutesProps, - PatchRoutesOnNavigationFunction as PatchRoutesOnNavigationFunction, } from "./lib/components"; export type { NavigateFunction } from "./lib/hooks"; export { diff --git a/packages/react-router/lib/components.tsx b/packages/react-router/lib/components.tsx index fc5c3f5462..547bfdc33f 100644 --- a/packages/react-router/lib/components.tsx +++ b/packages/react-router/lib/components.tsx @@ -23,7 +23,6 @@ import type { } from "./router/router"; import { createRouter } from "./router/router"; import type { - AgnosticPatchRoutesOnNavigationFunction, DataStrategyFunction, LazyRouteFunction, TrackedPromise, @@ -35,6 +34,7 @@ import type { IndexRouteObject, Navigator, NonIndexRouteObject, + PatchRoutesOnNavigationFunction, RouteMatch, RouteObject, ViewTransitionContextObject, @@ -130,9 +130,6 @@ export function mapRouteProperties(route: RouteObject) { return updates; } -export interface PatchRoutesOnNavigationFunction - extends AgnosticPatchRoutesOnNavigationFunction {} - /** * @category Routers */ diff --git a/packages/react-router/lib/context.ts b/packages/react-router/lib/context.ts index 6e72c96576..259f10ee2a 100644 --- a/packages/react-router/lib/context.ts +++ b/packages/react-router/lib/context.ts @@ -13,6 +13,8 @@ import type { import type { AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, + AgnosticPatchRoutesOnNavigationFunction, + AgnosticPatchRoutesOnNavigationFunctionArgs, AgnosticRouteMatch, LazyRouteFunction, TrackedPromise, @@ -74,6 +76,12 @@ export interface RouteMatch< export interface DataRouteMatch extends RouteMatch {} +export type PatchRoutesOnNavigationFunctionArgs = + AgnosticPatchRoutesOnNavigationFunctionArgs; + +export type PatchRoutesOnNavigationFunction = + AgnosticPatchRoutesOnNavigationFunction; + export interface DataRouterContextObject // Omit `future` since those can be pulled from the `router` // `NavigationContext` needs future since it doesn't have a `router` in all cases diff --git a/packages/react-router/lib/dom/lib.tsx b/packages/react-router/lib/dom/lib.tsx index f036ace794..d4073c86f4 100644 --- a/packages/react-router/lib/dom/lib.tsx +++ b/packages/react-router/lib/dom/lib.tsx @@ -64,9 +64,12 @@ import { mergeRefs, usePrefetchBehavior, } from "./ssr/components"; -import type { PatchRoutesOnNavigationFunction } from "../components"; import { Router, mapRouteProperties } from "../components"; -import type { RouteObject, NavigateOptions } from "../context"; +import type { + RouteObject, + NavigateOptions, + PatchRoutesOnNavigationFunction, +} from "../context"; import { DataRouterContext, DataRouterStateContext, diff --git a/packages/react-router/lib/dom/ssr/fog-of-war.ts b/packages/react-router/lib/dom/ssr/fog-of-war.ts index eb85a0d19b..1f7541b288 100644 --- a/packages/react-router/lib/dom/ssr/fog-of-war.ts +++ b/packages/react-router/lib/dom/ssr/fog-of-war.ts @@ -1,5 +1,5 @@ import * as React from "react"; -import type { PatchRoutesOnNavigationFunction } from "../../components"; +import type { PatchRoutesOnNavigationFunction } from "../../context"; import type { Router as RemixRouter } from "../../router/router"; import { matchRoutes } from "../../router/utils"; import type { AssetsManifest } from "./entry"; diff --git a/packages/react-router/lib/router/utils.ts b/packages/react-router/lib/router/utils.ts index 06a4eee44e..f6396d2e5d 100644 --- a/packages/react-router/lib/router/utils.ts +++ b/packages/react-router/lib/router/utils.ts @@ -223,15 +223,21 @@ export interface DataStrategyFunction { (args: DataStrategyFunctionArgs): Promise>; } -export interface AgnosticPatchRoutesOnNavigationFunction< +export type AgnosticPatchRoutesOnNavigationFunctionArgs< + O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch -> { - (opts: { - path: string; - matches: M[]; - patch: (routeId: string | null, children: AgnosticRouteObject[]) => void; - }): void | Promise; -} +> = { + path: string; + matches: M[]; + patch: (routeId: string | null, children: O[]) => void; +}; + +export type AgnosticPatchRoutesOnNavigationFunction< + O extends AgnosticRouteObject = AgnosticRouteObject, + M extends AgnosticRouteMatch = AgnosticRouteMatch +> = ( + opts: AgnosticPatchRoutesOnNavigationFunctionArgs +) => void | Promise; /** * Function provided by the framework-aware layers to set any framework-specific