@tanstack/react-router 1.48.4 → 1.49.1
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/Matches.cjs +3 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +5 -4
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +4 -5
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -1
- package/dist/cjs/path.cjs +6 -9
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/route.cjs +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +80 -61
- package/dist/cjs/router.cjs +90 -57
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +22 -9
- package/dist/cjs/transformer.cjs +39 -0
- package/dist/cjs/transformer.cjs.map +1 -0
- package/dist/cjs/transformer.d.cts +5 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -0
- package/dist/esm/Matches.d.ts +5 -4
- package/dist/esm/Matches.js +3 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +4 -5
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/link.d.ts +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.js +6 -9
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/route.d.ts +80 -61
- package/dist/esm/route.js +1 -1
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +22 -9
- package/dist/esm/router.js +91 -58
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/transformer.d.ts +5 -0
- package/dist/esm/transformer.js +39 -0
- package/dist/esm/transformer.js.map +1 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +11 -7
- package/src/fileRoute.ts +28 -22
- package/src/index.tsx +5 -1
- package/src/link.tsx +10 -6
- package/src/path.ts +7 -10
- package/src/route.ts +375 -190
- package/src/router.ts +144 -75
- package/src/transformer.ts +49 -0
- package/src/utils.ts +5 -0
package/dist/esm/route.js
CHANGED
|
@@ -56,7 +56,7 @@ class Route {
|
|
|
56
56
|
this.originalIndex = opts.originalIndex;
|
|
57
57
|
const options2 = this.options;
|
|
58
58
|
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
|
|
59
|
-
this.parentRoute = (_b = (_a = this.options)
|
|
59
|
+
this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a);
|
|
60
60
|
if (isRoot) {
|
|
61
61
|
this.path = rootRouteId;
|
|
62
62
|
} else {
|
package/dist/esm/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { joinPaths, trimPathLeft } from './path'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { notFound } from './not-found'\nimport { useNavigate } from './useNavigate'\nimport { rootRouteId } from './root'\nimport type * as React from 'react'\nimport type { RootRouteId } from './root'\nimport type { UseNavigateResult } from './useNavigate'\nimport type { MakeRouteMatch, RouteMatch } from './Matches'\nimport type { NavigateOptions, ParsePathParams, ToMaskOptions } from './link'\nimport type { ParsedLocation } from './location'\nimport type { RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter, Router } from './router'\nimport type { Assign, Expand, NoInfer, PickRequired } from './utils'\nimport type { BuildLocationFn, NavigateFn } from './RouterProvider'\nimport type { NotFoundError } from './not-found'\nimport type { LazyRoute } from './fileRoute'\n\nexport type AnyPathParams = {}\n\nexport type SearchSchemaInput = {\n __TSearchSchemaInput__: 'TSearchSchemaInput'\n}\n\nexport type AnySearchSchema = {}\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 RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TParams = AnyPathParams,\n TAllParams = TParams,\n TRouteContextReturn = RouteContext,\n TRouteContext = RouteContext,\n TParentAllContext = AnyContext,\n TAllContext = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TParentAllContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn\n> &\n UpdatableRouteOptions<\n NoInfer<TParentRoute>,\n NoInfer<TCustomId>,\n NoInfer<TAllParams>,\n NoInfer<TSearchValidator>,\n NoInfer<TLoaderData>,\n NoInfer<TAllContext>,\n NoInfer<TRouteContext>,\n NoInfer<TLoaderDeps>\n >\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: Record<ParsePathParams<TPath>, string>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : Record<ParsePathParams<TPath>, any>\n\nexport type StringifyParamsFn<TPath extends string, TParams> = (\n params: TParams,\n) => Record<ParsePathParams<TPath>, string>\n\nexport type ParamsOptions<TPath extends string, 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\nexport interface FullSearchSchemaOption<TFullSearchSchema> {\n search: TFullSearchSchema\n}\n\nexport type FileBaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = undefined,\n TParams = {},\n TAllParams = {},\n TRouteContextReturn = RouteContext,\n TParentAllContext = AnyContext,\n TAllContext = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n> = {\n validateSearch?: TSearchValidator\n shouldReload?:\n | boolean\n | ((\n match: LoaderFnContext<\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TAllContext\n >,\n ) => any)\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?: (\n ctx: BeforeLoadContext<\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TAllParams,\n TParentAllContext\n >,\n ) => Promise<TRouteContextReturn> | TRouteContextReturn | void\n loaderDeps?: (\n opts: FullSearchSchemaOption<\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>\n >,\n ) => TLoaderDeps\n loader?: (\n ctx: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>,\n ) => TLoaderDataReturn | Promise<TLoaderDataReturn>\n} & ParamsOptions<TPath, TParams>\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = undefined,\n TParams = {},\n TAllParams = {},\n TRouteContextReturn = RouteContext,\n TParentAllContext = AnyContext,\n TAllContext = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n> = RoutePathOptions<TCustomId, TPath> &\n FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TParentAllContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn\n > & {\n getParentRoute: () => TParentRoute\n }\n\nexport interface BeforeLoadContext<\n TFullSearchSchema,\n TAllParams,\n TParentAllContext,\n> extends FullSearchSchemaOption<TFullSearchSchema> {\n abortController: AbortController\n preload: boolean\n params: Expand<TAllParams>\n context: TParentAllContext\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}\n\nexport type UpdatableRouteOptions<\n TParentRoute extends AnyRoute,\n TRouteId,\n TAllParams,\n TSearchValidator extends AnySearchValidator,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps,\n> = {\n // test?: (args: TAllContext) => void\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preloadStaleTime?: number\n preloadGcTime?: number\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n onCatch?: (error: Error, errorInfo: React.ErrorInfo) => 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 TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ) => void\n onStay?: (\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ) => void\n onLeave?: (\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ) => void\n meta?: (ctx: {\n matches: Array<\n RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >\n >\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >\n params: TAllParams\n loaderData: TLoaderData\n }) => Array<React.JSX.IntrinsicElements['meta']>\n links?: () => Array<React.JSX.IntrinsicElements['link']>\n scripts?: () => Array<React.JSX.IntrinsicElements['script']>\n headers?: (ctx: { loaderData: TLoaderData }) => Record<string, string>\n} & UpdatableStaticRouteOption\n\nexport type UpdatableStaticRouteOption =\n {} extends PickRequired<StaticDataRouteOption>\n ? {\n staticData?: StaticDataRouteOption\n }\n : {\n staticData: StaticDataRouteOption\n }\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 interface SearchValidatorObj<TInput, TOutput> {\n parse: SearchValidatorFn<TInput, TOutput>\n}\n\nexport type AnySearchValidatorObj = SearchValidatorObj<any, any>\n\nexport interface SearchValidatorAdapter<TInput, TOutput> {\n types: {\n input: TInput\n output: TOutput\n }\n parse: (input: unknown) => TOutput\n}\n\nexport type AnySearchValidatorAdapter = SearchValidatorAdapter<any, any>\n\nexport type AnySearchValidatorFn = SearchValidatorFn<any, any>\n\nexport type SearchValidatorFn<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type SearchValidator<TInput, TOutput> =\n | SearchValidatorObj<TInput, TOutput>\n | SearchValidatorFn<TInput, TOutput>\n | SearchValidatorAdapter<TInput, TOutput>\n | undefined\n\nexport type AnySearchValidator = SearchValidator<any, any>\n\nexport type DefaultSearchValidator = SearchValidator<\n Record<string, unknown>,\n AnySearchSchema\n>\n\nexport type RouteLoaderFn<\n in out TAllParams = {},\n in out TLoaderDeps extends Record<string, any> = {},\n in out TAllContext = AnyContext,\n TLoaderData = undefined,\n> = (\n match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>,\n) => TLoaderData | Promise<TLoaderData>\n\nexport interface LoaderFnContext<\n in out TAllParams = {},\n in out TLoaderDeps = {},\n in out TAllContext = AnyContext,\n> {\n abortController: AbortController\n preload: boolean\n params: Expand<TAllParams>\n deps: TLoaderDeps\n context: TAllContext\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>\n parentMatchPromise?: Promise<void>\n cause: 'preload' | 'enter' | 'stay'\n route: Route\n}\n\nexport type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult\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> = TRoute extends {\n types: {\n allContext: infer TAllContext\n }\n}\n ? TAllContext\n : {}\n\nexport type ResolveSearchSchemaFnInput<\n TSearchValidator extends AnySearchValidator,\n> = TSearchValidator extends (input: infer TSearchSchemaInput) => any\n ? TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : ResolveSearchSchemaFn<TSearchValidator>\n : AnySearchSchema\n\nexport type ResolveSearchSchemaInput<\n TSearchValidator extends AnySearchValidator,\n> = TSearchValidator extends AnySearchValidatorAdapter\n ? TSearchValidator['types']['input']\n : TSearchValidator extends AnySearchValidatorObj\n ? ResolveSearchSchemaFnInput<TSearchValidator['parse']>\n : ResolveSearchSchemaFnInput<TSearchValidator>\n\nexport type ResolveSearchSchemaFn<TSearchValidator extends AnySearchValidator> =\n TSearchValidator extends (...args: any) => infer TSearchSchema\n ? TSearchSchema\n : AnySearchSchema\n\nexport type ResolveSearchSchema<TSearchValidator extends AnySearchValidator> =\n unknown extends TSearchValidator\n ? TSearchValidator\n : TSearchValidator extends AnySearchValidatorAdapter\n ? TSearchValidator['types']['output']\n : TSearchValidator extends AnySearchValidatorObj\n ? ResolveSearchSchemaFn<TSearchValidator['parse']>\n : ResolveSearchSchemaFn<TSearchValidator>\n\nexport type ResolveFullSearchSchema<\n TParentRoute extends AnyRoute,\n TSearchValidator extends AnySearchValidator,\n> = unknown extends TParentRoute\n ? ResolveSearchSchema<TSearchValidator>\n : Assign<\n InferFullSearchSchema<TParentRoute>,\n ResolveSearchSchema<TSearchValidator>\n >\n\nexport type ResolveFullSearchSchemaInput<\n TParentRoute extends AnyRoute,\n TSearchValidator extends AnySearchValidator,\n> = Assign<\n InferFullSearchSchemaInput<TParentRoute>,\n ResolveSearchSchemaInput<TSearchValidator>\n>\n\nexport type ResolveRouteContext<TRouteContextReturn> = [\n TRouteContextReturn,\n] extends [never]\n ? RouteContext\n : TRouteContextReturn\n\nexport type ResolveAllContext<\n TParentRoute extends AnyRoute,\n TRouteContext,\n> = Assign<InferAllContext<TParentRoute>, TRouteContext>\n\nexport type ResolveLoaderData<TLoaderDataReturn> = [TLoaderDataReturn] extends [\n never,\n]\n ? undefined\n : TLoaderDataReturn\n\nexport interface AnyRoute\n extends 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 > {}\n\nexport type AnyRouteWithContext<TContext> = 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 TContext,\n any,\n any\n>\n\nexport type ResolveAllParamsFromParent<\n TParentRoute extends AnyRoute,\n TParams,\n> = Assign<InferAllParams<TParentRoute>, TParams>\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\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 function getRouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n TFullSearchSchema = TRoute['types']['fullSearchSchema'],\n TAllParams = TRoute['types']['allParams'],\n TAllContext = TRoute['types']['allContext'],\n TLoaderDeps = TRoute['types']['loaderDeps'],\n TLoaderData = TRoute['types']['loaderData'],\n>(id: TId) {\n return new RouteApi<\n TId,\n TRouter,\n TRoute,\n TFullSearchSchema,\n TAllParams,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >({ id })\n}\n\nexport class RouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n TFullSearchSchema = TRoute['types']['fullSearchSchema'],\n TAllParams = TRoute['types']['allParams'],\n TAllContext = TRoute['types']['allContext'],\n TLoaderDeps = TRoute['types']['loaderDeps'],\n TLoaderData = TRoute['types']['loaderData'],\n> {\n id: TId\n\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch = <\n TRouteTree extends AnyRoute = TRouter['routeTree'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TId>,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.id })\n }\n\n useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {\n select?: (s: Expand<TAllContext>) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {\n select?: (s: Expand<TFullSearchSchema>) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id })\n }\n\n useParams = <TSelected = Expand<TAllParams>>(opts?: {\n select?: (s: Expand<TAllParams>) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id })\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (s: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {\n return useNavigate({ from: this.id })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n in out TParams = Record<ParsePathParams<TPath>, string>,\n in out TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextReturn = RouteContext,\n in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n in out TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n in out TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n in out TChildren = unknown,\n> {\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n lazyFn?: () => Promise<LazyRoute<any>>\n _lazyPromise?: Promise<void>\n\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n ) {\n this.options = (options as any) || {}\n\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: ResolveSearchSchema<TSearchValidator>\n searchSchemaInput: ResolveSearchSchemaInput<TSearchValidator>\n searchValidator: TSearchValidator\n fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>\n fullSearchSchemaInput: ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchValidator\n >\n params: TParams\n allParams: TAllParams\n routeContext: TRouteContext\n allContext: TAllContext\n children: TChildren\n loaderData: TLoaderData\n loaderDeps: TLoaderDeps\n }\n\n init = (opts: { originalIndex: number }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.parentRoute = this.options?.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\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.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren<\n const TNewChildren extends\n | Record<string, AnyRoute>\n | ReadonlyArray<AnyRoute>,\n >(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TNewChildren\n > {\n this.children = (\n Array.isArray(children) ? children : Object.values(children)\n ) as any\n return this as any\n }\n\n updateLoader = <TNewLoaderData = unknown>(options: {\n loader: RouteLoaderFn<TAllParams, TLoaderDeps, TAllContext, TNewLoaderData>\n }) => {\n Object.assign(this.options, options)\n return this as unknown as Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TNewLoaderData,\n TChildren\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TAllParams,\n TSearchValidator,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy = (lazyFn: () => Promise<LazyRoute<any>>): this => {\n this.lazyFn = lazyFn\n return this\n }\n\n useMatch = <\n TRouter extends AnyRouter = RegisteredRouter,\n TRouteTree extends AnyRoute = TRouter['routeTree'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TId>,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id })\n }\n\n useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {\n select?: (search: Expand<TAllContext>) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <\n TSelected = Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>,\n >(opts?: {\n select?: (\n search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>,\n ) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id })\n }\n\n useParams = <TSelected = Expand<TAllParams>>(opts?: {\n select?: (search: Expand<TAllParams>) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id })\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (search: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.id })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TParams = Record<ParsePathParams<TPath>, string>,\n TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n) {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport type RootRouteOptions<\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TRouterContext = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n> = Omit<\n RouteOptions<\n any, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchValidator,\n {}, // TParams\n {}, // TAllParams\n TRouteContextReturn, // TRouteContextReturn\n TRouteContext, // TRouteContext\n TRouterContext, // TParentAllContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderDataReturn, // TLoaderDataReturn,\n TLoaderData // TLoaderData,\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'params'\n>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouteContextReturn extends RouteContext = RouteContext,\n TRouteContext extends\n RouteContext = ResolveRouteContext<TRouteContextReturn>,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouteContextReturn = RouteContext,\n in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n in out TRouterContext = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n {}, // TAllParams\n TRouteContextReturn, // TRouteContextReturn\n TRouteContext, // TRouteContext\n Assign<TRouterContext, TRouteContext>, // TAllContext\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren // TChildren\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n ) {\n super(options as any)\n }\n\n addChildren<\n const TNewChildren extends\n | Record<string, AnyRoute>\n | ReadonlyArray<AnyRoute>,\n >(\n children: TNewChildren,\n ): RootRoute<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TNewChildren\n > {\n return super.addChildren(children)\n }\n}\n\nexport function createRootRoute<\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TRouterContext = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n) {\n return new RootRoute<\n TSearchValidator,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >(options)\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype 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\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\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\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never'>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\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 = {\n error: Error\n info?: { componentStack: string }\n reset: () => void\n}\nexport type NotFoundRouteProps = {\n // TODO: Make sure this is `| null | undefined` (this is for global not-founds)\n data: unknown\n}\n//\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouteContextReturn = AnyContext,\n TRouteContext = RouteContext,\n TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n {},\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TSearchValidator,\n {},\n {},\n TRouteContextReturn,\n TRouteContext,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'path'\n | 'id'\n | 'params'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["options"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { joinPaths, trimPathLeft } from './path'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { notFound } from './not-found'\nimport { useNavigate } from './useNavigate'\nimport { rootRouteId } from './root'\nimport type * as React from 'react'\nimport type { RootRouteId } from './root'\nimport type { UseNavigateResult } from './useNavigate'\nimport type { MakeRouteMatch, RouteMatch } from './Matches'\nimport type { NavigateOptions, ParsePathParams, ToMaskOptions } from './link'\nimport type { ParsedLocation } from './location'\nimport type { RouteById, RouteIds, RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter, Router } from './router'\nimport type { Assign, Constrain, Expand, NoInfer, PickRequired } from './utils'\nimport type { BuildLocationFn, NavigateFn } from './RouterProvider'\nimport type { NotFoundError } from './not-found'\nimport type { LazyRoute } from './fileRoute'\n\nexport type AnyPathParams = {}\n\nexport type SearchSchemaInput = {\n __TSearchSchemaInput__: 'TSearchSchemaInput'\n}\n\nexport type AnySearchSchema = {}\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 RouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TParams = AnyPathParams,\n TAllParams = TParams,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n> = BaseRouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n> &\n UpdatableRouteOptions<\n NoInfer<TParentRoute>,\n NoInfer<TCustomId>,\n NoInfer<TAllParams>,\n NoInfer<TSearchValidator>,\n NoInfer<TLoaderData>,\n NoInfer<TLoaderDeps>,\n NoInfer<TRouterContext>,\n NoInfer<TRouteContextFn>,\n NoInfer<TBeforeLoadFn>\n >\n\nexport type ParseSplatParams<TPath extends string> = TPath extends `${string}$`\n ? '_splat'\n : TPath extends `${string}$/${string}`\n ? '_splat'\n : never\n\nexport interface SplatParams {\n _splat?: string\n}\n\nexport type ResolveParams<TPath extends string> =\n ParseSplatParams<TPath> extends never\n ? Record<ParsePathParams<TPath>, string>\n : Record<ParsePathParams<TPath>, string> & SplatParams\n\nexport type ParseParamsFn<TPath extends string, TParams> = (\n rawParams: ResolveParams<TPath>,\n) => TParams extends Record<ParsePathParams<TPath>, any>\n ? TParams\n : Record<ParsePathParams<TPath>, any>\n\nexport type StringifyParamsFn<TPath extends string, TParams> = (\n params: TParams,\n) => ResolveParams<TPath>\n\nexport type ParamsOptions<TPath extends string, 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\nexport interface FullSearchSchemaOption<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n> {\n search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n}\n\nexport type RouteContextFn<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n in out TParams,\n in out TRouterContext,\n> = (\n ctx: RouteContextOptions<\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext\n >,\n) => any\n\nexport type BeforeLoadFn<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n> = (\n ctx: BeforeLoadContextOptions<\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn\n >,\n) => any\n\nexport type FileBaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n> = ParamsOptions<TPath, TParams> & {\n validateSearch?: TSearchValidator\n shouldReload?:\n | boolean\n | ((\n match: LoaderFnContext<\n TParentRoute,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) => any)\n\n context?: Constrain<\n TRouteContextFn,\n RouteContextFn<TParentRoute, TSearchValidator, TParams, TRouterContext>\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 BeforeLoadFn<\n TParentRoute,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn\n >\n >\n\n loaderDeps?: (\n opts: FullSearchSchemaOption<TParentRoute, TSearchValidator>,\n ) => TLoaderDeps\n\n loader?: (\n ctx: LoaderFnContext<\n TParentRoute,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) => TLoaderDataReturn | Promise<TLoaderDataReturn>\n}\n\nexport type BaseRouteOptions<\n TParentRoute extends AnyRoute = AnyRoute,\n TCustomId extends string = string,\n TPath extends string = string,\n TSearchValidator extends AnySearchValidator = undefined,\n TParams = {},\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n> = RoutePathOptions<TCustomId, TPath> &\n FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n > & {\n getParentRoute: () => TParentRoute\n }\n\nexport interface ContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n in out TParams,\n> extends FullSearchSchemaOption<TParentRoute, TSearchValidator> {\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}\n\nexport interface RouteContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n in out TParams,\n in out TRouterContext,\n> extends ContextOptions<TParentRoute, TSearchValidator, TParams> {\n context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>\n}\n\nexport interface BeforeLoadContextOptions<\n in out TParentRoute extends AnyRoute,\n in out TSearchValidator extends AnySearchValidator,\n in out TParams,\n in out TRouterContext,\n in out TRouteContextFn,\n> extends ContextOptions<TParentRoute, TSearchValidator, TParams> {\n context: Expand<\n BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>\n >\n}\n\nexport type UpdatableRouteOptions<\n TParentRoute extends AnyRoute,\n TRouteId,\n TAllParams,\n TSearchValidator extends AnySearchValidator,\n TLoaderData,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n> = {\n // test?: (args: TAllContext) => void\n // If true, this route will be matched as case-sensitive\n caseSensitive?: boolean\n // If true, this route will be forcefully wrapped in a suspense boundary\n wrapInSuspense?: boolean\n // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n pendingMs?: number\n pendingMinMs?: number\n staleTime?: number\n gcTime?: number\n preload?: boolean\n preloadStaleTime?: number\n preloadGcTime?: number\n // Filter functions that can manipulate search params *before* they are passed to links and navigate\n // calls that match this route.\n preSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n // Filter functions that can manipulate search params *after* they are passed to links and navigate\n // calls that match this route.\n postSearchFilters?: Array<\n SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>\n >\n onCatch?: (error: Error, errorInfo: React.ErrorInfo) => 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 TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onStay?: (\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n onLeave?: (\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >,\n ) => void\n meta?: (ctx: {\n matches: Array<\n RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n >\n match: RouteMatch<\n TRouteId,\n TAllParams,\n ResolveFullSearchSchema<TParentRoute, TSearchValidator>,\n TLoaderData,\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n TLoaderDeps\n >\n params: TAllParams\n loaderData: TLoaderData\n }) => Array<React.JSX.IntrinsicElements['meta']>\n links?: () => Array<React.JSX.IntrinsicElements['link']>\n scripts?: () => Array<React.JSX.IntrinsicElements['script']>\n headers?: (ctx: { loaderData: TLoaderData }) => Record<string, string>\n} & UpdatableStaticRouteOption\n\nexport type UpdatableStaticRouteOption =\n {} extends PickRequired<StaticDataRouteOption>\n ? {\n staticData?: StaticDataRouteOption\n }\n : {\n staticData: StaticDataRouteOption\n }\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 interface SearchValidatorObj<TInput, TOutput> {\n parse: SearchValidatorFn<TInput, TOutput>\n}\n\nexport type AnySearchValidatorObj = SearchValidatorObj<any, any>\n\nexport interface SearchValidatorAdapter<TInput, TOutput> {\n types: {\n input: TInput\n output: TOutput\n }\n parse: (input: unknown) => TOutput\n}\n\nexport type AnySearchValidatorAdapter = SearchValidatorAdapter<any, any>\n\nexport type AnySearchValidatorFn = SearchValidatorFn<any, any>\n\nexport type SearchValidatorFn<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type SearchValidator<TInput, TOutput> =\n | SearchValidatorObj<TInput, TOutput>\n | SearchValidatorFn<TInput, TOutput>\n | SearchValidatorAdapter<TInput, TOutput>\n | undefined\n\nexport type AnySearchValidator = SearchValidator<any, any>\n\nexport type DefaultSearchValidator = SearchValidator<\n Record<string, unknown>,\n AnySearchSchema\n>\n\nexport type RouteLoaderFn<\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n TLoaderData = undefined,\n> = (\n match: LoaderFnContext<\n TParentRoute,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n) => TLoaderData | Promise<TLoaderData>\n\nexport interface LoaderFnContext<\n in out TParentRoute extends AnyRoute = AnyRoute,\n in out TParams = {},\n in out TLoaderDeps = {},\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\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>\n parentMatchPromise?: Promise<void>\n cause: 'preload' | 'enter' | 'stay'\n route: Route\n}\n\nexport type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult\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<\n TSearchValidator extends AnySearchValidator,\n> = TSearchValidator extends (input: infer TSearchSchemaInput) => any\n ? TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : ResolveSearchSchemaFn<TSearchValidator>\n : AnySearchSchema\n\nexport type ResolveSearchSchemaInput<\n TSearchValidator extends AnySearchValidator,\n> = TSearchValidator extends AnySearchValidatorAdapter\n ? TSearchValidator['types']['input']\n : TSearchValidator extends AnySearchValidatorObj\n ? ResolveSearchSchemaFnInput<TSearchValidator['parse']>\n : ResolveSearchSchemaFnInput<TSearchValidator>\n\nexport type ResolveSearchSchemaFn<TSearchValidator extends AnySearchValidator> =\n TSearchValidator extends (...args: any) => infer TSearchSchema\n ? TSearchSchema\n : AnySearchSchema\n\nexport type ResolveSearchSchema<TSearchValidator extends AnySearchValidator> =\n unknown extends TSearchValidator\n ? TSearchValidator\n : TSearchValidator extends AnySearchValidatorAdapter\n ? TSearchValidator['types']['output']\n : TSearchValidator extends AnySearchValidatorObj\n ? ResolveSearchSchemaFn<TSearchValidator['parse']>\n : ResolveSearchSchemaFn<TSearchValidator>\n\nexport type ResolveFullSearchSchema<\n TParentRoute extends AnyRoute,\n TSearchValidator extends AnySearchValidator,\n> = unknown extends TParentRoute\n ? ResolveSearchSchema<TSearchValidator>\n : Assign<\n InferFullSearchSchema<TParentRoute>,\n ResolveSearchSchema<TSearchValidator>\n >\n\nexport type ResolveFullSearchSchemaInput<\n TParentRoute extends AnyRoute,\n TSearchValidator extends AnySearchValidator,\n> = Assign<\n InferFullSearchSchemaInput<TParentRoute>,\n ResolveSearchSchemaInput<TSearchValidator>\n>\n\nexport type LooseReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn\n : never\n\nexport type LooseAsyncReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn extends Promise<infer TReturn>\n ? TReturn\n : TReturn\n : never\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 RouteContextParameter<\n TParentRoute extends AnyRoute,\n TRouterContext,\n> = unknown extends TParentRoute\n ? TRouterContext\n : Assign<TRouterContext, InferAllContext<TParentRoute>>\n\nexport type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<\n ContextReturnType<TRouteContextFn>,\n ContextAsyncReturnType<TBeforeLoadFn>\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>\n\nexport type ResolveLoaderData<TLoaderDataReturn> = [TLoaderDataReturn] extends [\n never,\n]\n ? undefined\n : TLoaderDataReturn\n\nexport interface AnyRoute\n extends 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 > {}\n\nexport type AnyRouteWithContext<TContext> = AnyRoute & {\n types: { allContext: TContext }\n}\n\nexport type ResolveAllParamsFromParent<\n TParentRoute extends AnyRoute,\n TParams,\n> = Assign<InferAllParams<TParentRoute>, TParams>\n\nexport type RouteConstraints = {\n TParentRoute: AnyRoute\n TPath: string\n TFullPath: string\n TCustomId: string\n TId: string\n TSearchSchema: AnySearchSchema\n TFullSearchSchema: AnySearchSchema\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 function getRouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n TFullSearchSchema = TRoute['types']['fullSearchSchema'],\n TAllParams = TRoute['types']['allParams'],\n TAllContext = TRoute['types']['allContext'],\n TLoaderDeps = TRoute['types']['loaderDeps'],\n TLoaderData = TRoute['types']['loaderData'],\n>(id: TId) {\n return new RouteApi<\n TId,\n TRouter,\n TRoute,\n TFullSearchSchema,\n TAllParams,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >({ id })\n}\n\nexport class RouteApi<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,\n TFullSearchSchema = TRoute['types']['fullSearchSchema'],\n TAllParams = TRoute['types']['allParams'],\n TAllContext = TRoute['types']['allContext'],\n TLoaderDeps = TRoute['types']['loaderDeps'],\n TLoaderData = TRoute['types']['loaderData'],\n> {\n id: TId\n\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch = <\n TRouteTree extends AnyRoute = TRouter['routeTree'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TId>,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.id })\n }\n\n useRouteContext = <TSelected = Expand<TAllContext>>(opts?: {\n select?: (s: Expand<TAllContext>) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = Expand<TFullSearchSchema>>(opts?: {\n select?: (s: Expand<TFullSearchSchema>) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id })\n }\n\n useParams = <TSelected = Expand<TAllParams>>(opts?: {\n select?: (s: Expand<TAllParams>) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id })\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (s: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {\n return useNavigate({ from: this.id })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n in out TParams = ResolveParams<TPath>,\n in out TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n in out TChildren = unknown,\n> {\n isRoot: TParentRoute extends Route<any> ? true : false\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n\n // Set up in this.init()\n parentRoute!: TParentRoute\n id!: TId\n // customId!: TCustomId\n path!: TPath\n fullPath!: TFullPath\n to!: TrimPathRight<TFullPath>\n\n // Optional\n children?: TChildren\n originalIndex?: number\n router?: AnyRouter\n rank!: number\n lazyFn?: () => Promise<LazyRoute<any>>\n _lazyPromise?: Promise<void>\n\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) {\n this.options = (options as any) || {}\n\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: {\n parentRoute: TParentRoute\n path: TPath\n to: TrimPathRight<TFullPath>\n fullPath: TFullPath\n customId: TCustomId\n id: TId\n searchSchema: ResolveSearchSchema<TSearchValidator>\n searchSchemaInput: ResolveSearchSchemaInput<TSearchValidator>\n searchValidator: TSearchValidator\n fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>\n fullSearchSchemaInput: ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchValidator\n >\n params: TParams\n allParams: TAllParams\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: TLoaderData\n loaderDeps: TLoaderDeps\n }\n\n init = (opts: { originalIndex: number }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.parentRoute = this.options.getParentRoute?.()\n\n if (isRoot) {\n this.path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\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.customId = customId as TCustomId\n this.fullPath = fullPath as TFullPath\n this.to = fullPath as TrimPathRight<TFullPath>\n }\n\n addChildren<\n const TNewChildren extends\n | Record<string, AnyRoute>\n | ReadonlyArray<AnyRoute>,\n >(\n children: TNewChildren,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TNewChildren\n > {\n this.children = (\n Array.isArray(children) ? children : Object.values(children)\n ) as any\n return this as any\n }\n\n updateLoader = <TNewLoaderData = unknown>(options: {\n loader: RouteLoaderFn<\n TParentRoute,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TNewLoaderData\n >\n }) => {\n Object.assign(this.options, options)\n return this as unknown as Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TNewLoaderData,\n TChildren\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TAllParams,\n TSearchValidator,\n TLoaderData,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy = (lazyFn: () => Promise<LazyRoute<any>>): this => {\n this.lazyFn = lazyFn\n return this\n }\n\n useMatch = <\n TRouter extends AnyRouter = RegisteredRouter,\n TRouteTree extends AnyRoute = TRouter['routeTree'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TId>,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ ...opts, from: this.id })\n }\n\n useRouteContext = <\n TSelected = Expand<\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >,\n >(opts?: {\n select?: (\n search: Expand<\n ResolveAllContext<\n TParentRoute,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >,\n ) => TSelected\n }): TSelected => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <\n TSelected = Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>,\n >(opts?: {\n select?: (\n search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>,\n ) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.id })\n }\n\n useParams = <TSelected = Expand<TAllParams>>(opts?: {\n select?: (search: Expand<TAllParams>) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.id })\n }\n\n useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {\n select?: (s: TLoaderDeps) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData = <TSelected = TLoaderData>(opts?: {\n select?: (search: TLoaderData) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.id })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TParams = ResolveParams<TPath>,\n TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TCustomId,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n) {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport type RootRouteOptions<\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n> = Omit<\n RouteOptions<\n any, // TParentRoute\n RootRouteId, // TCustomId\n '', // TPath\n TSearchValidator,\n {}, // TParams\n {}, // TAllParams\n TLoaderDeps,\n TLoaderDataReturn, // TLoaderDataReturn,\n TLoaderData, // TLoaderData,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'path'\n | 'id'\n | 'getParentRoute'\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'params'\n>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderData\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n {}, // TAllParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren // TChildren\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n ) {\n super(options as any)\n }\n\n addChildren<\n const TNewChildren extends\n | Record<string, AnyRoute>\n | ReadonlyArray<AnyRoute>,\n >(\n children: TNewChildren,\n ): RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TNewChildren\n > {\n return super.addChildren(children)\n }\n}\n\nexport function createRootRoute<\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n) {\n return new RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >(options)\n}\n\nexport type ResolveFullPath<\n TParentRoute extends AnyRoute,\n TPath extends string,\n TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,\n> = TPrefixed extends RootRouteId ? '/' : TPrefixed\n\ntype 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\nexport type TrimPathRight<T extends string> = T extends '/'\n ? '/'\n : T extends `${infer U}/`\n ? TrimPathRight<U>\n : T\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\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends RoutePaths<TRouteTree>,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never'>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\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 = {\n error: Error\n info?: { componentStack: string }\n reset: () => void\n}\nexport type NotFoundRouteProps = {\n // TODO: Make sure this is `| null | undefined` (this is for global not-founds)\n data: unknown\n}\n//\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TRouterContext = AnyContext,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n {},\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n TSearchValidator,\n {},\n {},\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'path'\n | 'id'\n | 'params'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["options"],"mappings":"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"}
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Store, NoInfer } from '@tanstack/react-store';
|
|
2
2
|
import { HistoryState, RouterHistory } from '@tanstack/history';
|
|
3
3
|
import { Manifest } from './manifest.js';
|
|
4
|
-
import { AnyContext, AnyRoute, AnyRouteWithContext,
|
|
4
|
+
import { AnyContext, AnyRoute, AnyRouteWithContext, ErrorRouteComponent, NotFoundRouteComponent, RootRoute, RouteComponent, RouteMask } from './route.js';
|
|
5
5
|
import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
|
|
6
6
|
import { ControlledPromise, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
|
|
7
7
|
import { AnyRouteMatch, MakeRouteMatch, MatchRouteOptions } from './Matches.js';
|
|
@@ -11,12 +11,17 @@ import { BuildLocationFn, CommitLocationOptions, NavigateFn } from './RouterProv
|
|
|
11
11
|
import { AnyRedirect, ResolvedRedirect } from './redirects.js';
|
|
12
12
|
import { NotFoundError } from './not-found.js';
|
|
13
13
|
import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
|
|
14
|
+
import { RouterTransformer } from './transformer.js';
|
|
14
15
|
|
|
15
16
|
import type * as React from 'react';
|
|
16
17
|
declare global {
|
|
17
18
|
interface Window {
|
|
18
19
|
__TSR__?: {
|
|
19
|
-
matches: Array<
|
|
20
|
+
matches: Array<{
|
|
21
|
+
__beforeLoadContext?: string;
|
|
22
|
+
loaderData?: string;
|
|
23
|
+
extracted?: Array<ExtractedEntry>;
|
|
24
|
+
}>;
|
|
20
25
|
streamedValues: Record<string, {
|
|
21
26
|
value: any;
|
|
22
27
|
parsed: any;
|
|
@@ -38,7 +43,19 @@ export type HydrationCtx = {
|
|
|
38
43
|
router: DehydratedRouter;
|
|
39
44
|
payload: Record<string, any>;
|
|
40
45
|
};
|
|
41
|
-
export type InferRouterContext<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any,
|
|
46
|
+
export type InferRouterContext<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any, infer TRouterContext extends AnyContext, any, any, any, any, any, any> ? TRouterContext : AnyContext;
|
|
47
|
+
export type ExtractedEntry = {
|
|
48
|
+
dataType: '__beforeLoadContext' | 'loaderData';
|
|
49
|
+
type: 'promise' | 'stream';
|
|
50
|
+
path: Array<string>;
|
|
51
|
+
value: any;
|
|
52
|
+
id: number;
|
|
53
|
+
streamState?: StreamState;
|
|
54
|
+
matchIndex: number;
|
|
55
|
+
};
|
|
56
|
+
export type StreamState = {
|
|
57
|
+
promises: Array<ControlledPromise<string | null>>;
|
|
58
|
+
};
|
|
42
59
|
export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends InferRouterContext<TRouteTree> ? {
|
|
43
60
|
context?: InferRouterContext<TRouteTree>;
|
|
44
61
|
} : {
|
|
@@ -328,10 +345,6 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
328
345
|
*/
|
|
329
346
|
isServer?: boolean;
|
|
330
347
|
}
|
|
331
|
-
export interface RouterTransformer {
|
|
332
|
-
stringify: (obj: unknown) => string;
|
|
333
|
-
parse: (str: string) => unknown;
|
|
334
|
-
}
|
|
335
348
|
export interface RouterErrorSerializer<TSerializedError> {
|
|
336
349
|
serialize: (err: unknown) => TSerializedError;
|
|
337
350
|
deserialize: (err: TSerializedError) => unknown;
|
|
@@ -422,7 +435,7 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
422
435
|
match: Pick<AnyRouteMatch, 'id' | 'status' | 'error' | 'loadPromise' | 'minPendingPromise'>;
|
|
423
436
|
matchIndex: number;
|
|
424
437
|
}) => any;
|
|
425
|
-
serializeLoaderData?: (
|
|
438
|
+
serializeLoaderData?: (type: '__beforeLoadContext' | 'loaderData', loaderData: any, ctx: {
|
|
426
439
|
router: AnyRouter;
|
|
427
440
|
match: AnyRouteMatch;
|
|
428
441
|
}) => any;
|
|
@@ -452,7 +465,7 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
452
465
|
parseLocation: (previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>) => ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
453
466
|
resolvePathWithBase: (from: string, path: string) => string;
|
|
454
467
|
get looseRoutesById(): Record<string, AnyRoute>;
|
|
455
|
-
matchRoutes: (
|
|
468
|
+
matchRoutes: (next: ParsedLocation, opts?: {
|
|
456
469
|
preload?: boolean;
|
|
457
470
|
throwOnError?: boolean;
|
|
458
471
|
}) => Array<AnyRouteMatch>;
|
package/dist/esm/router.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMemoryHistory, createBrowserHistory } from "@tanstack/history";
|
|
1
|
+
import { createMemoryHistory, createBrowserHistory, parseHref } from "@tanstack/history";
|
|
2
2
|
import { Store } from "@tanstack/react-store";
|
|
3
3
|
import invariant from "tiny-invariant";
|
|
4
4
|
import warning from "tiny-warning";
|
|
@@ -8,6 +8,7 @@ import { createControlledPromise, replaceEqualDeep, pick, deepEqual, last, funct
|
|
|
8
8
|
import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths } from "./path.js";
|
|
9
9
|
import { isResolvedRedirect, isRedirect } from "./redirects.js";
|
|
10
10
|
import { isNotFound } from "./not-found.js";
|
|
11
|
+
import { defaultTransformer } from "./transformer.js";
|
|
11
12
|
const componentTypes = [
|
|
12
13
|
"component",
|
|
13
14
|
"errorComponent",
|
|
@@ -208,12 +209,12 @@ class Router {
|
|
|
208
209
|
});
|
|
209
210
|
return resolvedPath;
|
|
210
211
|
};
|
|
211
|
-
this.matchRoutes = (
|
|
212
|
+
this.matchRoutes = (next, opts) => {
|
|
212
213
|
let routeParams = {};
|
|
213
214
|
const foundRoute = this.flatRoutes.find((route) => {
|
|
214
215
|
const matchedParams = matchPathname(
|
|
215
216
|
this.basepath,
|
|
216
|
-
trimPathRight(pathname),
|
|
217
|
+
trimPathRight(next.pathname),
|
|
217
218
|
{
|
|
218
219
|
to: route.fullPath,
|
|
219
220
|
caseSensitive: route.options.caseSensitive ?? this.options.caseSensitive,
|
|
@@ -233,7 +234,7 @@ class Router {
|
|
|
233
234
|
// If we found a route, and it's not an index route and we have left over path
|
|
234
235
|
foundRoute ? foundRoute.path !== "/" && routeParams["**"] : (
|
|
235
236
|
// Or if we didn't find a route and we have left over path
|
|
236
|
-
trimPathRight(pathname)
|
|
237
|
+
trimPathRight(next.pathname)
|
|
237
238
|
)
|
|
238
239
|
) {
|
|
239
240
|
if (this.options.notFoundRoute) {
|
|
@@ -282,10 +283,10 @@ class Router {
|
|
|
282
283
|
});
|
|
283
284
|
const matches = [];
|
|
284
285
|
matchedRoutes.forEach((route, index) => {
|
|
285
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
286
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
286
287
|
const parentMatch = matches[index - 1];
|
|
287
288
|
const [preMatchSearch, searchError] = (() => {
|
|
288
|
-
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ??
|
|
289
|
+
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
|
|
289
290
|
try {
|
|
290
291
|
const validator = typeof route.options.validateSearch === "object" ? route.options.validateSearch.parse : route.options.validateSearch;
|
|
291
292
|
const search = (validator == null ? void 0 : validator(parentSearch)) ?? {};
|
|
@@ -343,8 +344,9 @@ class Router {
|
|
|
343
344
|
isFetching: false,
|
|
344
345
|
error: void 0,
|
|
345
346
|
paramsError: parseErrors[index],
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
__routeContext: {},
|
|
348
|
+
__beforeLoadContext: {},
|
|
349
|
+
context: {},
|
|
348
350
|
abortController: new AbortController(),
|
|
349
351
|
fetchCount: 0,
|
|
350
352
|
cause,
|
|
@@ -373,6 +375,30 @@ class Router {
|
|
|
373
375
|
}
|
|
374
376
|
match.search = replaceEqualDeep(match.search, preMatchSearch);
|
|
375
377
|
match.searchError = searchError;
|
|
378
|
+
const parentMatchId = parentMatch == null ? void 0 : parentMatch.id;
|
|
379
|
+
const parentContext = !parentMatchId ? this.options.context ?? {} : parentMatch.context ?? this.options.context ?? {};
|
|
380
|
+
match.context = {
|
|
381
|
+
...parentContext,
|
|
382
|
+
...match.__routeContext,
|
|
383
|
+
...match.__beforeLoadContext
|
|
384
|
+
};
|
|
385
|
+
const contextFnContext = {
|
|
386
|
+
search: match.search,
|
|
387
|
+
params: match.params,
|
|
388
|
+
context: match.context,
|
|
389
|
+
location: next,
|
|
390
|
+
navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
|
|
391
|
+
buildLocation: this.buildLocation,
|
|
392
|
+
cause: match.cause,
|
|
393
|
+
abortController: match.abortController,
|
|
394
|
+
preload: !!match.preload
|
|
395
|
+
};
|
|
396
|
+
match.__routeContext = ((_l = (_k = route.options).context) == null ? void 0 : _l.call(_k, contextFnContext)) ?? {};
|
|
397
|
+
match.context = {
|
|
398
|
+
...parentContext,
|
|
399
|
+
...match.__routeContext,
|
|
400
|
+
...match.__beforeLoadContext
|
|
401
|
+
};
|
|
376
402
|
matches.push(match);
|
|
377
403
|
});
|
|
378
404
|
return matches;
|
|
@@ -392,10 +418,10 @@ class Router {
|
|
|
392
418
|
this.buildLocation = (opts) => {
|
|
393
419
|
const build = (dest = {}, matches) => {
|
|
394
420
|
var _a, _b, _c;
|
|
395
|
-
const fromMatches = dest._fromLocation != null ? this.matchRoutes(
|
|
396
|
-
dest._fromLocation
|
|
397
|
-
dest.fromSearch || dest._fromLocation.search
|
|
398
|
-
) : this.state.matches;
|
|
421
|
+
const fromMatches = dest._fromLocation != null ? this.matchRoutes({
|
|
422
|
+
...dest._fromLocation,
|
|
423
|
+
search: dest.fromSearch || dest._fromLocation.search
|
|
424
|
+
}) : this.state.matches;
|
|
399
425
|
const fromMatch = dest.from != null ? fromMatches.find(
|
|
400
426
|
(d) => matchPathname(this.basepath, trimPathRight(d.pathname), {
|
|
401
427
|
to: dest.from,
|
|
@@ -487,8 +513,8 @@ class Router {
|
|
|
487
513
|
maskedNext = build(maskedDest);
|
|
488
514
|
}
|
|
489
515
|
}
|
|
490
|
-
const nextMatches = this.matchRoutes(next
|
|
491
|
-
const maskedMatches = maskedNext ? this.matchRoutes(maskedNext
|
|
516
|
+
const nextMatches = this.matchRoutes(next);
|
|
517
|
+
const maskedMatches = maskedNext ? this.matchRoutes(maskedNext) : void 0;
|
|
492
518
|
const maskedFinal = maskedNext ? build(maskedDest, maskedMatches) : void 0;
|
|
493
519
|
const final = build(dest, nextMatches);
|
|
494
520
|
if (maskedFinal) {
|
|
@@ -566,6 +592,13 @@ class Router {
|
|
|
566
592
|
ignoreBlocker,
|
|
567
593
|
...rest
|
|
568
594
|
} = {}) => {
|
|
595
|
+
const href = rest.href;
|
|
596
|
+
if (href) {
|
|
597
|
+
const parsed = parseHref(href, {});
|
|
598
|
+
rest.to = parsed.pathname;
|
|
599
|
+
rest.search = this.options.parseSearch(parsed.search);
|
|
600
|
+
rest.hash = parsed.hash;
|
|
601
|
+
}
|
|
569
602
|
const location = this.buildLocation(rest);
|
|
570
603
|
return this.commitLocation({
|
|
571
604
|
...location,
|
|
@@ -575,7 +608,7 @@ class Router {
|
|
|
575
608
|
ignoreBlocker
|
|
576
609
|
});
|
|
577
610
|
};
|
|
578
|
-
this.navigate = ({
|
|
611
|
+
this.navigate = ({ to, __isRedirect, ...rest }) => {
|
|
579
612
|
const toString = String(to);
|
|
580
613
|
let isExternal;
|
|
581
614
|
try {
|
|
@@ -589,7 +622,6 @@ class Router {
|
|
|
589
622
|
);
|
|
590
623
|
return this.buildAndCommitLocation({
|
|
591
624
|
...rest,
|
|
592
|
-
from,
|
|
593
625
|
to
|
|
594
626
|
// to: toString,
|
|
595
627
|
});
|
|
@@ -602,7 +634,8 @@ class Router {
|
|
|
602
634
|
}));
|
|
603
635
|
let redirect;
|
|
604
636
|
let notFound;
|
|
605
|
-
|
|
637
|
+
let loadPromise;
|
|
638
|
+
loadPromise = new Promise((resolve) => {
|
|
606
639
|
this.startReactTransition(async () => {
|
|
607
640
|
var _a;
|
|
608
641
|
try {
|
|
@@ -612,7 +645,7 @@ class Router {
|
|
|
612
645
|
this.cancelMatches();
|
|
613
646
|
let pendingMatches;
|
|
614
647
|
this.__store.batch(() => {
|
|
615
|
-
pendingMatches = this.matchRoutes(next
|
|
648
|
+
pendingMatches = this.matchRoutes(next);
|
|
616
649
|
this.__store.setState((s) => ({
|
|
617
650
|
...s,
|
|
618
651
|
status: "pending",
|
|
@@ -832,6 +865,7 @@ class Router {
|
|
|
832
865
|
};
|
|
833
866
|
for (const [index, { id: matchId, routeId }] of matches.entries()) {
|
|
834
867
|
const existingMatch = this.getMatch(matchId);
|
|
868
|
+
const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
|
|
835
869
|
if (
|
|
836
870
|
// If we are in the middle of a load, either of these will be present
|
|
837
871
|
// (not to be confused with `loadPromise`, which is always defined)
|
|
@@ -850,13 +884,6 @@ class Router {
|
|
|
850
884
|
}));
|
|
851
885
|
const route = this.looseRoutesById[routeId];
|
|
852
886
|
const abortController = new AbortController();
|
|
853
|
-
const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
|
|
854
|
-
const getParentContext = () => {
|
|
855
|
-
if (!parentMatchId) {
|
|
856
|
-
return this.options.context ?? {};
|
|
857
|
-
}
|
|
858
|
-
return this.getMatch(parentMatchId).context ?? this.options.context ?? {};
|
|
859
|
-
};
|
|
860
887
|
const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
|
|
861
888
|
const shouldPending = !!(onReady && !this.isServer && !preload && (route.options.loader || route.options.beforeLoad) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options.defaultPendingComponent));
|
|
862
889
|
let pendingTimeout;
|
|
@@ -875,47 +902,54 @@ class Router {
|
|
|
875
902
|
if (searchError) {
|
|
876
903
|
handleSerialError(index, searchError, "VALIDATE_SEARCH");
|
|
877
904
|
}
|
|
878
|
-
const
|
|
905
|
+
const getParentMatchContext = () => parentMatchId ? this.getMatch(parentMatchId).context : this.options.context ?? {};
|
|
879
906
|
updateMatch(matchId, (prev) => ({
|
|
880
907
|
...prev,
|
|
881
908
|
isFetching: "beforeLoad",
|
|
882
909
|
fetchCount: prev.fetchCount + 1,
|
|
883
|
-
routeContext: replaceEqualDeep(
|
|
884
|
-
prev.routeContext,
|
|
885
|
-
parentContext
|
|
886
|
-
),
|
|
887
|
-
context: replaceEqualDeep(prev.context, parentContext),
|
|
888
910
|
abortController,
|
|
889
|
-
pendingTimeout
|
|
911
|
+
pendingTimeout,
|
|
912
|
+
context: {
|
|
913
|
+
...getParentMatchContext(),
|
|
914
|
+
...prev.__routeContext,
|
|
915
|
+
...prev.__beforeLoadContext
|
|
916
|
+
}
|
|
890
917
|
}));
|
|
891
|
-
const { search, params,
|
|
918
|
+
const { search, params, context, cause } = this.getMatch(matchId);
|
|
892
919
|
const beforeLoadFnContext = {
|
|
893
920
|
search,
|
|
894
921
|
abortController,
|
|
895
922
|
params,
|
|
896
923
|
preload: !!preload,
|
|
897
|
-
context
|
|
924
|
+
context,
|
|
898
925
|
location,
|
|
899
926
|
navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
|
|
900
927
|
buildLocation: this.buildLocation,
|
|
901
928
|
cause: preload ? "preload" : cause
|
|
902
929
|
};
|
|
903
|
-
|
|
930
|
+
let beforeLoadContext = await ((_c = (_b = route.options).beforeLoad) == null ? void 0 : _c.call(_b, beforeLoadFnContext)) ?? {};
|
|
931
|
+
if (this.serializeLoaderData) {
|
|
932
|
+
beforeLoadContext = this.serializeLoaderData(
|
|
933
|
+
"__beforeLoadContext",
|
|
934
|
+
beforeLoadContext,
|
|
935
|
+
{
|
|
936
|
+
router: this,
|
|
937
|
+
match: this.getMatch(matchId)
|
|
938
|
+
}
|
|
939
|
+
);
|
|
940
|
+
}
|
|
904
941
|
if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {
|
|
905
942
|
handleSerialError(index, beforeLoadContext, "BEFORE_LOAD");
|
|
906
943
|
}
|
|
907
944
|
updateMatch(matchId, (prev) => {
|
|
908
|
-
const routeContext2 = {
|
|
909
|
-
...prev.routeContext,
|
|
910
|
-
...beforeLoadContext
|
|
911
|
-
};
|
|
912
945
|
return {
|
|
913
946
|
...prev,
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
947
|
+
__beforeLoadContext: beforeLoadContext,
|
|
948
|
+
context: {
|
|
949
|
+
...getParentMatchContext(),
|
|
950
|
+
...prev.__routeContext,
|
|
951
|
+
...beforeLoadContext
|
|
952
|
+
},
|
|
919
953
|
abortController
|
|
920
954
|
};
|
|
921
955
|
});
|
|
@@ -1008,10 +1042,14 @@ class Router {
|
|
|
1008
1042
|
await route._lazyPromise;
|
|
1009
1043
|
let loaderData = await ((_b2 = (_a2 = route.options).loader) == null ? void 0 : _b2.call(_a2, getLoaderContext()));
|
|
1010
1044
|
if (this.serializeLoaderData) {
|
|
1011
|
-
loaderData = this.serializeLoaderData(
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1045
|
+
loaderData = this.serializeLoaderData(
|
|
1046
|
+
"loaderData",
|
|
1047
|
+
loaderData,
|
|
1048
|
+
{
|
|
1049
|
+
router: this,
|
|
1050
|
+
match: this.getMatch(matchId)
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1015
1053
|
}
|
|
1016
1054
|
handleRedirectAndNotFound(
|
|
1017
1055
|
this.getMatch(matchId),
|
|
@@ -1063,7 +1101,8 @@ class Router {
|
|
|
1063
1101
|
}
|
|
1064
1102
|
};
|
|
1065
1103
|
const { status, invalid } = this.getMatch(matchId);
|
|
1066
|
-
if (
|
|
1104
|
+
if (preload && route.options.preload === false) {
|
|
1105
|
+
} else if (status === "success" && (invalid || (shouldReload ?? age > staleAge))) {
|
|
1067
1106
|
;
|
|
1068
1107
|
(async () => {
|
|
1069
1108
|
try {
|
|
@@ -1145,7 +1184,7 @@ class Router {
|
|
|
1145
1184
|
};
|
|
1146
1185
|
this.preloadRoute = async (opts) => {
|
|
1147
1186
|
const next = this.buildLocation(opts);
|
|
1148
|
-
let matches = this.matchRoutes(next
|
|
1187
|
+
let matches = this.matchRoutes(next, {
|
|
1149
1188
|
throwOnError: true,
|
|
1150
1189
|
preload: true
|
|
1151
1190
|
});
|
|
@@ -1263,10 +1302,7 @@ class Router {
|
|
|
1263
1302
|
this.dehydratedData = ctx.payload;
|
|
1264
1303
|
(_c = (_b = this.options).hydrate) == null ? void 0 : _c.call(_b, ctx.payload);
|
|
1265
1304
|
const dehydratedState = ctx.router.state;
|
|
1266
|
-
const matches = this.matchRoutes(
|
|
1267
|
-
this.state.location.pathname,
|
|
1268
|
-
this.state.location.search
|
|
1269
|
-
).map((match) => {
|
|
1305
|
+
const matches = this.matchRoutes(this.state.location).map((match) => {
|
|
1270
1306
|
const dehydratedMatch = dehydratedState.dehydratedMatches.find(
|
|
1271
1307
|
(d) => d.id === match.id
|
|
1272
1308
|
);
|
|
@@ -1366,10 +1402,7 @@ class Router {
|
|
|
1366
1402
|
notFoundMode: options.notFoundMode ?? "fuzzy",
|
|
1367
1403
|
stringifySearch: options.stringifySearch ?? defaultStringifySearch,
|
|
1368
1404
|
parseSearch: options.parseSearch ?? defaultParseSearch,
|
|
1369
|
-
transformer: options.transformer ??
|
|
1370
|
-
parse: JSON.parse,
|
|
1371
|
-
stringify: JSON.stringify
|
|
1372
|
-
}
|
|
1405
|
+
transformer: options.transformer ?? defaultTransformer
|
|
1373
1406
|
});
|
|
1374
1407
|
if (typeof document !== "undefined") {
|
|
1375
1408
|
window.__TSR__ROUTER__ = this;
|