@tanstack/router-core 1.168.1 → 1.168.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/index.d.cts +3 -1
- package/dist/cjs/invariant.cjs +8 -0
- package/dist/cjs/invariant.cjs.map +1 -0
- package/dist/cjs/invariant.d.cts +1 -0
- package/dist/cjs/load-matches.cjs +5 -4
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/manifest.cjs +18 -0
- package/dist/cjs/manifest.cjs.map +1 -0
- package/dist/cjs/manifest.d.cts +12 -1
- package/dist/cjs/new-process-route-tree.cjs +5 -4
- package/dist/cjs/new-process-route-tree.cjs.map +1 -1
- package/dist/cjs/path.cjs +0 -1
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/route.cjs +5 -4
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +0 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +0 -1
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +0 -1
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/headers.cjs +0 -1
- package/dist/cjs/ssr/headers.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs +0 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +0 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs +0 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.cjs +0 -1
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-client.cjs +13 -6
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +5 -4
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +0 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/utils.cjs +0 -1
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/invariant.d.ts +1 -0
- package/dist/esm/invariant.js +8 -0
- package/dist/esm/invariant.js.map +1 -0
- package/dist/esm/load-matches.js +5 -2
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/manifest.d.ts +12 -1
- package/dist/esm/manifest.js +17 -0
- package/dist/esm/manifest.js.map +1 -0
- package/dist/esm/new-process-route-tree.js +5 -2
- package/dist/esm/new-process-route-tree.js.map +1 -1
- package/dist/esm/route.js +5 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/ssr/ssr-client.js +13 -4
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +5 -2
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/package.json +1 -3
- package/src/index.ts +9 -1
- package/src/invariant.ts +3 -0
- package/src/load-matches.ts +10 -5
- package/src/manifest.ts +37 -1
- package/src/new-process-route-tree.ts +10 -5
- package/src/route.ts +8 -5
- package/src/ssr/ssr-client.ts +28 -13
- package/src/ssr/ssr-server.ts +8 -2
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -23
package/dist/esm/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","names":[],"sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { joinPaths, trimPathLeft, trimPathRight } from './path'\nimport { notFound } from './not-found'\nimport { redirect } from './redirect'\nimport { rootRouteId } from './root'\nimport type { LazyRoute } from './fileRoute'\nimport type { NotFoundError } from './not-found'\nimport type { RedirectFnRoute } from './redirect'\nimport type { NavigateOptions, ParsePathParams } from './link'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRouteMatch,\n MakePreValidationErrorHandlingRouteMatchUnion,\n MakeRouteMatchFromRoute,\n MakeRouteMatchUnion,\n RouteMatch,\n} from './Matches'\nimport type { RootRouteId } from './root'\nimport type { ParseRoute, RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport type { AnyRouter, Register, RegisteredRouter, SSROption } from './router'\nimport type { BuildLocationFn, NavigateFn } from './RouterProvider'\nimport type {\n Assign,\n Awaitable,\n Constrain,\n Expand,\n IntersectAssign,\n LooseAsyncReturnType,\n LooseReturnType,\n NoInfer,\n} from './utils'\nimport type {\n AnySchema,\n AnyStandardSchemaValidator,\n AnyValidator,\n AnyValidatorAdapter,\n AnyValidatorObj,\n DefaultValidator,\n ResolveSearchValidatorInput,\n ResolveValidatorOutput,\n StandardSchemaValidator,\n ValidatorAdapter,\n ValidatorFn,\n ValidatorObj,\n} from './validators'\nimport type { ValidateSerializableLifecycleResult } from './ssr/serializer/transformer'\n\nexport type AnyPathParams = {}\n\nexport type SearchSchemaInput = {\n __TSearchSchemaInput__: 'TSearchSchemaInput'\n}\n\nexport type AnyContext = {}\n\nexport interface RouteContext {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport interface StaticDataRouteOption {}\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> = {\n path: TPath\n id: TCustomId\n}\n\nexport type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult\n\nexport type SearchMiddlewareContext<TSearchSchema> = {\n search: TSearchSchema\n next: (newSearch: TSearchSchema) => TSearchSchema\n}\n\nexport type SearchMiddleware<TSearchSchema> = (\n ctx: SearchMiddlewareContext<TSearchSchema>,\n) => TSearchSchema\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type InferFullSearchSchemaInput<TRoute> = TRoute extends {\n types: {\n fullSearchSchemaInput: infer TFullSearchSchemaInput\n }\n}\n ? TFullSearchSchemaInput\n : {}\n\nexport type InferAllParams<TRoute> = TRoute extends {\n types: {\n allParams: infer TAllParams\n }\n}\n ? TAllParams\n : {}\n\nexport type InferAllContext<TRoute> = unknown extends TRoute\n ? TRoute\n : TRoute extends {\n types: {\n allContext: infer TAllContext\n }\n }\n ? TAllContext\n : {}\n\nexport type ResolveSearchSchemaFnInput<TSearchValidator> =\n TSearchValidator extends (input: infer TSearchSchemaInput) => any\n ? TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : ResolveSearchSchemaFn<TSearchValidator>\n : AnySchema\n\nexport type ResolveSearchSchemaInput<TSearchValidator> =\n TSearchValidator extends AnyStandardSchemaValidator\n ? NonNullable<TSearchValidator['~standard']['types']>['input']\n : TSearchValidator extends AnyValidatorAdapter\n ? TSearchValidator['types']['input']\n : TSearchValidator extends AnyValidatorObj\n ? ResolveSearchSchemaFnInput<TSearchValidator['parse']>\n : ResolveSearchSchemaFnInput<TSearchValidator>\n\nexport type ResolveSearchSchemaFn<TSearchValidator> = TSearchValidator extends (\n ...args: any\n) => infer TSearchSchema\n ? TSearchSchema\n : AnySchema\n\nexport type ResolveSearchSchema<TSearchValidator> =\n unknown extends TSearchValidator\n ? TSearchValidator\n : TSearchValidator extends AnyStandardSchemaValidator\n ? NonNullable<TSearchValidator['~standard']['types']>['output']\n : TSearchValidator extends AnyValidatorAdapter\n ? TSearchValidator['types']['output']\n : TSearchValidator extends AnyValidatorObj\n ? ResolveSearchSchemaFn<TSearchValidator['parse']>\n : ResolveSearchSchemaFn<TSearchValidator>\n\nexport type ResolveRequiredParams<TPath extends string, T> = {\n [K in ParsePathParams<TPath>['required']]: T\n}\n\nexport type ResolveOptionalParams<TPath extends string, T> = {\n [K in ParsePathParams<TPath>['optional']]?: T | undefined\n}\n\nexport type ResolveParams<\n TPath extends string,\n T = string,\n> = ResolveRequiredParams<TPath, T> & ResolveOptionalParams<TPath, T>\n\nexport type ParseParamsFn<in out TPath extends string, in out TParams> = (\n rawParams: Expand<ResolveParams<TPath>>,\n) => TParams extends ResolveParams<TPath, any>\n ? TParams\n : ResolveParams<TPath, any>\n\nexport type StringifyParamsFn<in out TPath extends string, in out TParams> = (\n params: TParams,\n) => ResolveParams<TPath>\n\nexport type ParamsOptions<in out TPath extends string, in out TParams> = {\n params?: {\n parse?: ParseParamsFn<TPath, TParams>\n stringify?: StringifyParamsFn<TPath, TParams>\n }\n\n /** \n @deprecated Use params.parse instead\n */\n parseParams?: ParseParamsFn<TPath, TParams>\n\n /** \n @deprecated Use params.stringify instead\n */\n stringifyParams?: StringifyParamsFn<TPath, TParams>\n}\n\ninterface RequiredStaticDataRouteOption {\n staticData: StaticDataRouteOption\n}\n\ninterface OptionalStaticDataRouteOption {\n staticData?: StaticDataRouteOption\n}\n\nexport type UpdatableStaticRouteOption = {} extends StaticDataRouteOption\n ? OptionalStaticDataRouteOption\n : RequiredStaticDataRouteOption\n\nexport type MetaDescriptor =\n | { charSet: 'utf-8' }\n | { title: string }\n | { name: string; content: string }\n | { property: string; content: string }\n | { httpEquiv: string; content: string }\n | { 'script:ld+json': LdJsonObject }\n | { tagName: 'meta' | 'link'; [name: string]: string }\n | Record<string, unknown>\n\ntype LdJsonObject = { [Key in string]: LdJsonValue } & {\n [Key in string]?: LdJsonValue | undefined\n}\ntype LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>\ntype LdJsonPrimitive = string | number | boolean | null\ntype LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray\n\nexport type RouteLinkEntry = {}\n\nexport type SearchValidator<TInput, TOutput> =\n | ValidatorObj<TInput, TOutput>\n | ValidatorFn<TInput, TOutput>\n | ValidatorAdapter<TInput, TOutput>\n | StandardSchemaValidator<TInput, TOutput>\n | undefined\n\nexport type AnySearchValidator = SearchValidator<any, any>\n\nexport type DefaultSearchValidator = SearchValidator<\n Record<string, unknown>,\n AnySchema\n>\n\nexport type RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\n\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type ContextReturnType<TContextFn> = unknown extends TContextFn\n ? TContextFn\n : LooseReturnType<TContextFn> extends never\n ? AnyContext\n : LooseReturnType<TContextFn>\n\nexport type ContextAsyncReturnType<TContextFn> = unknown extends TContextFn\n ? TContextFn\n : LooseAsyncReturnType<TContextFn> extends never\n ? AnyContext\n : LooseAsyncReturnType<TContextFn>\n\nexport type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<\n ContextReturnType<TRouteContextFn>,\n ContextAsyncReturnType<TBeforeLoadFn>\n>\n\nexport type ResolveRouteLoaderFn<TLoaderFn> = TLoaderFn extends {\n handler: infer THandler\n}\n ? THandler\n : TLoaderFn\n\nexport type RouteLoaderObject<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TParams = {},\n TLoaderDeps = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = {\n handler: RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n staleReloadMode?: LoaderStaleReloadMode\n}\n\nexport type ResolveLoaderData<TLoaderFn> = unknown extends TLoaderFn\n ? TLoaderFn\n : LooseAsyncReturnType<ResolveRouteLoaderFn<TLoaderFn>> extends never\n ? undefined\n : LooseAsyncReturnType<ResolveRouteLoaderFn<TLoaderFn>>\n\nexport type ResolveFullSearchSchema<\n TParentRoute extends AnyRoute,\n TSearchValidator,\n> = unknown extends TParentRoute\n ? ResolveValidatorOutput<TSearchValidator>\n : IntersectAssign<\n InferFullSearchSchema<TParentRoute>,\n ResolveValidatorOutput<TSearchValidator>\n >\n\nexport type ResolveFullSearchSchemaInput<\n TParentRoute extends AnyRoute,\n TSearchValidator,\n> = IntersectAssign<\n InferFullSearchSchemaInput<TParentRoute>,\n ResolveSearchValidatorInput<TSearchValidator>\n>\n\nexport type ResolveAllParamsFromParent<\n TParentRoute extends AnyRoute,\n TParams,\n> = Assign<InferAllParams<TParentRoute>, TParams>\n\nexport type RouteContextParameter<\n TParentRoute extends AnyRoute,\n TRouterContext,\n> = unknown extends TParentRoute\n ? TRouterContext\n : Assign<TRouterContext, InferAllContext<TParentRoute>>\n\nexport type BeforeLoadContextParameter<\n TParentRoute extends AnyRoute,\n TRouterContext,\n TRouteContextFn,\n> = Assign<\n RouteContextParameter<TParentRoute, TRouterContext>,\n ContextReturnType<TRouteContextFn>\n>\n\nexport type ResolveAllContext<\n TParentRoute extends AnyRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n> = Assign<\n BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>,\n ContextAsyncReturnType<TBeforeLoadFn>\n>\nexport interface FullSearchSchemaOption<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n> {\n search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n}\n\nexport interface RemountDepsOptions<\n in out TRouteId,\n in out TFullSearchSchema,\n in out TAllParams,\n in out TLoaderDeps,\n> {\n routeId: TRouteId\n search: TFullSearchSchema\n params: TAllParams\n loaderDeps: TLoaderDeps\n}\n\nexport type MakeRemountDepsOptionsUnion<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> =\n ParseRoute<TRouteTree> extends infer TRoute extends AnyRoute\n ? TRoute extends any\n ? RemountDepsOptions<\n TRoute['id'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps']\n >\n : never\n : never\n\nexport interface RouteTypes<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps,\n in out TLoaderFn,\n in out TChildren,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: ResolveValidatorOutput<TSearchValidator>\n searchSchemaInput: ResolveSearchValidatorInput<TSearchValidator>\n searchValidator: TSearchValidator\n fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>\n fullSearchSchemaInput: ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchValidator\n >\n params: TParams\n allParams: ResolveAllParamsFromParent<TParentRoute, TParams>\n routerContext: TRouterContext\n routeContext: ResolveRouteContext<TRouteContextFn, TBeforeLoadFn>\n routeContextFn: TRouteContextFn\n beforeLoadFn: TBeforeLoadFn\n allContext: ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n children: TChildren\n loaderData: ResolveLoaderData<TLoaderFn>\n loaderDeps: TLoaderDeps\n fileRouteTypes: TFileRouteTypes\n ssr: ResolveSSR<TSSR>\n allSsr: ResolveAllSSR<TParentRoute, TSSR>\n}\n\nexport type ResolveSSR<TSSR> = TSSR extends (...args: ReadonlyArray<any>) => any\n ? LooseReturnType<TSSR>\n : TSSR\n\nexport type ResolveAllSSR<\n TParentRoute extends AnyRoute,\n TSSR,\n> = unknown extends TParentRoute\n ? ResolveSSR<TSSR>\n : unknown extends TSSR\n ? TParentRoute['types']['allSsr']\n : ResolveSSR<TSSR>\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\nexport interface RouteExtensions<in out TId, in out TFullPath> {\n id: TId\n fullPath: TFullPath\n}\n\nexport type RouteLazyFn<TRoute extends AnyRoute> = (\n lazyFn: () => Promise<LazyRoute<TRoute>>,\n) => TRoute\n\nexport type RouteAddChildrenFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> = <const TNewChildren>(\n children: Constrain<\n TNewChildren,\n ReadonlyArray<AnyRoute> | Record<string, AnyRoute>\n >,\n) => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TNewChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport type RouteAddFileChildrenFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> = <const TNewChildren>(\n children: TNewChildren,\n) => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TNewChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport type RouteAddFileTypesFn<\n TRegister,\n TParentRoute extends AnyRoute,\n TPath extends string,\n TFullPath extends string,\n TCustomId extends string,\n TId extends string,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps extends Record<string, any>,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers,\n> = <TNewFileRouteTypes>() => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TNewFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport interface Route<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TChildren,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> extends RouteExtensions<TId, TFullPath> {\n path: TPath\n parentRoute: TParentRoute\n children?: TChildren\n types: RouteTypes<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n options: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n isRoot: TParentRoute extends AnyRoute ? true : false\n /** @internal */\n _componentsPromise?: Promise<void>\n /** @internal */\n _componentsLoaded?: boolean\n lazyFn?: () => Promise<\n LazyRoute<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n >\n /** @internal */\n _lazyPromise?: Promise<void>\n /** @internal */\n _lazyLoaded?: boolean\n rank: number\n to: TrimPathRight<TFullPath>\n init: (opts: { originalIndex: number }) => void\n update: (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) => this\n lazy: RouteLazyFn<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n addChildren: RouteAddChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n _addFileChildren: RouteAddFileChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n _addFileTypes: RouteAddFileTypesFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n /**\n * Create a redirect with `from` automatically set to this route's path.\n * Enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<TFullPath>\n}\n\nexport type AnyRoute = Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport type AnyRouteWithContext<TContext> = AnyRoute & {\n types: { allContext: TContext }\n}\n\nexport type RouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TCustomId extends string = string,\n TFullPath extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = AnyPathParams,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = BaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n> &\n UpdatableRouteOptions<\n NoInfer<TParentRoute>,\n NoInfer<TCustomId>,\n NoInfer<TFullPath>,\n NoInfer<TParams>,\n NoInfer<TSearchValidator>,\n NoInfer<TLoaderFn>,\n NoInfer<TLoaderDeps>,\n NoInfer<TRouterContext>,\n NoInfer<TRouteContextFn>,\n NoInfer<TBeforeLoadFn>\n >\n\nexport type RouteContextFn<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteId,\n> = (\n ctx: RouteContextOptions<\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteId\n >,\n) => any\n\nexport type FileBaseRouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TRemountDepsFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = ParamsOptions<TPath, TParams> &\n FilebaseRouteOptionsInterface<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TRemountDepsFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\nexport interface FilebaseRouteOptionsInterface<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TRemountDepsFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> {\n validateSearch?: Constrain<TSearchValidator, AnyValidator, DefaultValidator>\n\n shouldReload?:\n | boolean\n | ((\n match: LoaderFnContext<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >,\n ) => any)\n\n context?: Constrain<\n TRouteContextFn,\n (\n ctx: RouteContextOptions<\n TParentRoute,\n TParams,\n TRouterContext,\n TLoaderDeps,\n TId\n >,\n ) => any\n >\n\n ssr?: Constrain<\n TSSR,\n | undefined\n | SSROption\n | ((\n ctx: SsrContextOptions<TParentRoute, TSearchValidator, TParams>,\n ) => Awaitable<undefined | SSROption>)\n >\n\n // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: Constrain<\n TBeforeLoadFn,\n (\n ctx: BeforeLoadContextOptions<\n TRegister,\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TId,\n TServerMiddlewares,\n THandlers\n >,\n ) => ValidateSerializableLifecycleResult<\n TRegister,\n TParentRoute,\n TSSR,\n TBeforeLoadFn\n >\n >\n\n loaderDeps?: (\n opts: FullSearchSchemaOption<TParentRoute, TSearchValidator>,\n ) => TLoaderDeps\n\n remountDeps?: Constrain<\n TRemountDepsFn,\n (\n opt: RemountDepsOptions<\n TId,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>,\n TLoaderDeps\n >,\n ) => any\n >\n\n loader?: Constrain<\n TLoaderFn,\n | RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n | RouteLoaderObject<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n >\n}\n\nexport type BaseRouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = RoutePathOptions<TCustomId, TPath> &\n FileBaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n AnyContext,\n TSSR,\n TServerMiddlewares,\n THandlers\n > & {\n getParentRoute: () => TParentRoute\n }\n\nexport interface ContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TRouteId,\n> {\n abortController: AbortController\n preload: boolean\n params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n location: ParsedLocation\n /**\n * @deprecated Use `throw redirect({ to: '/somewhere' })` instead\n **/\n navigate: NavigateFn\n buildLocation: BuildLocationFn\n cause: 'preload' | 'enter' | 'stay'\n matches: Array<MakeRouteMatchUnion>\n routeId: TRouteId\n}\n\nexport interface RouteContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TRouterContext,\n in out TLoaderDeps,\n in out TRouteId,\n> extends ContextOptions<TParentRoute, TParams, TRouteId> {\n deps: TLoaderDeps\n context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>\n}\n\nexport interface SsrContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n> {\n params:\n | {\n status: 'success'\n value: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n }\n | { status: 'error'; error: unknown }\n search:\n | {\n status: 'success'\n value: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n }\n | { status: 'error'; error: unknown }\n location: ParsedLocation\n matches: Array<MakePreValidationErrorHandlingRouteMatchUnion>\n}\n\nexport interface BeforeLoadContextOptions<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TRouteId,\n in out TServerMiddlewares,\n in out THandlers,\n>\n extends\n ContextOptions<TParentRoute, TParams, TRouteId>,\n FullSearchSchemaOption<TParentRoute, TSearchValidator> {\n context: Expand<\n BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>\n >\n}\n\ntype AssetFnContextOptions<\n in out TRouteId,\n in out TFullPath,\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TSearchValidator,\n in out TLoaderFn,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps,\n> = {\n ssr?: {\n nonce?: string\n }\n matches: Array<\n RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n >\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n params: ResolveAllParamsFromParent<TParentRoute, TParams>\n loaderData?: ResolveLoaderData<TLoaderFn>\n}\n\nexport interface DefaultUpdatableRouteOptionsExtensions {\n component?: unknown\n errorComponent?: unknown\n notFoundComponent?: unknown\n pendingComponent?: unknown\n}\n\nexport interface UpdatableRouteOptionsExtensions extends DefaultUpdatableRouteOptionsExtensions {}\n\nexport interface UpdatableRouteOptions<\n in out TParentRoute extends AnyRoute,\n in out TRouteId,\n in out TFullPath,\n in out TParams,\n in out TSearchValidator,\n in out TLoaderFn,\n in out TLoaderDeps,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n>\n extends UpdatableStaticRouteOption, UpdatableRouteOptionsExtensions {\n /**\n * Options to control route matching behavior with runtime code.\n *\n * @experimental 🚧 this feature is subject to change\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType\n */\n skipRouteOnParseError?: {\n /**\n * If `true`, skip this route during matching if `params.parse` fails.\n *\n * Without this option, a `/$param` route could match *any* value for `param`,\n * and only later during the route lifecycle would `params.parse` run and potentially\n * show the `errorComponent` if validation failed.\n *\n * With this option enabled, the route will only match if `params.parse` succeeds.\n * If it fails, the router will continue trying to match other routes, potentially\n * finding a different route that works, or ultimately showing the `notFoundComponent`.\n *\n * @default false\n */\n params?: boolean\n /**\n * In cases where multiple routes would need to run `params.parse` during matching\n * to determine which route to pick, this priority number can be used as a tie-breaker\n * for which route to try first. Higher number = higher priority.\n *\n * @default 0\n */\n priority?: number\n }\n /**\n * If true, this route will be matched as case-sensitive\n *\n * @default false\n */\n caseSensitive?: boolean\n /**\n * If true, this route will be forcefully wrapped in a suspense boundary\n */\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preload?: boolean\n preloadStaleTime?: number\n preloadGcTime?: number\n search?: {\n middlewares?: Array<\n SearchMiddleware<\n ResolveFullSearchSchemaInput<TParentRoute, TSearchValidator>\n >\n >\n }\n /** \n @deprecated Use search.middlewares instead\n */\n preSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n /** \n @deprecated Use search.middlewares instead\n */\n postSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n onCatch?: (error: Error) => void\n onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onStay?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onLeave?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n headers?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<Record<string, string> | undefined>\n head?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<{\n links?: AnyRouteMatch['links']\n scripts?: AnyRouteMatch['headScripts']\n meta?: AnyRouteMatch['meta']\n styles?: AnyRouteMatch['styles']\n }>\n scripts?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<AnyRouteMatch['scripts']>\n codeSplitGroupings?: Array<\n Array<\n | 'loader'\n | 'component'\n | 'pendingComponent'\n | 'notFoundComponent'\n | 'errorComponent'\n >\n >\n}\n\nexport type RouteLoaderFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TId extends string = string,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> = (\n match: LoaderFnContext<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >,\n) => any\n\nexport type LoaderStaleReloadMode = 'background' | 'blocking'\n\nexport type RouteLoaderEntry<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TParams = {},\n TLoaderDeps = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> =\n | RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n | RouteLoaderObject<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n\nexport interface LoaderFnContext<\n in out TRegister = unknown,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TId extends string = string,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> {\n abortController: AbortController\n preload: boolean\n params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n deps: TLoaderDeps\n context: Expand<\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps\n /**\n * @deprecated Use `throw redirect({ to: '/somewhere' })` instead\n **/\n navigate: (opts: NavigateOptions<AnyRouter>) => Promise<void> | void\n // root route does not have a parent match\n parentMatchPromise: TId extends RootRouteId\n ? never\n : Promise<MakeRouteMatchFromRoute<TParentRoute>>\n cause: 'preload' | 'enter' | 'stay'\n route: AnyRoute\n}\n\nexport interface DefaultRootRouteOptionsExtensions {\n shellComponent?: unknown\n}\n\nexport interface RootRouteOptionsExtensions extends DefaultRootRouteOptionsExtensions {}\n\nexport interface RootRouteOptions<\n TRegister = unknown,\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n>\n extends\n Omit<\n RouteOptions<\n TRegister,\n any, // TParentRoute\n RootRouteId, // TId\n RootRouteId, // TCustomId\n '', // TFullPath\n '', // TPath\n TSearchValidator,\n {}, // TParams\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'params'\n >,\n RootRouteOptionsExtensions {}\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySchema\n TFullSearchSchema: AnySchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport type RouteTypesById<TRouter extends AnyRouter, TId> = RouteById<\n TRouter['routeTree'],\n TId\n>['types']\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\n/**\n * @deprecated Use `ErrorComponentProps` instead.\n */\nexport type ErrorRouteProps = {\n error: unknown\n info?: { componentStack: string }\n reset: () => void\n}\n\nexport type ErrorComponentProps<TError = Error> = {\n error: TError\n info?: { componentStack: string }\n reset: () => void\n}\n\nexport type NotFoundRouteProps = {\n data?: unknown\n isNotFound: boolean\n routeId: RouteIds<RegisteredRouter['routeTree']>\n}\n\nexport class BaseRoute<\n in out TRegister = Register,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TPath extends string = '/',\n in out TFullPath extends string = ResolveFullPath<TParentRoute, TPath>,\n in out TCustomId extends string = string,\n in out TId extends string = ResolveId<TParentRoute, TCustomId, TPath>,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> {\n isRoot: TParentRoute extends AnyRoute ? true : false\n options: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\n // The following properties are set up in this.init()\n parentRoute!: TParentRoute\n private _id!: TId\n private _path!: TPath\n private _fullPath!: TFullPath\n private _to!: TrimPathRight<TFullPath>\n\n public get to() {\n return this._to\n }\n\n public get id() {\n return this._id\n }\n\n public get path() {\n return this._path\n }\n\n public get fullPath() {\n return this._fullPath\n }\n\n // Optional\n children?: TChildren\n originalIndex?: number\n rank!: number\n lazyFn?: () => Promise<\n LazyRoute<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n >\n /** @internal */\n _lazyPromise?: Promise<void>\n /** @internal */\n _componentsPromise?: Promise<void>\n\n constructor(\n options?: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n\n if ((options as any)?.id && (options as any)?.path) {\n throw new Error(`Route cannot have both an 'id' and a 'path' option.`)\n }\n }\n\n types!: RouteTypes<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\n init = (opts: { originalIndex: number }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options.getParentRoute?.()\n\n if (isRoot) {\n this._path = rootRouteId as TPath\n } else if (!this.parentRoute) {\n invariant(\n false,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options?.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this._path = path as TPath\n this._id = id as TId\n this._fullPath = fullPath as TFullPath\n this._to = trimPathRight(fullPath) as TrimPathRight<TFullPath>\n }\n\n addChildren: RouteAddChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = (children) => {\n return this._addFileChildren(children) as any\n }\n\n _addFileChildren: RouteAddFileChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = (children) => {\n if (Array.isArray(children)) {\n this.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n this.children = Object.values(children) as TChildren\n }\n\n return this as any\n }\n\n _addFileTypes: RouteAddFileTypesFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = () => {\n return this as any\n }\n\n updateLoader = <TNewLoaderFn>(options: {\n loader: Constrain<\n TNewLoaderFn,\n RouteLoaderFn<\n TRegister,\n TParentRoute,\n TCustomId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n }) => {\n Object.assign(this.options, options)\n return this as unknown as BaseRoute<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TNewLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy: RouteLazyFn<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n > = (lazyFn) => {\n this.lazyFn = lazyFn\n return this\n }\n\n /**\n * Create a redirect with `from` automatically set to this route's fullPath.\n * Enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<TFullPath> = (opts) =>\n redirect({ from: this.fullPath, ...opts } as any)\n}\n\nexport class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {\n id: TId\n\n constructor({ id }: { id: TId }) {\n this.id = id\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n\n /**\n * Create a redirect with `from` automatically set to this route's path.\n * Enables relative redirects like `routeApi.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<RouteTypesById<TRouter, TId>['fullPath']> = (\n opts,\n ) => redirect({ from: this.id as string, ...opts } as any)\n}\n\nexport interface RootRoute<\n in out TRegister,\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> extends Route<\n TRegister,\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n> {}\n\nexport class BaseRootRoute<\n in out TRegister = Register,\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> extends BaseRoute<\n TRegister,\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n> {\n constructor(\n options?: RootRouteOptions<\n TRegister,\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n ) {\n super(options as any)\n }\n}\n\n//\n\nexport interface RouteLike {\n id: string\n isRoot?: boolean\n path?: string\n fullPath: string\n rank?: number\n parentRoute?: RouteLike\n children?: Array<RouteLike>\n options?: {\n caseSensitive?: boolean\n }\n}\n"],"mappings":";;;;;;AAkmDA,IAAa,YAAb,MAmBE;CA4BA,IAAW,KAAK;AACd,SAAO,KAAK;;CAGd,IAAW,KAAK;AACd,SAAO,KAAK;;CAGd,IAAW,OAAO;AAChB,SAAO,KAAK;;CAGd,IAAW,WAAW;AACpB,SAAO,KAAK;;CAoCd,YACE,SAkBA;eA8BM,SAA0C;AAChD,QAAK,gBAAgB,KAAK;GAE1B,MAAM,UAAU,KAAK;GAqBrB,MAAM,SA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,MAA6E;CAG3E,YAAY,EAAE,MAAmB;mBAIrB,SAAyB;AACnC,UAAO,SAAS;IAAE,SAAS,KAAK;IAAc,GAAG;IAAM,CAAC;;mBAWxD,SACG,SAAS;GAAE,MAAM,KAAK;GAAc,GAAG;GAAM,CAAQ;AAhBxD,OAAK,KAAK;;;AAqDd,IAAa,gBAAb,cAaU,UAmBR;CACA,YACE,SAYA;AACA,QAAM,QAAe"}
|
|
1
|
+
{"version":3,"file":"route.js","names":[],"sources":["../../src/route.ts"],"sourcesContent":["import { invariant } from './invariant'\nimport { joinPaths, trimPathLeft, trimPathRight } from './path'\nimport { notFound } from './not-found'\nimport { redirect } from './redirect'\nimport { rootRouteId } from './root'\nimport type { LazyRoute } from './fileRoute'\nimport type { NotFoundError } from './not-found'\nimport type { RedirectFnRoute } from './redirect'\nimport type { NavigateOptions, ParsePathParams } from './link'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRouteMatch,\n MakePreValidationErrorHandlingRouteMatchUnion,\n MakeRouteMatchFromRoute,\n MakeRouteMatchUnion,\n RouteMatch,\n} from './Matches'\nimport type { RootRouteId } from './root'\nimport type { ParseRoute, RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport type { AnyRouter, Register, RegisteredRouter, SSROption } from './router'\nimport type { BuildLocationFn, NavigateFn } from './RouterProvider'\nimport type {\n Assign,\n Awaitable,\n Constrain,\n Expand,\n IntersectAssign,\n LooseAsyncReturnType,\n LooseReturnType,\n NoInfer,\n} from './utils'\nimport type {\n AnySchema,\n AnyStandardSchemaValidator,\n AnyValidator,\n AnyValidatorAdapter,\n AnyValidatorObj,\n DefaultValidator,\n ResolveSearchValidatorInput,\n ResolveValidatorOutput,\n StandardSchemaValidator,\n ValidatorAdapter,\n ValidatorFn,\n ValidatorObj,\n} from './validators'\nimport type { ValidateSerializableLifecycleResult } from './ssr/serializer/transformer'\n\nexport type AnyPathParams = {}\n\nexport type SearchSchemaInput = {\n __TSearchSchemaInput__: 'TSearchSchemaInput'\n}\n\nexport type AnyContext = {}\n\nexport interface RouteContext {}\n\nexport type PreloadableObj = { preload?: () => Promise<void> }\n\nexport type RoutePathOptions<TCustomId, TPath> =\n | {\n path: TPath\n }\n | {\n id: TCustomId\n }\n\nexport interface StaticDataRouteOption {}\n\nexport type RoutePathOptionsIntersection<TCustomId, TPath> = {\n path: TPath\n id: TCustomId\n}\n\nexport type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult\n\nexport type SearchMiddlewareContext<TSearchSchema> = {\n search: TSearchSchema\n next: (newSearch: TSearchSchema) => TSearchSchema\n}\n\nexport type SearchMiddleware<TSearchSchema> = (\n ctx: SearchMiddlewareContext<TSearchSchema>,\n) => TSearchSchema\n\nexport type ResolveId<\n TParentRoute,\n TCustomId extends string,\n TPath extends string,\n> = TParentRoute extends { id: infer TParentId extends string }\n ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>\n : RootRouteId\n\nexport type InferFullSearchSchema<TRoute> = TRoute extends {\n types: {\n fullSearchSchema: infer TFullSearchSchema\n }\n}\n ? TFullSearchSchema\n : {}\n\nexport type InferFullSearchSchemaInput<TRoute> = TRoute extends {\n types: {\n fullSearchSchemaInput: infer TFullSearchSchemaInput\n }\n}\n ? TFullSearchSchemaInput\n : {}\n\nexport type InferAllParams<TRoute> = TRoute extends {\n types: {\n allParams: infer TAllParams\n }\n}\n ? TAllParams\n : {}\n\nexport type InferAllContext<TRoute> = unknown extends TRoute\n ? TRoute\n : TRoute extends {\n types: {\n allContext: infer TAllContext\n }\n }\n ? TAllContext\n : {}\n\nexport type ResolveSearchSchemaFnInput<TSearchValidator> =\n TSearchValidator extends (input: infer TSearchSchemaInput) => any\n ? TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : ResolveSearchSchemaFn<TSearchValidator>\n : AnySchema\n\nexport type ResolveSearchSchemaInput<TSearchValidator> =\n TSearchValidator extends AnyStandardSchemaValidator\n ? NonNullable<TSearchValidator['~standard']['types']>['input']\n : TSearchValidator extends AnyValidatorAdapter\n ? TSearchValidator['types']['input']\n : TSearchValidator extends AnyValidatorObj\n ? ResolveSearchSchemaFnInput<TSearchValidator['parse']>\n : ResolveSearchSchemaFnInput<TSearchValidator>\n\nexport type ResolveSearchSchemaFn<TSearchValidator> = TSearchValidator extends (\n ...args: any\n) => infer TSearchSchema\n ? TSearchSchema\n : AnySchema\n\nexport type ResolveSearchSchema<TSearchValidator> =\n unknown extends TSearchValidator\n ? TSearchValidator\n : TSearchValidator extends AnyStandardSchemaValidator\n ? NonNullable<TSearchValidator['~standard']['types']>['output']\n : TSearchValidator extends AnyValidatorAdapter\n ? TSearchValidator['types']['output']\n : TSearchValidator extends AnyValidatorObj\n ? ResolveSearchSchemaFn<TSearchValidator['parse']>\n : ResolveSearchSchemaFn<TSearchValidator>\n\nexport type ResolveRequiredParams<TPath extends string, T> = {\n [K in ParsePathParams<TPath>['required']]: T\n}\n\nexport type ResolveOptionalParams<TPath extends string, T> = {\n [K in ParsePathParams<TPath>['optional']]?: T | undefined\n}\n\nexport type ResolveParams<\n TPath extends string,\n T = string,\n> = ResolveRequiredParams<TPath, T> & ResolveOptionalParams<TPath, T>\n\nexport type ParseParamsFn<in out TPath extends string, in out TParams> = (\n rawParams: Expand<ResolveParams<TPath>>,\n) => TParams extends ResolveParams<TPath, any>\n ? TParams\n : ResolveParams<TPath, any>\n\nexport type StringifyParamsFn<in out TPath extends string, in out TParams> = (\n params: TParams,\n) => ResolveParams<TPath>\n\nexport type ParamsOptions<in out TPath extends string, in out TParams> = {\n params?: {\n parse?: ParseParamsFn<TPath, TParams>\n stringify?: StringifyParamsFn<TPath, TParams>\n }\n\n /** \n @deprecated Use params.parse instead\n */\n parseParams?: ParseParamsFn<TPath, TParams>\n\n /** \n @deprecated Use params.stringify instead\n */\n stringifyParams?: StringifyParamsFn<TPath, TParams>\n}\n\ninterface RequiredStaticDataRouteOption {\n staticData: StaticDataRouteOption\n}\n\ninterface OptionalStaticDataRouteOption {\n staticData?: StaticDataRouteOption\n}\n\nexport type UpdatableStaticRouteOption = {} extends StaticDataRouteOption\n ? OptionalStaticDataRouteOption\n : RequiredStaticDataRouteOption\n\nexport type MetaDescriptor =\n | { charSet: 'utf-8' }\n | { title: string }\n | { name: string; content: string }\n | { property: string; content: string }\n | { httpEquiv: string; content: string }\n | { 'script:ld+json': LdJsonObject }\n | { tagName: 'meta' | 'link'; [name: string]: string }\n | Record<string, unknown>\n\ntype LdJsonObject = { [Key in string]: LdJsonValue } & {\n [Key in string]?: LdJsonValue | undefined\n}\ntype LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>\ntype LdJsonPrimitive = string | number | boolean | null\ntype LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray\n\nexport type RouteLinkEntry = {}\n\nexport type SearchValidator<TInput, TOutput> =\n | ValidatorObj<TInput, TOutput>\n | ValidatorFn<TInput, TOutput>\n | ValidatorAdapter<TInput, TOutput>\n | StandardSchemaValidator<TInput, TOutput>\n | undefined\n\nexport type AnySearchValidator = SearchValidator<any, any>\n\nexport type DefaultSearchValidator = SearchValidator<\n Record<string, unknown>,\n AnySchema\n>\n\nexport type RoutePrefix<\n TPrefix extends string,\n TPath extends string,\n> = string extends TPath\n ? RootRouteId\n : TPath extends string\n ? TPrefix extends RootRouteId\n ? TPath extends '/'\n ? '/'\n : `/${TrimPath<TPath>}`\n : `${TPrefix}/${TPath}` extends '/'\n ? '/'\n : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`\n : never\n\nexport type TrimPath<T extends string> = '' extends T\n ? ''\n : TrimPathRight<TrimPathLeft<T>>\n\nexport type TrimPathLeft<T extends string> =\n T extends `${RootRouteId}/${infer U}`\n ? TrimPathLeft<U>\n : T extends `/${infer U}`\n ? TrimPathLeft<U>\n : T\n\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\n\nexport type ContextReturnType<TContextFn> = unknown extends TContextFn\n ? TContextFn\n : LooseReturnType<TContextFn> extends never\n ? AnyContext\n : LooseReturnType<TContextFn>\n\nexport type ContextAsyncReturnType<TContextFn> = unknown extends TContextFn\n ? TContextFn\n : LooseAsyncReturnType<TContextFn> extends never\n ? AnyContext\n : LooseAsyncReturnType<TContextFn>\n\nexport type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<\n ContextReturnType<TRouteContextFn>,\n ContextAsyncReturnType<TBeforeLoadFn>\n>\n\nexport type ResolveRouteLoaderFn<TLoaderFn> = TLoaderFn extends {\n handler: infer THandler\n}\n ? THandler\n : TLoaderFn\n\nexport type RouteLoaderObject<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TParams = {},\n TLoaderDeps = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = {\n handler: RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n staleReloadMode?: LoaderStaleReloadMode\n}\n\nexport type ResolveLoaderData<TLoaderFn> = unknown extends TLoaderFn\n ? TLoaderFn\n : LooseAsyncReturnType<ResolveRouteLoaderFn<TLoaderFn>> extends never\n ? undefined\n : LooseAsyncReturnType<ResolveRouteLoaderFn<TLoaderFn>>\n\nexport type ResolveFullSearchSchema<\n TParentRoute extends AnyRoute,\n TSearchValidator,\n> = unknown extends TParentRoute\n ? ResolveValidatorOutput<TSearchValidator>\n : IntersectAssign<\n InferFullSearchSchema<TParentRoute>,\n ResolveValidatorOutput<TSearchValidator>\n >\n\nexport type ResolveFullSearchSchemaInput<\n TParentRoute extends AnyRoute,\n TSearchValidator,\n> = IntersectAssign<\n InferFullSearchSchemaInput<TParentRoute>,\n ResolveSearchValidatorInput<TSearchValidator>\n>\n\nexport type ResolveAllParamsFromParent<\n TParentRoute extends AnyRoute,\n TParams,\n> = Assign<InferAllParams<TParentRoute>, TParams>\n\nexport type RouteContextParameter<\n TParentRoute extends AnyRoute,\n TRouterContext,\n> = unknown extends TParentRoute\n ? TRouterContext\n : Assign<TRouterContext, InferAllContext<TParentRoute>>\n\nexport type BeforeLoadContextParameter<\n TParentRoute extends AnyRoute,\n TRouterContext,\n TRouteContextFn,\n> = Assign<\n RouteContextParameter<TParentRoute, TRouterContext>,\n ContextReturnType<TRouteContextFn>\n>\n\nexport type ResolveAllContext<\n TParentRoute extends AnyRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n> = Assign<\n BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>,\n ContextAsyncReturnType<TBeforeLoadFn>\n>\nexport interface FullSearchSchemaOption<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n> {\n search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n}\n\nexport interface RemountDepsOptions<\n in out TRouteId,\n in out TFullSearchSchema,\n in out TAllParams,\n in out TLoaderDeps,\n> {\n routeId: TRouteId\n search: TFullSearchSchema\n params: TAllParams\n loaderDeps: TLoaderDeps\n}\n\nexport type MakeRemountDepsOptionsUnion<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> =\n ParseRoute<TRouteTree> extends infer TRoute extends AnyRoute\n ? TRoute extends any\n ? RemountDepsOptions<\n TRoute['id'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps']\n >\n : never\n : never\n\nexport interface RouteTypes<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps,\n in out TLoaderFn,\n in out TChildren,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: ResolveValidatorOutput<TSearchValidator>\n searchSchemaInput: ResolveSearchValidatorInput<TSearchValidator>\n searchValidator: TSearchValidator\n fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>\n fullSearchSchemaInput: ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchValidator\n >\n params: TParams\n allParams: ResolveAllParamsFromParent<TParentRoute, TParams>\n routerContext: TRouterContext\n routeContext: ResolveRouteContext<TRouteContextFn, TBeforeLoadFn>\n routeContextFn: TRouteContextFn\n beforeLoadFn: TBeforeLoadFn\n allContext: ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n children: TChildren\n loaderData: ResolveLoaderData<TLoaderFn>\n loaderDeps: TLoaderDeps\n fileRouteTypes: TFileRouteTypes\n ssr: ResolveSSR<TSSR>\n allSsr: ResolveAllSSR<TParentRoute, TSSR>\n}\n\nexport type ResolveSSR<TSSR> = TSSR extends (...args: ReadonlyArray<any>) => any\n ? LooseReturnType<TSSR>\n : TSSR\n\nexport type ResolveAllSSR<\n TParentRoute extends AnyRoute,\n TSSR,\n> = unknown extends TParentRoute\n ? ResolveSSR<TSSR>\n : unknown extends TSSR\n ? TParentRoute['types']['allSsr']\n : ResolveSSR<TSSR>\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\nexport interface RouteExtensions<in out TId, in out TFullPath> {\n id: TId\n fullPath: TFullPath\n}\n\nexport type RouteLazyFn<TRoute extends AnyRoute> = (\n lazyFn: () => Promise<LazyRoute<TRoute>>,\n) => TRoute\n\nexport type RouteAddChildrenFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> = <const TNewChildren>(\n children: Constrain<\n TNewChildren,\n ReadonlyArray<AnyRoute> | Record<string, AnyRoute>\n >,\n) => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TNewChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport type RouteAddFileChildrenFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> = <const TNewChildren>(\n children: TNewChildren,\n) => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TNewChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport type RouteAddFileTypesFn<\n TRegister,\n TParentRoute extends AnyRoute,\n TPath extends string,\n TFullPath extends string,\n TCustomId extends string,\n TId extends string,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps extends Record<string, any>,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers,\n> = <TNewFileRouteTypes>() => Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TNewFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n>\n\nexport interface Route<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TPath extends string,\n in out TFullPath extends string,\n in out TCustomId extends string,\n in out TId extends string,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps extends Record<string, any>,\n in out TLoaderFn,\n in out TChildren,\n in out TFileRouteTypes,\n in out TSSR,\n in out TServerMiddlewares,\n in out THandlers,\n> extends RouteExtensions<TId, TFullPath> {\n path: TPath\n parentRoute: TParentRoute\n children?: TChildren\n types: RouteTypes<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n options: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n isRoot: TParentRoute extends AnyRoute ? true : false\n /** @internal */\n _componentsPromise?: Promise<void>\n /** @internal */\n _componentsLoaded?: boolean\n lazyFn?: () => Promise<\n LazyRoute<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n >\n /** @internal */\n _lazyPromise?: Promise<void>\n /** @internal */\n _lazyLoaded?: boolean\n rank: number\n to: TrimPathRight<TFullPath>\n init: (opts: { originalIndex: number }) => void\n update: (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) => this\n lazy: RouteLazyFn<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n addChildren: RouteAddChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n _addFileChildren: RouteAddFileChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n _addFileTypes: RouteAddFileTypesFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n /**\n * Create a redirect with `from` automatically set to this route's path.\n * Enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<TFullPath>\n}\n\nexport type AnyRoute = Route<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport type AnyRouteWithContext<TContext> = AnyRoute & {\n types: { allContext: TContext }\n}\n\nexport type RouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TCustomId extends string = string,\n TFullPath extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = AnyPathParams,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = BaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n> &\n UpdatableRouteOptions<\n NoInfer<TParentRoute>,\n NoInfer<TCustomId>,\n NoInfer<TFullPath>,\n NoInfer<TParams>,\n NoInfer<TSearchValidator>,\n NoInfer<TLoaderFn>,\n NoInfer<TLoaderDeps>,\n NoInfer<TRouterContext>,\n NoInfer<TRouteContextFn>,\n NoInfer<TBeforeLoadFn>\n >\n\nexport type RouteContextFn<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteId,\n> = (\n ctx: RouteContextOptions<\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteId\n >,\n) => any\n\nexport type FileBaseRouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TRemountDepsFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = ParamsOptions<TPath, TParams> &\n FilebaseRouteOptionsInterface<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TRemountDepsFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\nexport interface FilebaseRouteOptionsInterface<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TRemountDepsFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> {\n validateSearch?: Constrain<TSearchValidator, AnyValidator, DefaultValidator>\n\n shouldReload?:\n | boolean\n | ((\n match: LoaderFnContext<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >,\n ) => any)\n\n context?: Constrain<\n TRouteContextFn,\n (\n ctx: RouteContextOptions<\n TParentRoute,\n TParams,\n TRouterContext,\n TLoaderDeps,\n TId\n >,\n ) => any\n >\n\n ssr?: Constrain<\n TSSR,\n | undefined\n | SSROption\n | ((\n ctx: SsrContextOptions<TParentRoute, TSearchValidator, TParams>,\n ) => Awaitable<undefined | SSROption>)\n >\n\n // This async function is called before a route is loaded.\n // If an error is thrown here, the route's loader will not be called.\n // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.\n // If thrown during a preload event, the error will be logged to the console.\n beforeLoad?: Constrain<\n TBeforeLoadFn,\n (\n ctx: BeforeLoadContextOptions<\n TRegister,\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TId,\n TServerMiddlewares,\n THandlers\n >,\n ) => ValidateSerializableLifecycleResult<\n TRegister,\n TParentRoute,\n TSSR,\n TBeforeLoadFn\n >\n >\n\n loaderDeps?: (\n opts: FullSearchSchemaOption<TParentRoute, TSearchValidator>,\n ) => TLoaderDeps\n\n remountDeps?: Constrain<\n TRemountDepsFn,\n (\n opt: RemountDepsOptions<\n TId,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>,\n TLoaderDeps\n >,\n ) => any\n >\n\n loader?: Constrain<\n TLoaderFn,\n | RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n | RouteLoaderObject<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n >\n}\n\nexport type BaseRouteOptions<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> = RoutePathOptions<TCustomId, TPath> &\n FileBaseRouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n AnyContext,\n TSSR,\n TServerMiddlewares,\n THandlers\n > & {\n getParentRoute: () => TParentRoute\n }\n\nexport interface ContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TRouteId,\n> {\n abortController: AbortController\n preload: boolean\n params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n location: ParsedLocation\n /**\n * @deprecated Use `throw redirect({ to: '/somewhere' })` instead\n **/\n navigate: NavigateFn\n buildLocation: BuildLocationFn\n cause: 'preload' | 'enter' | 'stay'\n matches: Array<MakeRouteMatchUnion>\n routeId: TRouteId\n}\n\nexport interface RouteContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TRouterContext,\n in out TLoaderDeps,\n in out TRouteId,\n> extends ContextOptions<TParentRoute, TParams, TRouteId> {\n deps: TLoaderDeps\n context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>\n}\n\nexport interface SsrContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n> {\n params:\n | {\n status: 'success'\n value: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n }\n | { status: 'error'; error: unknown }\n search:\n | {\n status: 'success'\n value: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n }\n | { status: 'error'; error: unknown }\n location: ParsedLocation\n matches: Array<MakePreValidationErrorHandlingRouteMatchUnion>\n}\n\nexport interface BeforeLoadContextOptions<\n in out TRegister,\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TRouteId,\n in out TServerMiddlewares,\n in out THandlers,\n>\n extends\n ContextOptions<TParentRoute, TParams, TRouteId>,\n FullSearchSchemaOption<TParentRoute, TSearchValidator> {\n context: Expand<\n BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>\n >\n}\n\ntype AssetFnContextOptions<\n in out TRouteId,\n in out TFullPath,\n in out TParentRoute extends AnyRoute,\n in out TParams,\n in out TSearchValidator,\n in out TLoaderFn,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n in out TLoaderDeps,\n> = {\n ssr?: {\n nonce?: string\n }\n matches: Array<\n RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n >\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n params: ResolveAllParamsFromParent<TParentRoute, TParams>\n loaderData?: ResolveLoaderData<TLoaderFn>\n}\n\nexport interface DefaultUpdatableRouteOptionsExtensions {\n component?: unknown\n errorComponent?: unknown\n notFoundComponent?: unknown\n pendingComponent?: unknown\n}\n\nexport interface UpdatableRouteOptionsExtensions extends DefaultUpdatableRouteOptionsExtensions {}\n\nexport interface UpdatableRouteOptions<\n in out TParentRoute extends AnyRoute,\n in out TRouteId,\n in out TFullPath,\n in out TParams,\n in out TSearchValidator,\n in out TLoaderFn,\n in out TLoaderDeps,\n in out TRouterContext,\n in out TRouteContextFn,\n in out TBeforeLoadFn,\n>\n extends UpdatableStaticRouteOption, UpdatableRouteOptionsExtensions {\n /**\n * Options to control route matching behavior with runtime code.\n *\n * @experimental 🚧 this feature is subject to change\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType\n */\n skipRouteOnParseError?: {\n /**\n * If `true`, skip this route during matching if `params.parse` fails.\n *\n * Without this option, a `/$param` route could match *any* value for `param`,\n * and only later during the route lifecycle would `params.parse` run and potentially\n * show the `errorComponent` if validation failed.\n *\n * With this option enabled, the route will only match if `params.parse` succeeds.\n * If it fails, the router will continue trying to match other routes, potentially\n * finding a different route that works, or ultimately showing the `notFoundComponent`.\n *\n * @default false\n */\n params?: boolean\n /**\n * In cases where multiple routes would need to run `params.parse` during matching\n * to determine which route to pick, this priority number can be used as a tie-breaker\n * for which route to try first. Higher number = higher priority.\n *\n * @default 0\n */\n priority?: number\n }\n /**\n * If true, this route will be matched as case-sensitive\n *\n * @default false\n */\n caseSensitive?: boolean\n /**\n * If true, this route will be forcefully wrapped in a suspense boundary\n */\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preload?: boolean\n preloadStaleTime?: number\n preloadGcTime?: number\n search?: {\n middlewares?: Array<\n SearchMiddleware<\n ResolveFullSearchSchemaInput<TParentRoute, TSearchValidator>\n >\n >\n }\n /** \n @deprecated Use search.middlewares instead\n */\n preSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n /** \n @deprecated Use search.middlewares instead\n */\n postSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n onCatch?: (error: Error) => void\n onError?: (err: any) => void\n // These functions are called as route matches are loaded, stick around and leave the active\n // matches\n onEnter?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onStay?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onLeave?: (\n match: RouteMatch<\n TRouteId,\n TFullPath,\n ResolveAllParamsFromParent<TParentRoute, TParams>,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n ResolveLoaderData<TLoaderFn>,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n headers?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<Record<string, string> | undefined>\n head?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<{\n links?: AnyRouteMatch['links']\n scripts?: AnyRouteMatch['headScripts']\n meta?: AnyRouteMatch['meta']\n styles?: AnyRouteMatch['styles']\n }>\n scripts?: (\n ctx: AssetFnContextOptions<\n TRouteId,\n TFullPath,\n TParentRoute,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps\n >,\n ) => Awaitable<AnyRouteMatch['scripts']>\n codeSplitGroupings?: Array<\n Array<\n | 'loader'\n | 'component'\n | 'pendingComponent'\n | 'notFoundComponent'\n | 'errorComponent'\n >\n >\n}\n\nexport type RouteLoaderFn<\n in out TRegister,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TId extends string = string,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> = (\n match: LoaderFnContext<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >,\n) => any\n\nexport type LoaderStaleReloadMode = 'background' | 'blocking'\n\nexport type RouteLoaderEntry<\n TRegister,\n TParentRoute extends AnyRoute = AnyRoute,\n TId extends string = string,\n TParams = {},\n TLoaderDeps = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n> =\n | RouteLoaderFn<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n | RouteLoaderObject<\n TRegister,\n TParentRoute,\n TId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TServerMiddlewares,\n THandlers\n >\n\nexport interface LoaderFnContext<\n in out TRegister = unknown,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TId extends string = string,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> {\n abortController: AbortController\n preload: boolean\n params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>\n deps: TLoaderDeps\n context: Expand<\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps\n /**\n * @deprecated Use `throw redirect({ to: '/somewhere' })` instead\n **/\n navigate: (opts: NavigateOptions<AnyRouter>) => Promise<void> | void\n // root route does not have a parent match\n parentMatchPromise: TId extends RootRouteId\n ? never\n : Promise<MakeRouteMatchFromRoute<TParentRoute>>\n cause: 'preload' | 'enter' | 'stay'\n route: AnyRoute\n}\n\nexport interface DefaultRootRouteOptionsExtensions {\n shellComponent?: unknown\n}\n\nexport interface RootRouteOptionsExtensions extends DefaultRootRouteOptionsExtensions {}\n\nexport interface RootRouteOptions<\n TRegister = unknown,\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TSSR = unknown,\n TServerMiddlewares = unknown,\n THandlers = undefined,\n>\n extends\n Omit<\n RouteOptions<\n TRegister,\n any, // TParentRoute\n RootRouteId, // TId\n RootRouteId, // TCustomId\n '', // TFullPath\n '', // TPath\n TSearchValidator,\n {}, // TParams\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'params'\n >,\n RootRouteOptionsExtensions {}\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySchema\n TFullSearchSchema: AnySchema\n TParams: Record<string, any>\n TAllParams: Record<string, any>\n TParentContext: AnyContext\n TRouteContext: RouteContext\n TAllContext: AnyContext\n TRouterContext: AnyContext\n TChildren: unknown\n TRouteTree: AnyRoute\n}\n\nexport type RouteTypesById<TRouter extends AnyRouter, TId> = RouteById<\n TRouter['routeTree'],\n TId\n>['types']\n\nexport type RouteMask<TRouteTree extends AnyRoute> = {\n routeTree: TRouteTree\n from: RoutePaths<TRouteTree>\n to?: any\n params?: any\n search?: any\n hash?: any\n state?: any\n unmaskOnReload?: boolean\n}\n\n/**\n * @deprecated Use `ErrorComponentProps` instead.\n */\nexport type ErrorRouteProps = {\n error: unknown\n info?: { componentStack: string }\n reset: () => void\n}\n\nexport type ErrorComponentProps<TError = Error> = {\n error: TError\n info?: { componentStack: string }\n reset: () => void\n}\n\nexport type NotFoundRouteProps = {\n data?: unknown\n isNotFound: boolean\n routeId: RouteIds<RegisteredRouter['routeTree']>\n}\n\nexport class BaseRoute<\n in out TRegister = Register,\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TPath extends string = '/',\n in out TFullPath extends string = ResolveFullPath<TParentRoute, TPath>,\n in out TCustomId extends string = string,\n in out TId extends string = ResolveId<TParentRoute, TCustomId, TPath>,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> {\n isRoot: TParentRoute extends AnyRoute ? true : false\n options: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\n // The following properties are set up in this.init()\n parentRoute!: TParentRoute\n private _id!: TId\n private _path!: TPath\n private _fullPath!: TFullPath\n private _to!: TrimPathRight<TFullPath>\n\n public get to() {\n return this._to\n }\n\n public get id() {\n return this._id\n }\n\n public get path() {\n return this._path\n }\n\n public get fullPath() {\n return this._fullPath\n }\n\n // Optional\n children?: TChildren\n originalIndex?: number\n rank!: number\n lazyFn?: () => Promise<\n LazyRoute<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n >\n >\n /** @internal */\n _lazyPromise?: Promise<void>\n /** @internal */\n _componentsPromise?: Promise<void>\n\n constructor(\n options?: RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n ) {\n this.options = (options as any) || {}\n this.isRoot = !options?.getParentRoute as any\n\n if ((options as any)?.id && (options as any)?.path) {\n throw new Error(`Route cannot have both an 'id' and a 'path' option.`)\n }\n }\n\n types!: RouteTypes<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n\n init = (opts: { originalIndex: number }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TRegister,\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TSSR,\n TServerMiddlewares\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n this.parentRoute = this.options.getParentRoute?.()\n\n if (isRoot) {\n this._path = rootRouteId as TPath\n } else if (!this.parentRoute) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n invariant()\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options?.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this._path = path as TPath\n this._id = id as TId\n this._fullPath = fullPath as TFullPath\n this._to = trimPathRight(fullPath) as TrimPathRight<TFullPath>\n }\n\n addChildren: RouteAddChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = (children) => {\n return this._addFileChildren(children) as any\n }\n\n _addFileChildren: RouteAddFileChildrenFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = (children) => {\n if (Array.isArray(children)) {\n this.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n this.children = Object.values(children) as TChildren\n }\n\n return this as any\n }\n\n _addFileTypes: RouteAddFileTypesFn<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TSSR,\n TServerMiddlewares,\n THandlers\n > = () => {\n return this as any\n }\n\n updateLoader = <TNewLoaderFn>(options: {\n loader: Constrain<\n TNewLoaderFn,\n RouteLoaderFn<\n TRegister,\n TParentRoute,\n TCustomId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n }) => {\n Object.assign(this.options, options)\n return this as unknown as BaseRoute<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TNewLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy: RouteLazyFn<\n Route<\n TRegister,\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n >\n > = (lazyFn) => {\n this.lazyFn = lazyFn\n return this\n }\n\n /**\n * Create a redirect with `from` automatically set to this route's fullPath.\n * Enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<TFullPath> = (opts) =>\n redirect({ from: this.fullPath, ...opts } as any)\n}\n\nexport class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {\n id: TId\n\n constructor({ id }: { id: TId }) {\n this.id = id\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n\n /**\n * Create a redirect with `from` automatically set to this route's path.\n * Enables relative redirects like `routeApi.redirect({ to: './overview' })`.\n * @param opts Redirect options (same as `redirect()` but without `from`)\n * @returns A redirect Response that can be thrown from loaders/beforeLoad\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\n redirect: RedirectFnRoute<RouteTypesById<TRouter, TId>['fullPath']> = (\n opts,\n ) => redirect({ from: this.id as string, ...opts } as any)\n}\n\nexport interface RootRoute<\n in out TRegister,\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> extends Route<\n TRegister,\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n> {}\n\nexport class BaseRootRoute<\n in out TRegister = Register,\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n in out TSSR = unknown,\n in out TServerMiddlewares = unknown,\n in out THandlers = undefined,\n> extends BaseRoute<\n TRegister,\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes,\n TSSR,\n TServerMiddlewares,\n THandlers\n> {\n constructor(\n options?: RootRouteOptions<\n TRegister,\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TSSR,\n TServerMiddlewares,\n THandlers\n >,\n ) {\n super(options as any)\n }\n}\n\n//\n\nexport interface RouteLike {\n id: string\n isRoot?: boolean\n path?: string\n fullPath: string\n rank?: number\n parentRoute?: RouteLike\n children?: Array<RouteLike>\n options?: {\n caseSensitive?: boolean\n }\n}\n"],"mappings":";;;;;;AAkmDA,IAAa,YAAb,MAmBE;CA4BA,IAAW,KAAK;AACd,SAAO,KAAK;;CAGd,IAAW,KAAK;AACd,SAAO,KAAK;;CAGd,IAAW,OAAO;AAChB,SAAO,KAAK;;CAGd,IAAW,WAAW;AACpB,SAAO,KAAK;;CAoCd,YACE,SAkBA;eA8BM,SAA0C;AAChD,QAAK,gBAAgB,KAAK;GAE1B,MAAM,UAAU,KAAK;GAqBrB,MAAM,SAAS,CAAC,SAAS,QAAQ,CAAC,SAAS;AAE3C,QAAK,cAAc,KAAK,QAAQ,kBAAkB;AAElD,OAAI,OACF,MAAK,QAAQ;YACJ,CAAC,KAAK,aAAa;AAC5B,QAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,gIACD;AAGH,eAAW;;GAGb,IAAI,OAA2B,SAAS,cAAc,SAAS;AAG/D,OAAI,QAAQ,SAAS,IACnB,QAAO,aAAa,KAAK;GAG3B,MAAM,WAAW,SAAS,MAAM;GAGhC,IAAI,KAAK,SACL,cACA,UAAU,CACR,KAAK,YAAY,OAAA,aAAqB,KAAK,KAAK,YAAY,IAC5D,SACD,CAAC;AAEN,OAAI,SAAA,WACF,QAAO;AAGT,OAAI,OAAA,WACF,MAAK,UAAU,CAAC,KAAK,GAAG,CAAC;GAG3B,MAAM,WACJ,OAAA,aAAqB,MAAM,UAAU,CAAC,KAAK,YAAY,UAAU,KAAK,CAAC;AAEzE,QAAK,QAAQ;AACb,QAAK,MAAM;AACX,QAAK,YAAY;AACjB,QAAK,MAAM,cAAc,SAAS;;sBAqB/B,aAAa;AAChB,UAAO,KAAK,iBAAiB,SAAS;;2BAqBnC,aAAa;AAChB,OAAI,MAAM,QAAQ,SAAS,CACzB,MAAK,WAAW;AAGlB,OAAI,OAAO,aAAa,YAAY,aAAa,KAC/C,MAAK,WAAW,OAAO,OAAO,SAAS;AAGzC,UAAO;;6BAqBC;AACR,UAAO;;uBAGqB,YAcxB;AACJ,UAAO,OAAO,KAAK,SAAS,QAAQ;AACpC,UAAO;;iBAuBP,YAYS;AACT,UAAO,OAAO,KAAK,SAAS,QAAQ;AACpC,UAAO;;eAwBJ,WAAW;AACd,QAAK,SAAS;AACd,UAAO;;mBAU+B,SACtC,SAAS;GAAE,MAAM,KAAK;GAAU,GAAG;GAAM,CAAQ;AA3QjD,OAAK,UAAW,WAAmB,EAAE;AACrC,OAAK,SAAS,CAAC,SAAS;AAExB,MAAK,SAAiB,MAAO,SAAiB,KAC5C,OAAM,IAAI,MAAM,sDAAsD;;;AA0Q5E,IAAa,eAAb,MAA6E;CAG3E,YAAY,EAAE,MAAmB;mBAIrB,SAAyB;AACnC,UAAO,SAAS;IAAE,SAAS,KAAK;IAAc,GAAG;IAAM,CAAC;;mBAWxD,SACG,SAAS;GAAE,MAAM,KAAK;GAAc,GAAG;GAAM,CAAQ;AAhBxD,OAAK,KAAK;;;AAqDd,IAAa,gBAAb,cAaU,UAmBR;CACA,YACE,SAYA;AACA,QAAM,QAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createControlledPromise } from "../utils.js";
|
|
2
|
+
import { invariant } from "../invariant.js";
|
|
2
3
|
import { isNotFound } from "../not-found.js";
|
|
3
4
|
import { hydrateSsrMatchId } from "./ssr-match-id.js";
|
|
4
|
-
import invariant from "tiny-invariant";
|
|
5
5
|
//#region src/ssr/ssr-client.ts
|
|
6
6
|
function hydrateMatch(match, deyhydratedMatch) {
|
|
7
7
|
match.id = deyhydratedMatch.i;
|
|
@@ -14,7 +14,10 @@ function hydrateMatch(match, deyhydratedMatch) {
|
|
|
14
14
|
if (deyhydratedMatch.g !== void 0) match.globalNotFound = deyhydratedMatch.g;
|
|
15
15
|
}
|
|
16
16
|
async function hydrate(router) {
|
|
17
|
-
|
|
17
|
+
if (!window.$_TSR) {
|
|
18
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected to find bootstrap data on window.$_TSR, but we did not. Please file an issue!");
|
|
19
|
+
invariant();
|
|
20
|
+
}
|
|
18
21
|
const serializationAdapters = router.options.serializationAdapters;
|
|
19
22
|
if (serializationAdapters?.length) {
|
|
20
23
|
const fromSerializableMap = /* @__PURE__ */ new Map();
|
|
@@ -25,7 +28,10 @@ async function hydrate(router) {
|
|
|
25
28
|
window.$_TSR.buffer.forEach((script) => script());
|
|
26
29
|
}
|
|
27
30
|
window.$_TSR.initialized = true;
|
|
28
|
-
|
|
31
|
+
if (!window.$_TSR.router) {
|
|
32
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!");
|
|
33
|
+
invariant();
|
|
34
|
+
}
|
|
29
35
|
const dehydratedRouter = window.$_TSR.router;
|
|
30
36
|
dehydratedRouter.matches.forEach((dehydratedMatch) => {
|
|
31
37
|
dehydratedMatch.i = hydrateSsrMatchId(dehydratedMatch.i);
|
|
@@ -147,7 +153,10 @@ async function hydrate(router) {
|
|
|
147
153
|
});
|
|
148
154
|
if (isSpaMode) {
|
|
149
155
|
const match = matches[1];
|
|
150
|
-
|
|
156
|
+
if (!match) {
|
|
157
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: Expected to find a match below the root match in SPA mode.");
|
|
158
|
+
invariant();
|
|
159
|
+
}
|
|
151
160
|
setMatchForcePending(match);
|
|
152
161
|
match._displayPending = true;
|
|
153
162
|
match._nonReactive.displayPendingPromise = loadPromise;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-client.js","names":[],"sources":["../../../src/ssr/ssr-client.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { isNotFound } from '../not-found'\nimport { createControlledPromise } from '../utils'\nimport { hydrateSsrMatchId } from './ssr-match-id'\nimport type { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants'\nimport type { DehydratedMatch, TsrSsrGlobal } from './types'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { AnyRouter } from '../router'\nimport type { RouteContextOptions } from '../route'\nimport type { AnySerializationAdapter } from './serializer/transformer'\n\ndeclare global {\n interface Window {\n [GLOBAL_TSR]?: TsrSsrGlobal\n [GLOBAL_SEROVAL]?: any\n }\n}\n\nfunction hydrateMatch(\n match: AnyRouteMatch,\n deyhydratedMatch: DehydratedMatch,\n): void {\n match.id = deyhydratedMatch.i\n match.__beforeLoadContext = deyhydratedMatch.b\n match.loaderData = deyhydratedMatch.l\n match.status = deyhydratedMatch.s\n match.ssr = deyhydratedMatch.ssr\n match.updatedAt = deyhydratedMatch.u\n match.error = deyhydratedMatch.e\n // Only hydrate global-not-found when a defined value is present in the\n // dehydrated payload. If omitted, preserve the value computed from the\n // current client location (important for SPA fallback HTML served at unknown\n // URLs, where dehydrated matches may come from `/` but client matching marks\n // root as globalNotFound).\n if (deyhydratedMatch.g !== undefined) {\n match.globalNotFound = deyhydratedMatch.g\n }\n}\n\nexport async function hydrate(router: AnyRouter): Promise<any> {\n invariant(\n window.$_TSR,\n 'Expected to find bootstrap data on window.$_TSR, but we did not. Please file an issue!',\n )\n\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n\n if (serializationAdapters?.length) {\n const fromSerializableMap = new Map()\n serializationAdapters.forEach((adapter) => {\n fromSerializableMap.set(adapter.key, adapter.fromSerializable)\n })\n window.$_TSR.t = fromSerializableMap\n window.$_TSR.buffer.forEach((script) => script())\n }\n window.$_TSR.initialized = true\n\n invariant(\n window.$_TSR.router,\n 'Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',\n )\n\n const dehydratedRouter = window.$_TSR.router\n dehydratedRouter.matches.forEach((dehydratedMatch) => {\n dehydratedMatch.i = hydrateSsrMatchId(dehydratedMatch.i)\n })\n if (dehydratedRouter.lastMatchId) {\n dehydratedRouter.lastMatchId = hydrateSsrMatchId(\n dehydratedRouter.lastMatchId,\n )\n }\n const { manifest, dehydratedData, lastMatchId } = dehydratedRouter\n\n router.ssr = {\n manifest,\n }\n const meta = document.querySelector('meta[property=\"csp-nonce\"]') as\n | HTMLMetaElement\n | undefined\n const nonce = meta?.content\n router.options.ssr = {\n nonce,\n }\n\n // Hydrate the router state\n const matches = router.matchRoutes(router.stores.location.state)\n\n // kick off loading the route chunks\n const routeChunkPromise = Promise.all(\n matches.map((match) =>\n router.loadRouteChunk(router.looseRoutesById[match.routeId]!),\n ),\n )\n\n function setMatchForcePending(match: AnyRouteMatch) {\n // usually the minPendingPromise is created in the Match component if a pending match is rendered\n // however, this might be too late if the match synchronously resolves\n const route = router.looseRoutesById[match.routeId]!\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const minPendingPromise = createControlledPromise<void>()\n match._nonReactive.minPendingPromise = minPendingPromise\n match._forcePending = true\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => {\n prev._nonReactive.minPendingPromise = undefined\n return {\n ...prev,\n _forcePending: undefined,\n }\n })\n }, pendingMinMs)\n }\n }\n\n function setRouteSsr(match: AnyRouteMatch) {\n const route = router.looseRoutesById[match.routeId]\n if (route) {\n route.options.ssr = match.ssr\n }\n }\n // Right after hydration and before the first render, we need to rehydrate each match\n // First step is to reyhdrate loaderData and __beforeLoadContext\n let firstNonSsrMatchIndex: number | undefined = undefined\n matches.forEach((match) => {\n const dehydratedMatch = dehydratedRouter.matches.find(\n (d) => d.i === match.id,\n )\n if (!dehydratedMatch) {\n match._nonReactive.dehydrated = false\n match.ssr = false\n setRouteSsr(match)\n return\n }\n\n hydrateMatch(match, dehydratedMatch)\n setRouteSsr(match)\n\n match._nonReactive.dehydrated = match.ssr !== false\n\n if (match.ssr === 'data-only' || match.ssr === false) {\n if (firstNonSsrMatchIndex === undefined) {\n firstNonSsrMatchIndex = match.index\n setMatchForcePending(match)\n }\n }\n })\n\n router.stores.setActiveMatches(matches)\n\n // Allow the user to handle custom hydration data\n await router.options.hydrate?.(dehydratedData)\n\n // now that all necessary data is hydrated:\n // 1) fully reconstruct the route context\n // 2) execute `head()` and `scripts()` for each match\n const activeMatches = router.stores.activeMatchesSnapshot.state\n const location = router.stores.location.state\n await Promise.all(\n activeMatches.map(async (match) => {\n try {\n const route = router.looseRoutesById[match.routeId]!\n\n const parentMatch = activeMatches[match.index - 1]\n const parentContext = parentMatch?.context ?? router.options.context\n\n // `context()` was already executed by `matchRoutes`, however route context was not yet fully reconstructed\n // so run it again and merge route context\n if (route.options.context) {\n const contextFnContext: RouteContextOptions<any, any, any, any, any> =\n {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext ?? {},\n location,\n navigate: (opts: any) =>\n router.navigate({\n ...opts,\n _fromLocation: location,\n }),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches,\n routeId: route.id,\n }\n match.__routeContext =\n route.options.context(contextFnContext) ?? undefined\n }\n\n match.context = {\n ...parentContext,\n ...match.__routeContext,\n ...match.__beforeLoadContext,\n }\n\n const assetContext = {\n ssr: router.options.ssr,\n matches: activeMatches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n const headFnContent = await route.options.head?.(assetContext)\n\n const scripts = await route.options.scripts?.(assetContext)\n\n match.meta = headFnContent?.meta\n match.links = headFnContent?.links\n match.headScripts = headFnContent?.scripts\n match.styles = headFnContent?.styles\n match.scripts = scripts\n } catch (err) {\n if (isNotFound(err)) {\n match.error = { isNotFound: true }\n console.error(\n `NotFound error during hydration for routeId: ${match.routeId}`,\n err,\n )\n } else {\n match.error = err as any\n console.error(\n `Error during hydration for route ${match.routeId}:`,\n err,\n )\n throw err\n }\n }\n }),\n )\n\n const isSpaMode = matches[matches.length - 1]!.id !== lastMatchId\n const hasSsrFalseMatches = matches.some((m) => m.ssr === false)\n // all matches have data from the server and we are not in SPA mode so we don't need to kick of router.load()\n if (!hasSsrFalseMatches && !isSpaMode) {\n matches.forEach((match) => {\n // remove the dehydrated flag since we won't run router.load() which would remove it\n match._nonReactive.dehydrated = undefined\n })\n return routeChunkPromise\n }\n\n // schedule router.load() to run after the next tick so we can store the promise in the match before loading starts\n const loadPromise = Promise.resolve()\n .then(() => router.load())\n .catch((err) => {\n console.error('Error during router hydration:', err)\n })\n\n // in SPA mode we need to keep the first match below the root route pending until router.load() is finished\n // this will prevent that other pending components are rendered but hydration is not blocked\n if (isSpaMode) {\n const match = matches[1]\n invariant(\n match,\n 'Expected to find a match below the root match in SPA mode.',\n )\n setMatchForcePending(match)\n\n match._displayPending = true\n match._nonReactive.displayPendingPromise = loadPromise\n\n loadPromise.then(() => {\n router.batch(() => {\n // ensure router is not in status 'pending' anymore\n // this usually happens in Transitioner but if loading synchronously resolves,\n // Transitioner won't be rendered while loading so it cannot track the change from loading:true to loading:false\n if (router.stores.status.state === 'pending') {\n router.batch(() => {\n router.stores.status.setState(() => 'idle')\n router.stores.resolvedLocation.setState(\n () => router.stores.location.state,\n )\n })\n }\n // hide the pending component once the load is finished\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n _displayPending: undefined,\n displayPendingPromise: undefined,\n }))\n })\n })\n }\n return routeChunkPromise\n}\n"],"mappings":";;;;;AAkBA,SAAS,aACP,OACA,kBACM;AACN,OAAM,KAAK,iBAAiB;AAC5B,OAAM,sBAAsB,iBAAiB;AAC7C,OAAM,aAAa,iBAAiB;AACpC,OAAM,SAAS,iBAAiB;AAChC,OAAM,MAAM,iBAAiB;AAC7B,OAAM,YAAY,iBAAiB;AACnC,OAAM,QAAQ,iBAAiB;AAM/B,KAAI,iBAAiB,MAAM,KAAA,EACzB,OAAM,iBAAiB,iBAAiB;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AU;KACtC,GAAG;KACH,iBAAiB,KAAA;KACjB,uBAAuB,KAAA;KACxB,EAAE;KACH;IACF;;AAEJ,QAAO"}
|
|
1
|
+
{"version":3,"file":"ssr-client.js","names":[],"sources":["../../../src/ssr/ssr-client.ts"],"sourcesContent":["import { invariant } from '../invariant'\nimport { isNotFound } from '../not-found'\nimport { createControlledPromise } from '../utils'\nimport { hydrateSsrMatchId } from './ssr-match-id'\nimport type { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants'\nimport type { DehydratedMatch, TsrSsrGlobal } from './types'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { AnyRouter } from '../router'\nimport type { RouteContextOptions } from '../route'\nimport type { AnySerializationAdapter } from './serializer/transformer'\n\ndeclare global {\n interface Window {\n [GLOBAL_TSR]?: TsrSsrGlobal\n [GLOBAL_SEROVAL]?: any\n }\n}\n\nfunction hydrateMatch(\n match: AnyRouteMatch,\n deyhydratedMatch: DehydratedMatch,\n): void {\n match.id = deyhydratedMatch.i\n match.__beforeLoadContext = deyhydratedMatch.b\n match.loaderData = deyhydratedMatch.l\n match.status = deyhydratedMatch.s\n match.ssr = deyhydratedMatch.ssr\n match.updatedAt = deyhydratedMatch.u\n match.error = deyhydratedMatch.e\n // Only hydrate global-not-found when a defined value is present in the\n // dehydrated payload. If omitted, preserve the value computed from the\n // current client location (important for SPA fallback HTML served at unknown\n // URLs, where dehydrated matches may come from `/` but client matching marks\n // root as globalNotFound).\n if (deyhydratedMatch.g !== undefined) {\n match.globalNotFound = deyhydratedMatch.g\n }\n}\n\nexport async function hydrate(router: AnyRouter): Promise<any> {\n if (!window.$_TSR) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Expected to find bootstrap data on window.$_TSR, but we did not. Please file an issue!',\n )\n }\n\n invariant()\n }\n\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n\n if (serializationAdapters?.length) {\n const fromSerializableMap = new Map()\n serializationAdapters.forEach((adapter) => {\n fromSerializableMap.set(adapter.key, adapter.fromSerializable)\n })\n window.$_TSR.t = fromSerializableMap\n window.$_TSR.buffer.forEach((script) => script())\n }\n window.$_TSR.initialized = true\n\n if (!window.$_TSR.router) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',\n )\n }\n\n invariant()\n }\n\n const dehydratedRouter = window.$_TSR.router\n dehydratedRouter.matches.forEach((dehydratedMatch) => {\n dehydratedMatch.i = hydrateSsrMatchId(dehydratedMatch.i)\n })\n if (dehydratedRouter.lastMatchId) {\n dehydratedRouter.lastMatchId = hydrateSsrMatchId(\n dehydratedRouter.lastMatchId,\n )\n }\n const { manifest, dehydratedData, lastMatchId } = dehydratedRouter\n\n router.ssr = {\n manifest,\n }\n const meta = document.querySelector('meta[property=\"csp-nonce\"]') as\n | HTMLMetaElement\n | undefined\n const nonce = meta?.content\n router.options.ssr = {\n nonce,\n }\n\n // Hydrate the router state\n const matches = router.matchRoutes(router.stores.location.state)\n\n // kick off loading the route chunks\n const routeChunkPromise = Promise.all(\n matches.map((match) =>\n router.loadRouteChunk(router.looseRoutesById[match.routeId]!),\n ),\n )\n\n function setMatchForcePending(match: AnyRouteMatch) {\n // usually the minPendingPromise is created in the Match component if a pending match is rendered\n // however, this might be too late if the match synchronously resolves\n const route = router.looseRoutesById[match.routeId]!\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const minPendingPromise = createControlledPromise<void>()\n match._nonReactive.minPendingPromise = minPendingPromise\n match._forcePending = true\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => {\n prev._nonReactive.minPendingPromise = undefined\n return {\n ...prev,\n _forcePending: undefined,\n }\n })\n }, pendingMinMs)\n }\n }\n\n function setRouteSsr(match: AnyRouteMatch) {\n const route = router.looseRoutesById[match.routeId]\n if (route) {\n route.options.ssr = match.ssr\n }\n }\n // Right after hydration and before the first render, we need to rehydrate each match\n // First step is to reyhdrate loaderData and __beforeLoadContext\n let firstNonSsrMatchIndex: number | undefined = undefined\n matches.forEach((match) => {\n const dehydratedMatch = dehydratedRouter.matches.find(\n (d) => d.i === match.id,\n )\n if (!dehydratedMatch) {\n match._nonReactive.dehydrated = false\n match.ssr = false\n setRouteSsr(match)\n return\n }\n\n hydrateMatch(match, dehydratedMatch)\n setRouteSsr(match)\n\n match._nonReactive.dehydrated = match.ssr !== false\n\n if (match.ssr === 'data-only' || match.ssr === false) {\n if (firstNonSsrMatchIndex === undefined) {\n firstNonSsrMatchIndex = match.index\n setMatchForcePending(match)\n }\n }\n })\n\n router.stores.setActiveMatches(matches)\n\n // Allow the user to handle custom hydration data\n await router.options.hydrate?.(dehydratedData)\n\n // now that all necessary data is hydrated:\n // 1) fully reconstruct the route context\n // 2) execute `head()` and `scripts()` for each match\n const activeMatches = router.stores.activeMatchesSnapshot.state\n const location = router.stores.location.state\n await Promise.all(\n activeMatches.map(async (match) => {\n try {\n const route = router.looseRoutesById[match.routeId]!\n\n const parentMatch = activeMatches[match.index - 1]\n const parentContext = parentMatch?.context ?? router.options.context\n\n // `context()` was already executed by `matchRoutes`, however route context was not yet fully reconstructed\n // so run it again and merge route context\n if (route.options.context) {\n const contextFnContext: RouteContextOptions<any, any, any, any, any> =\n {\n deps: match.loaderDeps,\n params: match.params,\n context: parentContext ?? {},\n location,\n navigate: (opts: any) =>\n router.navigate({\n ...opts,\n _fromLocation: location,\n }),\n buildLocation: router.buildLocation,\n cause: match.cause,\n abortController: match.abortController,\n preload: false,\n matches,\n routeId: route.id,\n }\n match.__routeContext =\n route.options.context(contextFnContext) ?? undefined\n }\n\n match.context = {\n ...parentContext,\n ...match.__routeContext,\n ...match.__beforeLoadContext,\n }\n\n const assetContext = {\n ssr: router.options.ssr,\n matches: activeMatches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n const headFnContent = await route.options.head?.(assetContext)\n\n const scripts = await route.options.scripts?.(assetContext)\n\n match.meta = headFnContent?.meta\n match.links = headFnContent?.links\n match.headScripts = headFnContent?.scripts\n match.styles = headFnContent?.styles\n match.scripts = scripts\n } catch (err) {\n if (isNotFound(err)) {\n match.error = { isNotFound: true }\n console.error(\n `NotFound error during hydration for routeId: ${match.routeId}`,\n err,\n )\n } else {\n match.error = err as any\n console.error(\n `Error during hydration for route ${match.routeId}:`,\n err,\n )\n throw err\n }\n }\n }),\n )\n\n const isSpaMode = matches[matches.length - 1]!.id !== lastMatchId\n const hasSsrFalseMatches = matches.some((m) => m.ssr === false)\n // all matches have data from the server and we are not in SPA mode so we don't need to kick of router.load()\n if (!hasSsrFalseMatches && !isSpaMode) {\n matches.forEach((match) => {\n // remove the dehydrated flag since we won't run router.load() which would remove it\n match._nonReactive.dehydrated = undefined\n })\n return routeChunkPromise\n }\n\n // schedule router.load() to run after the next tick so we can store the promise in the match before loading starts\n const loadPromise = Promise.resolve()\n .then(() => router.load())\n .catch((err) => {\n console.error('Error during router hydration:', err)\n })\n\n // in SPA mode we need to keep the first match below the root route pending until router.load() is finished\n // this will prevent that other pending components are rendered but hydration is not blocked\n if (isSpaMode) {\n const match = matches[1]\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Expected to find a match below the root match in SPA mode.',\n )\n }\n\n invariant()\n }\n setMatchForcePending(match)\n\n match._displayPending = true\n match._nonReactive.displayPendingPromise = loadPromise\n\n loadPromise.then(() => {\n router.batch(() => {\n // ensure router is not in status 'pending' anymore\n // this usually happens in Transitioner but if loading synchronously resolves,\n // Transitioner won't be rendered while loading so it cannot track the change from loading:true to loading:false\n if (router.stores.status.state === 'pending') {\n router.batch(() => {\n router.stores.status.setState(() => 'idle')\n router.stores.resolvedLocation.setState(\n () => router.stores.location.state,\n )\n })\n }\n // hide the pending component once the load is finished\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n _displayPending: undefined,\n display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KAAA;IAChC;AACF,SAAO;;CAIT,MAAM,cAAc,QAAQ,SAAS,CAClC,WAAW,OAAO,MAAM,CAAC,CACzB,OAAO,QAAQ;AACd,UAAQ,MAAM,kCAAkC,IAAI;GACpD;AAIJ,KAAI,WAAW;EACb,MAAM,QAAQ,QAAQ;AACtB,MAAI,CAAC,OAAO;AACV,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,+EACD;AAGH,cAAW;;AAEb,uBAAqB,MAAM;AAE3B,QAAM,kBAAkB;AACxB,QAAM,aAAa,wBAAwB;AAE3C,cAAY,WAAW;AACrB,UAAO,YAAY;AAIjB,QAAI,OAAO,OAAO,OAAO,UAAU,UACjC,QAAO,YAAY;AACjB,YAAO,OAAO,OAAO,eAAe,OAAO;AAC3C,YAAO,OAAO,iBAAiB,eACvB,OAAO,OAAO,SAAS,MAC9B;MACD;AAGJ,WAAO,YAAY,MAAM,KAAK,UAAU;KACtC,GAAG;KACH,iBAAiB,KAAA;KACjB,uBAAuB,KAAA;KACxB,EAAE;KACH;IACF;;AAEJ,QAAO"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { decodePath } from "../utils.js";
|
|
2
|
+
import { invariant } from "../invariant.js";
|
|
2
3
|
import { createLRUCache } from "../lru-cache.js";
|
|
3
4
|
import { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from "./constants.js";
|
|
4
5
|
import { makeSsrSerovalPlugin } from "./serializer/transformer.js";
|
|
5
6
|
import { defaultSerovalPlugins } from "./serializer/seroval-plugins.js";
|
|
6
7
|
import { dehydrateSsrMatchId } from "./ssr-match-id.js";
|
|
7
8
|
import tsrScript_default from "./tsrScript.js";
|
|
8
|
-
import invariant from "tiny-invariant";
|
|
9
9
|
import { crossSerializeStream, getCrossReferenceHeader } from "seroval";
|
|
10
10
|
//#region src/ssr/ssr-server.ts
|
|
11
11
|
var SCOPE_ID = "tsr";
|
|
@@ -121,7 +121,10 @@ function attachRouterServerSsrUtils({ router, manifest }) {
|
|
|
121
121
|
router.serverSsr.injectHtml(html);
|
|
122
122
|
},
|
|
123
123
|
dehydrate: async () => {
|
|
124
|
-
|
|
124
|
+
if (_dehydrated) {
|
|
125
|
+
if (process.env.NODE_ENV !== "production") throw new Error("Invariant failed: router is already dehydrated!");
|
|
126
|
+
invariant();
|
|
127
|
+
}
|
|
125
128
|
let matchesToDehydrate = router.stores.activeMatchesSnapshot.state;
|
|
126
129
|
if (router.isShell()) matchesToDehydrate = matchesToDehydrate.slice(0, 1);
|
|
127
130
|
const matches = matchesToDehydrate.map(dehydrateMatch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-server.js","names":[],"sources":["../../../src/ssr/ssr-server.ts"],"sourcesContent":["import { crossSerializeStream, getCrossReferenceHeader } from 'seroval'\nimport invariant from 'tiny-invariant'\nimport { decodePath } from '../utils'\nimport { createLRUCache } from '../lru-cache'\nimport minifiedTsrBootStrapScript from './tsrScript?script-string'\nimport { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from './constants'\nimport { dehydrateSsrMatchId } from './ssr-match-id'\nimport { defaultSerovalPlugins } from './serializer/seroval-plugins'\nimport { makeSsrSerovalPlugin } from './serializer/transformer'\nimport type { LRUCache } from '../lru-cache'\nimport type { DehydratedMatch, DehydratedRouter } from './types'\nimport type { AnySerializationAdapter } from './serializer/transformer'\nimport type { AnyRouter } from '../router'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { Manifest, RouterManagedTag } from '../manifest'\n\ndeclare module '../router' {\n interface ServerSsr {\n setRenderFinished: () => void\n cleanup: () => void\n }\n interface RouterEvents {\n onInjectedHtml: {\n type: 'onInjectedHtml'\n }\n onSerializationFinished: {\n type: 'onSerializationFinished'\n }\n }\n}\n\nconst SCOPE_ID = 'tsr'\n\nconst TSR_PREFIX = GLOBAL_TSR + '.router='\nconst P_PREFIX = GLOBAL_TSR + '.p(()=>'\nconst P_SUFFIX = ')'\n\nexport function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {\n const dehydratedMatch: DehydratedMatch = {\n i: dehydrateSsrMatchId(match.id),\n u: match.updatedAt,\n s: match.status,\n }\n\n const properties = [\n ['__beforeLoadContext', 'b'],\n ['loaderData', 'l'],\n ['error', 'e'],\n ['ssr', 'ssr'],\n ] as const\n\n for (const [key, shorthand] of properties) {\n if (match[key] !== undefined) {\n dehydratedMatch[shorthand] = match[key]\n }\n }\n if (match.globalNotFound) {\n dehydratedMatch.g = true\n }\n return dehydratedMatch\n}\n\nconst INITIAL_SCRIPTS = [\n getCrossReferenceHeader(SCOPE_ID),\n minifiedTsrBootStrapScript,\n]\n\nclass ScriptBuffer {\n private router: AnyRouter | undefined\n private _queue: Array<string>\n private _scriptBarrierLifted = false\n private _cleanedUp = false\n private _pendingMicrotask = false\n\n constructor(router: AnyRouter) {\n this.router = router\n // Copy INITIAL_SCRIPTS to avoid mutating the shared array\n this._queue = INITIAL_SCRIPTS.slice()\n }\n\n enqueue(script: string) {\n if (this._cleanedUp) return\n this._queue.push(script)\n // If barrier is lifted, schedule injection (if not already scheduled)\n if (this._scriptBarrierLifted && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n liftBarrier() {\n if (this._scriptBarrierLifted || this._cleanedUp) return\n this._scriptBarrierLifted = true\n if (this._queue.length > 0 && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n /**\n * Flushes any pending scripts synchronously.\n * Call this before emitting onSerializationFinished to ensure all scripts are injected.\n *\n * IMPORTANT: Only injects if the barrier has been lifted. Before the barrier is lifted,\n * scripts should remain in the queue so takeBufferedScripts() can retrieve them\n */\n flush() {\n if (!this._scriptBarrierLifted) return\n if (this._cleanedUp) return\n this._pendingMicrotask = false\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n takeAll() {\n const bufferedScripts = this._queue\n this._queue = []\n if (bufferedScripts.length === 0) {\n return undefined\n }\n // Optimization: if only one script, avoid join\n if (bufferedScripts.length === 1) {\n return bufferedScripts[0] + ';document.currentScript.remove()'\n }\n // Append cleanup script and join - avoid push() to not mutate then iterate\n return bufferedScripts.join(';') + ';document.currentScript.remove()'\n }\n\n injectBufferedScripts() {\n if (this._cleanedUp) return\n // Early return if queue is empty (avoids unnecessary takeAll() call)\n if (this._queue.length === 0) return\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n cleanup() {\n this._cleanedUp = true\n this._queue = []\n this.router = undefined\n }\n}\n\nconst isProd = process.env.NODE_ENV === 'production'\n\ntype FilteredRoutes = Manifest['routes']\n\ntype ManifestLRU = LRUCache<string, FilteredRoutes>\n\nconst MANIFEST_CACHE_SIZE = 100\nconst manifestCaches = new WeakMap<Manifest, ManifestLRU>()\n\nfunction getManifestCache(manifest: Manifest): ManifestLRU {\n const cache = manifestCaches.get(manifest)\n if (cache) return cache\n const newCache = createLRUCache<string, FilteredRoutes>(MANIFEST_CACHE_SIZE)\n manifestCaches.set(manifest, newCache)\n return newCache\n}\n\nexport function attachRouterServerSsrUtils({\n router,\n manifest,\n}: {\n router: AnyRouter\n manifest: Manifest | undefined\n}) {\n router.ssr = {\n manifest,\n }\n let _dehydrated = false\n let _serializationFinished = false\n const renderFinishedListeners: Array<() => void> = []\n const serializationFinishedListeners: Array<() => void> = []\n const scriptBuffer = new ScriptBuffer(router)\n let injectedHtmlBuffer = ''\n\n router.serverSsr = {\n injectHtml: (html: string) => {\n if (!html) return\n // Buffer the HTML so it can be retrieved via takeBufferedHtml()\n injectedHtmlBuffer += html\n // Emit event to notify subscribers that new HTML is available\n router.emit({\n type: 'onInjectedHtml',\n })\n },\n injectScript: (script: string) => {\n if (!script) return\n const html = `<script${router.options.ssr?.nonce ? ` nonce='${router.options.ssr.nonce}'` : ''}>${script}</script>`\n router.serverSsr!.injectHtml(html)\n },\n dehydrate: async () => {\n invariant(!_dehydrated, 'router is already dehydrated!')\n let matchesToDehydrate = router.stores.activeMatchesSnapshot.state\n if (router.isShell()) {\n // In SPA mode we only want to dehydrate the root match\n matchesToDehydrate = matchesToDehydrate.slice(0, 1)\n }\n const matches = matchesToDehydrate.map(dehydrateMatch)\n\n let manifestToDehydrate: Manifest | undefined = undefined\n // For currently matched routes, send full manifest (preloads + assets)\n // For all other routes, only send assets (no preloads as they are handled via dynamic imports)\n if (manifest) {\n // Prod-only caching; in dev manifests may be replaced/updated (HMR)\n const currentRouteIdsList = matchesToDehydrate.map((m) => m.routeId)\n const manifestCacheKey = currentRouteIdsList.join('\\0')\n\n let filteredRoutes: FilteredRoutes | undefined\n\n if (isProd) {\n filteredRoutes = getManifestCache(manifest).get(manifestCacheKey)\n }\n\n if (!filteredRoutes) {\n const currentRouteIds = new Set(currentRouteIdsList)\n const nextFilteredRoutes: FilteredRoutes = {}\n\n for (const routeId in manifest.routes) {\n const routeManifest = manifest.routes[routeId]!\n if (currentRouteIds.has(routeId)) {\n nextFilteredRoutes[routeId] = routeManifest\n } else if (\n routeManifest.assets &&\n routeManifest.assets.length > 0\n ) {\n nextFilteredRoutes[routeId] = {\n assets: routeManifest.assets,\n }\n }\n }\n\n if (isProd) {\n getManifestCache(manifest).set(manifestCacheKey, nextFilteredRoutes)\n }\n\n filteredRoutes = nextFilteredRoutes\n }\n\n manifestToDehydrate = {\n routes: filteredRoutes,\n }\n }\n const dehydratedRouter: DehydratedRouter = {\n manifest: manifestToDehydrate,\n matches,\n }\n const lastMatchId = matchesToDehydrate[matchesToDehydrate.length - 1]?.id\n if (lastMatchId) {\n dehydratedRouter.lastMatchId = dehydrateSsrMatchId(lastMatchId)\n }\n const dehydratedData = await router.options.dehydrate?.()\n if (dehydratedData) {\n dehydratedRouter.dehydratedData = dehydratedData\n }\n _dehydrated = true\n\n const trackPlugins = { didRun: false }\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n const plugins = serializationAdapters\n ? serializationAdapters\n .map((t) => makeSsrSerovalPlugin(t, trackPlugins))\n .concat(defaultSerovalPlugins)\n : defaultSerovalPlugins\n\n const signalSerializationComplete = () => {\n _serializationFinished = true\n try {\n serializationFinishedListeners.forEach((l) => l())\n router.emit({ type: 'onSerializationFinished' })\n } catch (err) {\n console.error('Serialization listener error:', err)\n } finally {\n serializationFinishedListeners.length = 0\n renderFinishedListeners.length = 0\n }\n }\n\n crossSerializeStream(dehydratedRouter, {\n refs: new Map(),\n plugins,\n onSerialize: (data, initial) => {\n let serialized = initial ? TSR_PREFIX + data : data\n if (trackPlugins.didRun) {\n serialized = P_PREFIX + serialized + P_SUFFIX\n }\n scriptBuffer.enqueue(serialized)\n },\n scopeId: SCOPE_ID,\n onDone: () => {\n scriptBuffer.enqueue(GLOBAL_TSR + '.e()')\n // Flush all pending scripts synchronously before signaling completion\n // This ensures all scripts are injected before onSerializationFinished is emitted\n scriptBuffer.flush()\n signalSerializationComplete()\n },\n onError: (err) => {\n console.error('Serialization error:', err)\n signalSerializationComplete()\n },\n })\n },\n isDehydrated() {\n return _dehydrated\n },\n isSerializationFinished() {\n return _serializationFinished\n },\n onRenderFinished: (listener) => renderFinishedListeners.push(listener),\n onSerializationFinished: (listener) =>\n serializationFinishedListeners.push(listener),\n setRenderFinished: () => {\n // Wrap in try-catch to ensure scriptBuffer.liftBarrier() is always called\n try {\n renderFinishedListeners.forEach((l) => l())\n } catch (err) {\n console.error('Error in render finished listener:', err)\n } finally {\n // Clear listeners after calling them to prevent memory leaks\n renderFinishedListeners.length = 0\n }\n scriptBuffer.liftBarrier()\n },\n takeBufferedScripts() {\n const scripts = scriptBuffer.takeAll()\n const serverBufferedScript: RouterManagedTag = {\n tag: 'script',\n attrs: {\n nonce: router.options.ssr?.nonce,\n className: '$tsr',\n id: TSR_SCRIPT_BARRIER_ID,\n },\n children: scripts,\n }\n return serverBufferedScript\n },\n liftScriptBarrier() {\n scriptBuffer.liftBarrier()\n },\n takeBufferedHtml() {\n if (!injectedHtmlBuffer) {\n return undefined\n }\n const buffered = injectedHtmlBuffer\n injectedHtmlBuffer = ''\n return buffered\n },\n cleanup() {\n // Guard against multiple cleanup calls\n if (!router.serverSsr) return\n renderFinishedListeners.length = 0\n serializationFinishedListeners.length = 0\n injectedHtmlBuffer = ''\n scriptBuffer.cleanup()\n router.serverSsr = undefined\n },\n }\n}\n\n/**\n * Get the origin for the request.\n *\n * SECURITY: We intentionally do NOT trust the Origin header for determining\n * the router's origin. The Origin header can be spoofed by attackers, which\n * could lead to SSRF-like vulnerabilities where redirects are constructed\n * using a malicious origin (CVE-2024-34351).\n *\n * Instead, we derive the origin from request.url, which is typically set by\n * the server infrastructure (not client-controlled headers).\n *\n * For applications behind proxies that need to trust forwarded headers,\n * use the router's `origin` option to explicitly configure a trusted origin.\n */\nexport function getOrigin(request: Request) {\n try {\n return new URL(request.url).origin\n } catch {}\n return 'http://localhost'\n}\n\n// server and browser can decode/encode characters differently in paths and search params.\n// Server generally strictly follows the WHATWG URL Standard, while browsers may differ for legacy reasons.\n// for example, in paths \"|\" is not encoded on the server but is encoded on chromium (and not on firefox) while \"대\" is encoded on both sides.\n// Another anomaly is that in Node new URLSearchParams and new URL also decode/encode characters differently.\n// new URLSearchParams() encodes \"|\" while new URL() does not, and in this instance\n// chromium treats search params differently than paths, i.e. \"|\" is not encoded in search params.\nexport function getNormalizedURL(url: string | URL, base?: string | URL) {\n // ensure backslashes are encoded correctly in the URL\n if (typeof url === 'string') url = url.replace('\\\\', '%5C')\n\n const rawUrl = new URL(url, base)\n const { path: decodedPathname, handledProtocolRelativeURL } = decodePath(\n rawUrl.pathname,\n )\n const searchParams = new URLSearchParams(rawUrl.search)\n const normalizedHref =\n decodedPathname +\n (searchParams.size > 0 ? '?' : '') +\n searchParams.toString() +\n rawUrl.hash\n\n return {\n url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;AACjB,wBAAqB;AACrB,UAAO;;EAET,UAAU;AAER,OAAI,CAAC,OAAO,UAAW;AACvB,2BAAwB,SAAS;AACjC,kCAA+B,SAAS;AACxC,wBAAqB;AACrB,gBAAa,SAAS;AACtB,UAAO,YAAY,KAAA;;EAEtB;;;;;;;;;;;;;;;;AAiBH,SAAgB,UAAU,SAAkB;AAC1C,KAAI;AACF,SAAO,IAAI,IAAI,QAAQ,IAAI,CAAC;SACtB;AACR,QAAO;;AAST,SAAgB,iBAAiB,KAAmB,MAAqB;AAEvE,KAAI,OAAO,QAAQ,SAAU,OAAM,IAAI,QAAQ,MAAM,MAAM;CAE3D,MAAM,SAAS,IAAI,IAAI,KAAK,KAAK;CACjC,MAAM,EAAE,MAAM,iBAAiB,+BAA+B,WAC5D,OAAO,SACR;CACD,MAAM,eAAe,IAAI,gBAAgB,OAAO,OAAO;CACvD,MAAM,iBACJ,mBACC,aAAa,OAAO,IAAI,MAAM,MAC/B,aAAa,UAAU,GACvB,OAAO;AAET,QAAO;EACL,KAAK,IAAI,IAAI,gBAAgB,OAAO,OAAO;EAC3C;EACD"}
|
|
1
|
+
{"version":3,"file":"ssr-server.js","names":[],"sources":["../../../src/ssr/ssr-server.ts"],"sourcesContent":["import { crossSerializeStream, getCrossReferenceHeader } from 'seroval'\nimport { invariant } from '../invariant'\nimport { decodePath } from '../utils'\nimport { createLRUCache } from '../lru-cache'\nimport minifiedTsrBootStrapScript from './tsrScript?script-string'\nimport { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from './constants'\nimport { dehydrateSsrMatchId } from './ssr-match-id'\nimport { defaultSerovalPlugins } from './serializer/seroval-plugins'\nimport { makeSsrSerovalPlugin } from './serializer/transformer'\nimport type { LRUCache } from '../lru-cache'\nimport type { DehydratedMatch, DehydratedRouter } from './types'\nimport type { AnySerializationAdapter } from './serializer/transformer'\nimport type { AnyRouter } from '../router'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { Manifest, RouterManagedTag } from '../manifest'\n\ndeclare module '../router' {\n interface ServerSsr {\n setRenderFinished: () => void\n cleanup: () => void\n }\n interface RouterEvents {\n onInjectedHtml: {\n type: 'onInjectedHtml'\n }\n onSerializationFinished: {\n type: 'onSerializationFinished'\n }\n }\n}\n\nconst SCOPE_ID = 'tsr'\n\nconst TSR_PREFIX = GLOBAL_TSR + '.router='\nconst P_PREFIX = GLOBAL_TSR + '.p(()=>'\nconst P_SUFFIX = ')'\n\nexport function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {\n const dehydratedMatch: DehydratedMatch = {\n i: dehydrateSsrMatchId(match.id),\n u: match.updatedAt,\n s: match.status,\n }\n\n const properties = [\n ['__beforeLoadContext', 'b'],\n ['loaderData', 'l'],\n ['error', 'e'],\n ['ssr', 'ssr'],\n ] as const\n\n for (const [key, shorthand] of properties) {\n if (match[key] !== undefined) {\n dehydratedMatch[shorthand] = match[key]\n }\n }\n if (match.globalNotFound) {\n dehydratedMatch.g = true\n }\n return dehydratedMatch\n}\n\nconst INITIAL_SCRIPTS = [\n getCrossReferenceHeader(SCOPE_ID),\n minifiedTsrBootStrapScript,\n]\n\nclass ScriptBuffer {\n private router: AnyRouter | undefined\n private _queue: Array<string>\n private _scriptBarrierLifted = false\n private _cleanedUp = false\n private _pendingMicrotask = false\n\n constructor(router: AnyRouter) {\n this.router = router\n // Copy INITIAL_SCRIPTS to avoid mutating the shared array\n this._queue = INITIAL_SCRIPTS.slice()\n }\n\n enqueue(script: string) {\n if (this._cleanedUp) return\n this._queue.push(script)\n // If barrier is lifted, schedule injection (if not already scheduled)\n if (this._scriptBarrierLifted && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n liftBarrier() {\n if (this._scriptBarrierLifted || this._cleanedUp) return\n this._scriptBarrierLifted = true\n if (this._queue.length > 0 && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n /**\n * Flushes any pending scripts synchronously.\n * Call this before emitting onSerializationFinished to ensure all scripts are injected.\n *\n * IMPORTANT: Only injects if the barrier has been lifted. Before the barrier is lifted,\n * scripts should remain in the queue so takeBufferedScripts() can retrieve them\n */\n flush() {\n if (!this._scriptBarrierLifted) return\n if (this._cleanedUp) return\n this._pendingMicrotask = false\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n takeAll() {\n const bufferedScripts = this._queue\n this._queue = []\n if (bufferedScripts.length === 0) {\n return undefined\n }\n // Optimization: if only one script, avoid join\n if (bufferedScripts.length === 1) {\n return bufferedScripts[0] + ';document.currentScript.remove()'\n }\n // Append cleanup script and join - avoid push() to not mutate then iterate\n return bufferedScripts.join(';') + ';document.currentScript.remove()'\n }\n\n injectBufferedScripts() {\n if (this._cleanedUp) return\n // Early return if queue is empty (avoids unnecessary takeAll() call)\n if (this._queue.length === 0) return\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n cleanup() {\n this._cleanedUp = true\n this._queue = []\n this.router = undefined\n }\n}\n\nconst isProd = process.env.NODE_ENV === 'production'\n\ntype FilteredRoutes = Manifest['routes']\n\ntype ManifestLRU = LRUCache<string, FilteredRoutes>\n\nconst MANIFEST_CACHE_SIZE = 100\nconst manifestCaches = new WeakMap<Manifest, ManifestLRU>()\n\nfunction getManifestCache(manifest: Manifest): ManifestLRU {\n const cache = manifestCaches.get(manifest)\n if (cache) return cache\n const newCache = createLRUCache<string, FilteredRoutes>(MANIFEST_CACHE_SIZE)\n manifestCaches.set(manifest, newCache)\n return newCache\n}\n\nexport function attachRouterServerSsrUtils({\n router,\n manifest,\n}: {\n router: AnyRouter\n manifest: Manifest | undefined\n}) {\n router.ssr = {\n manifest,\n }\n let _dehydrated = false\n let _serializationFinished = false\n const renderFinishedListeners: Array<() => void> = []\n const serializationFinishedListeners: Array<() => void> = []\n const scriptBuffer = new ScriptBuffer(router)\n let injectedHtmlBuffer = ''\n\n router.serverSsr = {\n injectHtml: (html: string) => {\n if (!html) return\n // Buffer the HTML so it can be retrieved via takeBufferedHtml()\n injectedHtmlBuffer += html\n // Emit event to notify subscribers that new HTML is available\n router.emit({\n type: 'onInjectedHtml',\n })\n },\n injectScript: (script: string) => {\n if (!script) return\n const html = `<script${router.options.ssr?.nonce ? ` nonce='${router.options.ssr.nonce}'` : ''}>${script}</script>`\n router.serverSsr!.injectHtml(html)\n },\n dehydrate: async () => {\n if (_dehydrated) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: router is already dehydrated!')\n }\n\n invariant()\n }\n let matchesToDehydrate = router.stores.activeMatchesSnapshot.state\n if (router.isShell()) {\n // In SPA mode we only want to dehydrate the root match\n matchesToDehydrate = matchesToDehydrate.slice(0, 1)\n }\n const matches = matchesToDehydrate.map(dehydrateMatch)\n\n let manifestToDehydrate: Manifest | undefined = undefined\n // For currently matched routes, send full manifest (preloads + assets)\n // For all other routes, only send assets (no preloads as they are handled via dynamic imports)\n if (manifest) {\n // Prod-only caching; in dev manifests may be replaced/updated (HMR)\n const currentRouteIdsList = matchesToDehydrate.map((m) => m.routeId)\n const manifestCacheKey = currentRouteIdsList.join('\\0')\n\n let filteredRoutes: FilteredRoutes | undefined\n\n if (isProd) {\n filteredRoutes = getManifestCache(manifest).get(manifestCacheKey)\n }\n\n if (!filteredRoutes) {\n const currentRouteIds = new Set(currentRouteIdsList)\n const nextFilteredRoutes: FilteredRoutes = {}\n\n for (const routeId in manifest.routes) {\n const routeManifest = manifest.routes[routeId]!\n if (currentRouteIds.has(routeId)) {\n nextFilteredRoutes[routeId] = routeManifest\n } else if (\n routeManifest.assets &&\n routeManifest.assets.length > 0\n ) {\n nextFilteredRoutes[routeId] = {\n assets: routeManifest.assets,\n }\n }\n }\n\n if (isProd) {\n getManifestCache(manifest).set(manifestCacheKey, nextFilteredRoutes)\n }\n\n filteredRoutes = nextFilteredRoutes\n }\n\n manifestToDehydrate = {\n routes: filteredRoutes,\n }\n }\n const dehydratedRouter: DehydratedRouter = {\n manifest: manifestToDehydrate,\n matches,\n }\n const lastMatchId = matchesToDehydrate[matchesToDehydrate.length - 1]?.id\n if (lastMatchId) {\n dehydratedRouter.lastMatchId = dehydrateSsrMatchId(lastMatchId)\n }\n const dehydratedData = await router.options.dehydrate?.()\n if (dehydratedData) {\n dehydratedRouter.dehydratedData = dehydratedData\n }\n _dehydrated = true\n\n const trackPlugins = { didRun: false }\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n const plugins = serializationAdapters\n ? serializationAdapters\n .map((t) => makeSsrSerovalPlugin(t, trackPlugins))\n .concat(defaultSerovalPlugins)\n : defaultSerovalPlugins\n\n const signalSerializationComplete = () => {\n _serializationFinished = true\n try {\n serializationFinishedListeners.forEach((l) => l())\n router.emit({ type: 'onSerializationFinished' })\n } catch (err) {\n console.error('Serialization listener error:', err)\n } finally {\n serializationFinishedListeners.length = 0\n renderFinishedListeners.length = 0\n }\n }\n\n crossSerializeStream(dehydratedRouter, {\n refs: new Map(),\n plugins,\n onSerialize: (data, initial) => {\n let serialized = initial ? TSR_PREFIX + data : data\n if (trackPlugins.didRun) {\n serialized = P_PREFIX + serialized + P_SUFFIX\n }\n scriptBuffer.enqueue(serialized)\n },\n scopeId: SCOPE_ID,\n onDone: () => {\n scriptBuffer.enqueue(GLOBAL_TSR + '.e()')\n // Flush all pending scripts synchronously before signaling completion\n // This ensures all scripts are injected before onSerializationFinished is emitted\n scriptBuffer.flush()\n signalSerializationComplete()\n },\n onError: (err) => {\n console.error('Serialization error:', err)\n signalSerializationComplete()\n },\n })\n },\n isDehydrated() {\n return _dehydrated\n },\n isSerializationFinished() {\n return _serializationFinished\n },\n onRenderFinished: (listener) => renderFinishedListeners.push(listener),\n onSerializationFinished: (listener) =>\n serializationFinishedListeners.push(listener),\n setRenderFinished: () => {\n // Wrap in try-catch to ensure scriptBuffer.liftBarrier() is always called\n try {\n renderFinishedListeners.forEach((l) => l())\n } catch (err) {\n console.error('Error in render finished listener:', err)\n } finally {\n // Clear listeners after calling them to prevent memory leaks\n renderFinishedListeners.length = 0\n }\n scriptBuffer.liftBarrier()\n },\n takeBufferedScripts() {\n const scripts = scriptBuffer.takeAll()\n const serverBufferedScript: RouterManagedTag = {\n tag: 'script',\n attrs: {\n nonce: router.options.ssr?.nonce,\n className: '$tsr',\n id: TSR_SCRIPT_BARRIER_ID,\n },\n children: scripts,\n }\n return serverBufferedScript\n },\n liftScriptBarrier() {\n scriptBuffer.liftBarrier()\n },\n takeBufferedHtml() {\n if (!injectedHtmlBuffer) {\n return undefined\n }\n const buffered = injectedHtmlBuffer\n injectedHtmlBuffer = ''\n return buffered\n },\n cleanup() {\n // Guard against multiple cleanup calls\n if (!router.serverSsr) return\n renderFinishedListeners.length = 0\n serializationFinishedListeners.length = 0\n injectedHtmlBuffer = ''\n scriptBuffer.cleanup()\n router.serverSsr = undefined\n },\n }\n}\n\n/**\n * Get the origin for the request.\n *\n * SECURITY: We intentionally do NOT trust the Origin header for determining\n * the router's origin. The Origin header can be spoofed by attackers, which\n * could lead to SSRF-like vulnerabilities where redirects are constructed\n * using a malicious origin (CVE-2024-34351).\n *\n * Instead, we derive the origin from request.url, which is typically set by\n * the server infrastructure (not client-controlled headers).\n *\n * For applications behind proxies that need to trust forwarded headers,\n * use the router's `origin` option to explicitly configure a trusted origin.\n */\nexport function getOrigin(request: Request) {\n try {\n return new URL(request.url).origin\n } catch {}\n return 'http://localhost'\n}\n\n// server and browser can decode/encode characters differently in paths and search params.\n// Server generally strictly follows the WHATWG URL Standard, while browsers may differ for legacy reasons.\n// for example, in paths \"|\" is not encoded on the server but is encoded on chromium (and not on firefox) while \"대\" is encoded on both sides.\n// Another anomaly is that in Node new URLSearchParams and new URL also decode/encode characters differently.\n// new URLSearchParams() encodes \"|\" while new URL() does not, and in this instance\n// chromium treats search params differently than paths, i.e. \"|\" is not encoded in search params.\nexport function getNormalizedURL(url: string | URL, base?: string | URL) {\n // ensure backslashes are encoded correctly in the URL\n if (typeof url === 'string') url = url.replace('\\\\', '%5C')\n\n const rawUrl = new URL(url, base)\n const { path: decodedPathname, handledProtocolRelativeURL } = decodePath(\n rawUrl.pathname,\n )\n const searchParams = new URLSearchParams(rawUrl.search)\n const normalizedHref =\n decodedPathname +\n (searchParams.size > 0 ? '?' : '') +\n searchParams.toString() +\n rawUrl.hash\n\n return {\n url: new URL(normalizedHref, rawUrl.origin),\n handledProtocolRelativeURL,\n }\n}\n"],"mappings":";;;;;;;;;;AA+BA,IAAM,WAAW;AAEjB,IAAM,aAAa,aAAa;AAChC,IAAM,WAAW,aAAa;AAC9B,IAAM,WAAW;AAEjB,SAAgB,eAAe,OAAuC;CACpE,MAAM,kBAAmC;EACvC,GAAG,oBAAoB,MAAM,GAAG;EAChC,GAAG,MAAM;EACT,GAAG,MAAM;EACV;AASD,MAAK,MAAM,CAAC,KAAK,cAPE;EACjB,CAAC,uBAAuB,IAAI;EAC5B,CAAC,cAAc,IAAI;EACnB,CAAC,SAAS,IAAI;EACd,CAAC,OAAO,MAAM;EACf,CAGC,KAAI,MAAM,SAAS,KAAA,EACjB,iBAAgB,aAAa,MAAM;AAGvC,KAAI,MAAM,eACR,iBAAgB,IAAI;AAEtB,QAAO;;AAGT,IAAM,kBAAkB,CACtB,wBAAwB,SAAS,EACjC,kBACD;AAED,IAAM,eAAN,MAAmB;CAOjB,YAAY,QAAmB;8BAJA;oBACV;2BACO;AAG1B,OAAK,SAAS;AAEd,OAAK,SAAS,gBAAgB,OAAO;;CAGvC,QAAQ,QAAgB;AACtB,MAAI,KAAK,WAAY;AACrB,OAAK,OAAO,KAAK,OAAO;AAExB,MAAI,KAAK,wBAAwB,CAAC,KAAK,mBAAmB;AACxD,QAAK,oBAAoB;AACzB,wBAAqB;AACnB,SAAK,oBAAoB;A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.168.3",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -150,8 +150,6 @@
|
|
|
150
150
|
"cookie-es": "^2.0.0",
|
|
151
151
|
"seroval": "^1.4.2",
|
|
152
152
|
"seroval-plugins": "^1.4.2",
|
|
153
|
-
"tiny-invariant": "^1.3.3",
|
|
154
|
-
"tiny-warning": "^1.0.3",
|
|
155
153
|
"@tanstack/history": "1.161.6"
|
|
156
154
|
},
|
|
157
155
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './global'
|
|
|
2
2
|
|
|
3
3
|
export { TSR_DEFERRED_PROMISE, defer } from './defer'
|
|
4
4
|
export type { DeferredPromiseState, DeferredPromise } from './defer'
|
|
5
|
+
export { invariant } from './invariant'
|
|
5
6
|
export { preloadWarning } from './link'
|
|
6
7
|
export type {
|
|
7
8
|
IsRequiredParams,
|
|
@@ -67,7 +68,14 @@ export type {
|
|
|
67
68
|
} from './fileRoute'
|
|
68
69
|
|
|
69
70
|
export type { ParsedLocation } from './location'
|
|
70
|
-
export type {
|
|
71
|
+
export type {
|
|
72
|
+
Manifest,
|
|
73
|
+
RouterManagedTag,
|
|
74
|
+
AssetCrossOrigin,
|
|
75
|
+
AssetCrossOriginConfig,
|
|
76
|
+
ManifestAssetLink,
|
|
77
|
+
} from './manifest'
|
|
78
|
+
export { getAssetCrossOrigin, resolveManifestAssetLink } from './manifest'
|
|
71
79
|
export { isMatch } from './Matches'
|
|
72
80
|
export type {
|
|
73
81
|
AnyMatchAndValue,
|
package/src/invariant.ts
ADDED
package/src/load-matches.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import invariant from 'tiny-invariant'
|
|
2
1
|
import { isServer } from '@tanstack/router-core/isServer'
|
|
2
|
+
import { invariant } from './invariant'
|
|
3
3
|
import { createControlledPromise, isPromise } from './utils'
|
|
4
4
|
import { isNotFound } from './not-found'
|
|
5
5
|
import { rootRouteId } from './root'
|
|
@@ -1076,10 +1076,15 @@ export async function loadMatches(arg: {
|
|
|
1076
1076
|
notFoundToThrow,
|
|
1077
1077
|
)
|
|
1078
1078
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1079
|
+
if (renderedBoundaryIndex === undefined) {
|
|
1080
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1081
|
+
throw new Error(
|
|
1082
|
+
'Invariant failed: Could not find match for notFound boundary',
|
|
1083
|
+
)
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
invariant()
|
|
1087
|
+
}
|
|
1083
1088
|
const boundaryMatch = inner.matches[renderedBoundaryIndex]!
|
|
1084
1089
|
|
|
1085
1090
|
const boundaryRoute = inner.router.looseRoutesById[boundaryMatch.routeId]!
|