@tanstack/react-router
Advanced tools
Comparing version 1.41.0 to 1.42.0
@@ -11,3 +11,11 @@ import { ParsePathParams } from './link.js'; | ||
} | ||
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): <TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = Assign<import('./route').InferFullSearchSchemaInput<TParentRoute>, TSearchSchemaUsed>, TFullSearchSchema = Assign<import('./route').InferFullSearchSchema<TParentRoute>, TSearchSchema>, TParams = Record<ParsePathParams<TPath, never>, string>, TAllParams = Assign<import('./route').InferAllParams<TParentRoute>, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = Assign<InferAllContext<TParentRoute>, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options?: (FileBaseRouteOptions<TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn> & { | ||
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): <TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = Assign<import('./route').InferFullSearchSchemaInput<TParentRoute>, TSearchSchemaUsed>, TFullSearchSchema = Assign<import('./route').InferFullSearchSchema<TParentRoute>, TSearchSchema>, TParams = Record<ParsePathParams<TPath, never>, string>, TAllParams = Assign<import('./route').InferAllParams<TParentRoute>, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = Assign<InferAllContext<TParentRoute>, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options?: ({ | ||
validateSearch?: ((input: TSearchSchemaInput) => TSearchSchema) | { | ||
parse: (input: TSearchSchemaInput) => TSearchSchema; | ||
} | undefined; | ||
shouldReload?: boolean | ((match: import('./route').LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext>) => any) | undefined; | ||
beforeLoad?: ((ctx: import('./route').BeforeLoadContext<TFullSearchSchema, TAllParams, InferAllContext<TParentRoute>>) => void | TRouteContextReturn | Promise<TRouteContextReturn>) | undefined; | ||
loaderDeps?: ((opts: import('./route').FullSearchSchemaOption<TFullSearchSchema>) => TLoaderDeps) | undefined; | ||
loader?: ((ctx: import('./route').LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => TLoaderDataReturn | Promise<TLoaderDataReturn>) | undefined; | ||
} & import('./route').ParamsOptions<TPath, TParams> & { | ||
caseSensitive?: boolean | undefined; | ||
@@ -14,0 +22,0 @@ wrapInSuspense?: boolean | undefined; |
@@ -24,3 +24,3 @@ export { createHistory, createBrowserHistory, createHashHistory, createMemoryHistory, type BlockerFn, type HistoryLocation, type RouterHistory, type ParsedPath, type HistoryState, } from '@tanstack/history'; | ||
export { rootRouteId, type RootRouteId } from './root.js'; | ||
export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithContext, createRootRoute, createRootRouteWithContext, createRouteMask, NotFoundRoute, type AnyPathParams, type SearchSchemaInput, type AnySearchSchema, type AnyContext, type RouteContext, type PreloadableObj, type RoutePathOptions, type StaticDataRouteOption, type RoutePathOptionsIntersection, type RouteOptions, type ParamsFallback, type FileBaseRouteOptions, type BaseRouteOptions, type UpdatableRouteOptions, type UpdatableStaticRouteOption, type MetaDescriptor, type RouteLinkEntry, type ParseParamsOption, type ParseParamsFn, type ParseParamsObj, type SearchSchemaValidator, type SearchSchemaValidatorObj, type SearchSchemaValidatorFn, type RouteLoaderFn, type LoaderFnContext, type SearchFilter, type ResolveId, type InferFullSearchSchema, type InferFullSearchSchemaInput, type ResolveFullSearchSchema, type ResolveFullSearchSchemaInput, type AnyRoute, type RouteConstraints, type AnyRootRoute, type ResolveFullPath, type RouteMask, type ErrorRouteProps, type ErrorComponentProps, type NotFoundRouteProps, type ReactNode, type SyncRouteComponent, type AsyncRouteComponent, type RouteComponent, type ErrorRouteComponent, type NotFoundRouteComponent, type TrimPath, type TrimPathLeft, type TrimPathRight, type RootRouteOptions, } from './route.js'; | ||
export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithContext, createRootRoute, createRootRouteWithContext, createRouteMask, NotFoundRoute, type AnyPathParams, type SearchSchemaInput, type AnySearchSchema, type AnyContext, type RouteContext, type PreloadableObj, type RoutePathOptions, type StaticDataRouteOption, type RoutePathOptionsIntersection, type RouteOptions, type FileBaseRouteOptions, type BaseRouteOptions, type UpdatableRouteOptions, type UpdatableStaticRouteOption, type MetaDescriptor, type RouteLinkEntry, type ParseParamsFn, type SearchSchemaValidator, type SearchSchemaValidatorObj, type SearchSchemaValidatorFn, type RouteLoaderFn, type LoaderFnContext, type SearchFilter, type ResolveId, type InferFullSearchSchema, type InferFullSearchSchemaInput, type ResolveFullSearchSchema, type ResolveFullSearchSchemaInput, type AnyRoute, type RouteConstraints, type AnyRootRoute, type ResolveFullPath, type RouteMask, type ErrorRouteProps, type ErrorComponentProps, type NotFoundRouteProps, type ReactNode, type SyncRouteComponent, type AsyncRouteComponent, type RouteComponent, type ErrorRouteComponent, type NotFoundRouteComponent, type TrimPath, type TrimPathLeft, type TrimPathRight, type RootRouteOptions, } from './route.js'; | ||
export { type ParseRoute, type RoutesById, type RouteById, type RouteIds, type RoutesByPath, type RouteByPath, type RoutePaths, type FullSearchSchema, type AllParams, } from './routeInfo.js'; | ||
@@ -27,0 +27,0 @@ export { componentTypes, createRouter, Router, lazyFn, SearchParamError, PathParamError, getInitialRouterState, defaultSerializeError, type Register, type AnyRouter, type RegisteredRouter, type HydrationCtx, type RouterContextOptions, type TrailingSlashOption, type RouterOptions, type RouterTransformer, type RouterErrorSerializer, type RouterState, type ListenerFn, type BuildNextOptions, type DehydratedRouterState, type DehydratedRouteMatch, type DehydratedRouter, type RouterConstructorOptions, type RouterEvents, type RouterEvent, type RouterListener, } from './router.js'; |
@@ -8,3 +8,3 @@ import { RootRouteId } from './root.js'; | ||
import { AnyRouter, RegisteredRouter, Router } from './router.js'; | ||
import { Assign, Expand, IsAny, NoInfer, PickRequired } from './utils.js'; | ||
import { Assign, Expand, NoInfer, PickRequired } from './utils.js'; | ||
import { BuildLocationFn, NavigateFn } from './RouterProvider.js'; | ||
@@ -38,26 +38,37 @@ import { NotFoundError } from './not-found.js'; | ||
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TFullSearchSchema = TSearchSchema, TParams = AnyPathParams, TAllParams = TParams, TRouteContextReturn = RouteContext, TRouteContext = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TParentAllContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & UpdatableRouteOptions<NoInfer<TCustomId>, NoInfer<TAllParams>, NoInfer<TFullSearchSchema>, NoInfer<TLoaderData>, NoInfer<TAllContext>, NoInfer<TRouteContext>, NoInfer<TLoaderDeps>>; | ||
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams; | ||
export type FileBaseRouteOptions<TPath extends string = string, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TFullSearchSchema = TSearchSchema, TParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = { | ||
validateSearch?: SearchSchemaValidator<TSearchSchemaInput, TSearchSchema>; | ||
export type ParseParamsFn<TPath extends string, TParams> = (rawParams: Record<ParsePathParams<TPath>, string>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : Record<ParsePathParams<TPath>, any>; | ||
export type StringifyParamsFn<TPath extends string, TParams> = (params: TParams) => Record<ParsePathParams<TPath>, string>; | ||
export type ParamsOptions<TPath extends string, TParams> = { | ||
params?: { | ||
parse: ParseParamsFn<TPath, TParams>; | ||
stringify: StringifyParamsFn<TPath, TParams>; | ||
}; | ||
/** | ||
@deprecated Use params.parse instead | ||
*/ | ||
parseParams?: ParseParamsFn<TPath, TParams>; | ||
/** | ||
@deprecated Use params.stringify instead | ||
*/ | ||
stringifyParams?: StringifyParamsFn<TPath, TParams>; | ||
}; | ||
export interface FullSearchSchemaOption<TFullSearchSchema> { | ||
search: TFullSearchSchema; | ||
} | ||
export type FileBaseRouteOptions<TPath extends string = string, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TFullSearchSchema = TSearchSchema, TParams = {}, TAllParams = {}, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = { | ||
validateSearch?: ((input: TSearchSchemaInput) => TSearchSchema) | { | ||
parse: (input: TSearchSchemaInput) => TSearchSchema; | ||
}; | ||
shouldReload?: boolean | ((match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext>) => any); | ||
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TAllParams, TRouteContextReturn, TParentAllContext>; | ||
loaderDeps?: (opts: { | ||
search: TFullSearchSchema; | ||
}) => TLoaderDeps; | ||
loader?: RouteLoaderFn<TAllParams, NoInfer<TLoaderDeps>, NoInfer<TAllContext>, TLoaderDataReturn>; | ||
} & ({ | ||
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object'; | ||
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>; | ||
} | { | ||
stringifyParams?: never; | ||
parseParams?: never; | ||
}); | ||
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TFullSearchSchema = TSearchSchema, TParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = RoutePathOptions<TCustomId, TPath> & FileBaseRouteOptions<TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TParentAllContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & { | ||
beforeLoad?: (ctx: BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllContext>) => Promise<TRouteContextReturn> | TRouteContextReturn | void; | ||
loaderDeps?: (opts: FullSearchSchemaOption<TFullSearchSchema>) => TLoaderDeps; | ||
loader?: (ctx: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => TLoaderDataReturn | Promise<TLoaderDataReturn>; | ||
} & ParamsOptions<TPath, TParams>; | ||
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TFullSearchSchema = TSearchSchema, TParams = {}, TAllParams = {}, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = RoutePathOptions<TCustomId, TPath> & FileBaseRouteOptions<TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TParentAllContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & { | ||
getParentRoute: () => TParentRoute; | ||
}; | ||
type BeforeLoadFn<in out TFullSearchSchema, in out TAllParams, TRouteContextReturn, in out TParentAllContext> = (opts: { | ||
search: TFullSearchSchema; | ||
export interface BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllContext> extends FullSearchSchemaOption<TFullSearchSchema> { | ||
abortController: AbortController; | ||
preload: boolean; | ||
params: TAllParams; | ||
params: Expand<TAllParams>; | ||
context: TParentAllContext; | ||
@@ -71,3 +82,3 @@ location: ParsedLocation; | ||
cause: 'preload' | 'enter' | 'stay'; | ||
}) => Promise<TRouteContextReturn> | TRouteContextReturn | void; | ||
} | ||
export type UpdatableRouteOptions<TRouteId, TAllParams, TFullSearchSchema, TLoaderData, TAllContext, TRouteContext, TLoaderDeps, TRouteMatch = RouteMatch<TRouteId, TAllParams, TFullSearchSchema, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>> = { | ||
@@ -137,7 +148,2 @@ caseSensitive?: boolean; | ||
export type RouteLinkEntry = {}; | ||
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>; | ||
export type ParseParamsFn<TPath extends string, TParams> = (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object'; | ||
export type ParseParamsObj<TPath extends string, TParams> = { | ||
parse?: ParseParamsFn<TPath, TParams>; | ||
}; | ||
export type SearchSchemaValidator<TInput, TReturn> = SearchSchemaValidatorObj<TInput, TReturn> | SearchSchemaValidatorFn<TInput, TReturn>; | ||
@@ -148,7 +154,7 @@ export type SearchSchemaValidatorObj<TInput, TReturn> = { | ||
export type SearchSchemaValidatorFn<TInput, TReturn> = (searchObj: TInput) => TReturn; | ||
export type RouteLoaderFn<in out TAllParams = {}, in out TLoaderDeps extends Record<string, any> = {}, in out TAllContext = AnyContext, TLoaderData = undefined> = (match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => Promise<TLoaderData> | TLoaderData; | ||
export type RouteLoaderFn<in out TAllParams = {}, in out TLoaderDeps extends Record<string, any> = {}, in out TAllContext = AnyContext, TLoaderData = undefined> = (match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => TLoaderData | Promise<TLoaderData>; | ||
export interface LoaderFnContext<in out TAllParams = {}, in out TLoaderDeps = {}, in out TAllContext = AnyContext> { | ||
abortController: AbortController; | ||
preload: boolean; | ||
params: TAllParams; | ||
params: Expand<TAllParams>; | ||
deps: TLoaderDeps; | ||
@@ -330,3 +336,3 @@ context: TAllContext; | ||
TLoaderDeps, TLoaderDataReturn, // TLoaderDataReturn, | ||
TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>; | ||
TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'params'>; | ||
export declare function createRootRouteWithContext<TRouterContext extends {}>(): <TSearchSchemaInput = {}, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = ResolveRouteContext<TRouteContextReturn>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>>(options?: RootRouteOptions<TSearchSchemaInput, TSearchSchema, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>) => RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderData, ResolveLoaderData<TLoaderData>>; | ||
@@ -367,3 +373,3 @@ /** | ||
TRouterContext, Assign<TRouterContext, TRouteContext>, // TAllContext | ||
TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>): RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>; | ||
TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'params'>): RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>; | ||
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed; | ||
@@ -416,4 +422,4 @@ type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never; | ||
export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TSearchSchemaInput = Record<string, unknown>, TSearchSchema = {}, TSearchSchemaUsed = {}, TFullSearchSchemaInput = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TRouteContextReturn = AnyContext, TRouteContext = RouteContext, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren> { | ||
constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'>); | ||
constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id' | 'params'>); | ||
} | ||
export {}; |
@@ -270,6 +270,8 @@ import { createBrowserHistory, createMemoryHistory } from "@tanstack/history"; | ||
const parseErrors = matchedRoutes.map((route) => { | ||
var _a; | ||
let parsedParamsError; | ||
if (route.options.parseParams) { | ||
const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams; | ||
if (parseParams) { | ||
try { | ||
const parsedParams = route.options.parseParams(routeParams); | ||
const parsedParams = parseParams(routeParams); | ||
Object.assign(routeParams, parsedParams); | ||
@@ -431,3 +433,7 @@ } catch (err) { | ||
if (Object.keys(nextParams).length > 0) { | ||
matches == null ? void 0 : matches.map((d) => this.looseRoutesById[d.routeId].options.stringifyParams).filter(Boolean).forEach((fn) => { | ||
matches == null ? void 0 : matches.map((d) => { | ||
var _a2; | ||
const route = this.looseRoutesById[d.routeId]; | ||
return ((_a2 = route == null ? void 0 : route.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams; | ||
}).filter(Boolean).forEach((fn) => { | ||
nextParams = { ...nextParams, ...fn(nextParams) }; | ||
@@ -434,0 +440,0 @@ }); |
{ | ||
"name": "@tanstack/react-router", | ||
"version": "1.41.0", | ||
"version": "1.42.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Tanner Linsley", |
124
src/route.ts
@@ -94,7 +94,33 @@ import invariant from 'tiny-invariant' | ||
export type ParamsFallback< | ||
TPath extends string, | ||
TParams, | ||
> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams | ||
export type ParseParamsFn<TPath extends string, TParams> = ( | ||
rawParams: Record<ParsePathParams<TPath>, string>, | ||
) => TParams extends Record<ParsePathParams<TPath>, any> | ||
? TParams | ||
: Record<ParsePathParams<TPath>, any> | ||
export type StringifyParamsFn<TPath extends string, TParams> = ( | ||
params: TParams, | ||
) => Record<ParsePathParams<TPath>, string> | ||
export type ParamsOptions<TPath extends string, TParams> = { | ||
params?: { | ||
parse: ParseParamsFn<TPath, TParams> | ||
stringify: StringifyParamsFn<TPath, TParams> | ||
} | ||
/** | ||
@deprecated Use params.parse instead | ||
*/ | ||
parseParams?: ParseParamsFn<TPath, TParams> | ||
/** | ||
@deprecated Use params.stringify instead | ||
*/ | ||
stringifyParams?: StringifyParamsFn<TPath, TParams> | ||
} | ||
export interface FullSearchSchemaOption<TFullSearchSchema> { | ||
search: TFullSearchSchema | ||
} | ||
export type FileBaseRouteOptions< | ||
@@ -106,3 +132,3 @@ TPath extends string = string, | ||
TParams = {}, | ||
TAllParams = ParamsFallback<TPath, TParams>, | ||
TAllParams = {}, | ||
TRouteContextReturn = RouteContext, | ||
@@ -114,3 +140,5 @@ TParentAllContext = AnyContext, | ||
> = { | ||
validateSearch?: SearchSchemaValidator<TSearchSchemaInput, TSearchSchema> | ||
validateSearch?: | ||
| ((input: TSearchSchemaInput) => TSearchSchema) | ||
| { parse: (input: TSearchSchemaInput) => TSearchSchema } | ||
shouldReload?: | ||
@@ -125,32 +153,10 @@ | boolean | ||
// If thrown during a preload event, the error will be logged to the console. | ||
beforeLoad?: BeforeLoadFn< | ||
TFullSearchSchema, | ||
TAllParams, | ||
TRouteContextReturn, | ||
TParentAllContext | ||
> | ||
loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps | ||
loader?: RouteLoaderFn< | ||
TAllParams, | ||
NoInfer<TLoaderDeps>, | ||
NoInfer<TAllContext>, | ||
TLoaderDataReturn | ||
> | ||
} & ( | ||
| { | ||
// Both or none | ||
parseParams?: ( | ||
rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>, | ||
) => TParams extends Record<ParsePathParams<TPath>, any> | ||
? TParams | ||
: 'parseParams must return an object' | ||
stringifyParams?: ( | ||
params: NoInfer<ParamsFallback<TPath, TParams>>, | ||
) => Record<ParsePathParams<TPath>, string> | ||
} | ||
| { | ||
stringifyParams?: never | ||
parseParams?: never | ||
} | ||
) | ||
beforeLoad?: ( | ||
ctx: BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllContext>, | ||
) => Promise<TRouteContextReturn> | TRouteContextReturn | void | ||
loaderDeps?: (opts: FullSearchSchemaOption<TFullSearchSchema>) => TLoaderDeps | ||
loader?: ( | ||
ctx: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>, | ||
) => TLoaderDataReturn | Promise<TLoaderDataReturn> | ||
} & ParamsOptions<TPath, TParams> | ||
@@ -165,3 +171,3 @@ export type BaseRouteOptions< | ||
TParams = {}, | ||
TAllParams = ParamsFallback<TPath, TParams>, | ||
TAllParams = {}, | ||
TRouteContextReturn = RouteContext, | ||
@@ -189,12 +195,10 @@ TParentAllContext = AnyContext, | ||
type BeforeLoadFn< | ||
in out TFullSearchSchema, | ||
in out TAllParams, | ||
TRouteContextReturn, | ||
in out TParentAllContext, | ||
> = (opts: { | ||
search: TFullSearchSchema | ||
export interface BeforeLoadContext< | ||
TFullSearchSchema, | ||
TAllParams, | ||
TParentAllContext, | ||
> extends FullSearchSchemaOption<TFullSearchSchema> { | ||
abortController: AbortController | ||
preload: boolean | ||
params: TAllParams | ||
params: Expand<TAllParams> | ||
context: TParentAllContext | ||
@@ -208,3 +212,3 @@ location: ParsedLocation | ||
cause: 'preload' | 'enter' | 'stay' | ||
}) => Promise<TRouteContextReturn> | TRouteContextReturn | void | ||
} | ||
@@ -296,17 +300,2 @@ export type UpdatableRouteOptions< | ||
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn< | ||
TPath, | ||
TParams | ||
> | ||
export type ParseParamsFn<TPath extends string, TParams> = ( | ||
rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>, | ||
) => TParams extends Record<ParsePathParams<TPath>, any> | ||
? TParams | ||
: 'parseParams must return an object' | ||
export type ParseParamsObj<TPath extends string, TParams> = { | ||
parse?: ParseParamsFn<TPath, TParams> | ||
} | ||
// The parse type here allows a zod schema to be passed directly to the validator | ||
@@ -332,3 +321,3 @@ export type SearchSchemaValidator<TInput, TReturn> = | ||
match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>, | ||
) => Promise<TLoaderData> | TLoaderData | ||
) => TLoaderData | Promise<TLoaderData> | ||
@@ -342,3 +331,3 @@ export interface LoaderFnContext< | ||
preload: boolean | ||
params: TAllParams | ||
params: Expand<TAllParams> | ||
deps: TLoaderDeps | ||
@@ -1005,2 +994,3 @@ context: TAllContext | ||
| 'stringifyParams' | ||
| 'params' | ||
> | ||
@@ -1140,2 +1130,3 @@ | ||
| 'stringifyParams' | ||
| 'params' | ||
>, | ||
@@ -1309,3 +1300,8 @@ ) { | ||
>, | ||
'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id' | ||
| 'caseSensitive' | ||
| 'parseParams' | ||
| 'stringifyParams' | ||
| 'path' | ||
| 'id' | ||
| 'params' | ||
>, | ||
@@ -1312,0 +1308,0 @@ ) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1370062
16988