@tanstack/router-core 1.114.22 → 1.114.24
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.map +1 -1
- package/dist/cjs/Matches.d.cts +25 -0
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +69 -0
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/redirect.d.cts +15 -0
- package/dist/cjs/route.cjs +108 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/route.d.cts +54 -0
- package/dist/esm/Matches.d.ts +25 -0
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/link.d.ts +69 -0
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirect.d.ts +15 -0
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.d.ts +54 -0
- package/dist/esm/route.js +108 -0
- package/dist/esm/route.js.map +1 -0
- package/package.json +1 -1
- package/src/Matches.ts +25 -0
- package/src/index.ts +3 -2
- package/src/link.ts +69 -6
- package/src/redirect.ts +15 -0
- package/src/route.ts +368 -0
package/dist/cjs/route.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LazyRoute } from './fileRoute.cjs';
|
|
2
|
+
import { NotFoundError } from './not-found.cjs';
|
|
2
3
|
import { NavigateOptions, ParsePathParams } from './link.cjs';
|
|
3
4
|
import { ParsedLocation } from './location.cjs';
|
|
4
5
|
import { AnyRouteMatch, MakeRouteMatchFromRoute, MakeRouteMatchUnion, RouteMatch } from './Matches.cjs';
|
|
@@ -366,4 +367,57 @@ export type ErrorComponentProps = {
|
|
|
366
367
|
export type NotFoundRouteProps = {
|
|
367
368
|
data: unknown;
|
|
368
369
|
};
|
|
370
|
+
export declare class BaseRoute<in out TParentRoute extends AnyRoute = AnyRoute, in out TPath extends string = '/', in out TFullPath extends string = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends string = string, in out TId extends string = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> implements Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
371
|
+
isRoot: TParentRoute extends AnyRoute ? true : false;
|
|
372
|
+
options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>;
|
|
373
|
+
parentRoute: TParentRoute;
|
|
374
|
+
private _id;
|
|
375
|
+
private _path;
|
|
376
|
+
private _fullPath;
|
|
377
|
+
private _to;
|
|
378
|
+
private _ssr;
|
|
379
|
+
get to(): TrimPathRight<TFullPath>;
|
|
380
|
+
get id(): TId;
|
|
381
|
+
get path(): TPath;
|
|
382
|
+
get fullPath(): TFullPath;
|
|
383
|
+
get ssr(): boolean;
|
|
384
|
+
children?: TChildren;
|
|
385
|
+
originalIndex?: number;
|
|
386
|
+
rank: number;
|
|
387
|
+
lazyFn?: () => Promise<LazyRoute>;
|
|
388
|
+
_lazyPromise?: Promise<void>;
|
|
389
|
+
_componentsPromise?: Promise<Array<void>>;
|
|
390
|
+
constructor(options?: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>);
|
|
391
|
+
types: RouteTypes<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes>;
|
|
392
|
+
init: (opts: {
|
|
393
|
+
originalIndex: number;
|
|
394
|
+
defaultSsr?: boolean;
|
|
395
|
+
}) => void;
|
|
396
|
+
addChildren: RouteAddChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
397
|
+
_addFileChildren: RouteAddFileChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
398
|
+
_addFileTypes: RouteAddFileTypesFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
399
|
+
updateLoader: <TNewLoaderFn>(options: {
|
|
400
|
+
loader: Constrain<TNewLoaderFn, RouteLoaderFn<TParentRoute, TCustomId, TParams, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>>;
|
|
401
|
+
}) => BaseRoute<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TNewLoaderFn, TChildren, TFileRouteTypes>;
|
|
402
|
+
update: (options: UpdatableRouteOptions<TParentRoute, TCustomId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>) => this;
|
|
403
|
+
lazy: RouteLazyFn<this>;
|
|
404
|
+
}
|
|
405
|
+
export declare class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
406
|
+
id: TId;
|
|
407
|
+
constructor({ id }: {
|
|
408
|
+
id: TId;
|
|
409
|
+
});
|
|
410
|
+
notFound: (opts?: NotFoundError) => NotFoundError;
|
|
411
|
+
}
|
|
412
|
+
export declare class BaseRootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRoute<any, // TParentRoute
|
|
413
|
+
'/', // TPath
|
|
414
|
+
'/', // TFullPath
|
|
415
|
+
string, // TCustomId
|
|
416
|
+
RootRouteId, // TId
|
|
417
|
+
TSearchValidator, // TSearchValidator
|
|
418
|
+
{}, // TParams
|
|
419
|
+
TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, // TChildren
|
|
420
|
+
TFileRouteTypes> {
|
|
421
|
+
constructor(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>);
|
|
422
|
+
}
|
|
369
423
|
export {};
|
package/dist/esm/Matches.d.ts
CHANGED
|
@@ -76,9 +76,34 @@ export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<TRoute
|
|
|
76
76
|
export type MakeRouteMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId = RouteIds<TRouteTree>, TStrict extends boolean = true> = RouteMatch<TRouteId, RouteById<TRouteTree, TRouteId>['types']['fullPath'], TStrict extends false ? AllParams<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['allParams'], TStrict extends false ? FullSearchSchema<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'], TStrict extends false ? AllLoaderData<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['loaderData'], TStrict extends false ? AllContext<TRouteTree> : RouteById<TRouteTree, TRouteId>['types']['allContext'], RouteById<TRouteTree, TRouteId>['types']['loaderDeps']>;
|
|
77
77
|
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>;
|
|
78
78
|
export type MakeRouteMatchUnion<TRouter extends AnyRouter = RegisteredRouter, TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>> = TRoute extends any ? RouteMatch<TRoute['id'], TRoute['fullPath'], TRoute['types']['allParams'], TRoute['types']['fullSearchSchema'], TRoute['types']['loaderData'], TRoute['types']['allContext'], TRoute['types']['loaderDeps']> : never;
|
|
79
|
+
/**
|
|
80
|
+
* The `MatchRouteOptions` type is used to describe the options that can be used when matching a route.
|
|
81
|
+
*
|
|
82
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#matchrouteoptions-type)
|
|
83
|
+
*/
|
|
79
84
|
export interface MatchRouteOptions {
|
|
85
|
+
/**
|
|
86
|
+
* If `true`, will match against pending location instead of the current location.
|
|
87
|
+
*
|
|
88
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#pending-property)
|
|
89
|
+
*/
|
|
80
90
|
pending?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* If `true`, will match against the current location with case sensitivity.
|
|
93
|
+
*
|
|
94
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#casesensitive-property)
|
|
95
|
+
*/
|
|
81
96
|
caseSensitive?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* If `true`, will match against the current location's search params using a deep inclusive check. e.g. `{ a: 1 }` will match for a current location of `{ a: 1, b: 2 }`.
|
|
99
|
+
*
|
|
100
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#includesearch-property)
|
|
101
|
+
*/
|
|
82
102
|
includeSearch?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* If `true`, will match against the current location using a fuzzy match. e.g. `/posts` will match for a current location of `/posts/123`.
|
|
105
|
+
*
|
|
106
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#fuzzy-property)
|
|
107
|
+
*/
|
|
83
108
|
fuzzy?: boolean;
|
|
84
109
|
}
|
package/dist/esm/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","sources":["../../src/Matches.ts"],"sourcesContent":["import type { AnyRoute, StaticDataRouteOption } from './route'\nimport type {\n AllContext,\n AllLoaderData,\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteIds,\n} from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { Constrain, ControlledPromise } from './utils'\n\nexport type AnyMatchAndValue = { match: any; value: any }\n\nexport type FindValueByIndex<\n TKey,\n TValue extends ReadonlyArray<any>,\n> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never\n\nexport type FindValueByKey<TKey, TValue> =\n TValue extends ReadonlyArray<any>\n ? FindValueByIndex<TKey, TValue>\n : TValue[TKey & keyof TValue]\n\nexport type CreateMatchAndValue<TMatch, TValue> = TValue extends any\n ? {\n match: TMatch\n value: TValue\n }\n : never\n\nexport type NextMatchAndValue<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? CreateMatchAndValue<\n TMatchAndValue['match'],\n FindValueByKey<TKey, TMatchAndValue['value']>\n >\n : never\n\nexport type IsMatchKeyOf<TValue> =\n TValue extends ReadonlyArray<any>\n ? number extends TValue['length']\n ? `${number}`\n : keyof TValue & `${number}`\n : TValue extends object\n ? keyof TValue & string\n : never\n\nexport type IsMatchPath<\n TParentPath extends string,\n TMatchAndValue extends AnyMatchAndValue,\n> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`\n\nexport type IsMatchResult<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? TKey extends keyof TMatchAndValue['value']\n ? TMatchAndValue['match']\n : never\n : never\n\nexport type IsMatchParse<\n TPath,\n TMatchAndValue extends AnyMatchAndValue,\n TParentPath extends string = '',\n> = TPath extends `${string}.${string}`\n ? TPath extends `${infer TFirst}.${infer TRest}`\n ? IsMatchParse<\n TRest,\n NextMatchAndValue<TFirst, TMatchAndValue>,\n `${TParentPath}${TFirst}.`\n >\n : never\n : {\n path: IsMatchPath<TParentPath, TMatchAndValue>\n result: IsMatchResult<TPath, TMatchAndValue>\n }\n\nexport type IsMatch<TMatch, TPath> = IsMatchParse<\n TPath,\n TMatch extends any ? { match: TMatch; value: TMatch } : never\n>\n\n/**\n * Narrows matches based on a path\n * @experimental\n */\nexport const isMatch = <TMatch, TPath extends string>(\n match: TMatch,\n path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,\n): match is IsMatch<TMatch, TPath>['result'] => {\n const parts = (path as string).split('.')\n let part\n let value: any = match\n\n while ((part = parts.shift()) != null && value != null) {\n value = value[part]\n }\n\n return value != null\n}\n\nexport interface DefaultRouteMatchExtensions {\n scripts?: unknown\n links?: unknown\n headScripts?: unknown\n meta?: unknown\n}\n\nexport interface RouteMatchExtensions extends DefaultRouteMatchExtensions {}\n\nexport interface RouteMatch<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n out TLoaderData,\n out TAllContext,\n out TLoaderDeps,\n> extends RouteMatchExtensions {\n id: string\n routeId: TRouteId\n fullPath: TFullPath\n index: number\n pathname: string\n params: TAllParams\n _strictParams: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: ControlledPromise<void>\n beforeLoadPromise?: ControlledPromise<void>\n loaderPromise?: ControlledPromise<void>\n loaderData?: TLoaderData\n __routeContext: Record<string, unknown>\n __beforeLoadContext: Record<string, unknown>\n context: TAllContext\n search: TFullSearchSchema\n _strictSearch: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n pendingTimeout?: ReturnType<typeof setTimeout>\n}\n\nexport type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<\n TRoute['types']['id'],\n TRoute['types']['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n>\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n> = RouteMatch<\n TRouteId,\n RouteById<TRouteTree, TRouteId>['types']['fullPath'],\n TStrict extends false\n ? AllParams<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allParams'],\n TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],\n TStrict extends false\n ? AllLoaderData<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['loaderData'],\n TStrict extends false\n ? AllContext<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allContext'],\n RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport type MakeRouteMatchUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? RouteMatch<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n >\n : never\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n"],"names":[],"mappings":"AA2Fa,MAAA,UAAU,CACrB,OACA,SAC8C;AACxC,QAAA,QAAS,KAAgB,MAAM,GAAG;AACpC,MAAA;AACJ,MAAI,QAAa;AAEjB,UAAQ,OAAO,MAAM,MAAY,MAAA,QAAQ,SAAS,MAAM;AACtD,YAAQ,MAAM,IAAI;AAAA,EAAA;AAGpB,SAAO,SAAS;AAClB;"}
|
|
1
|
+
{"version":3,"file":"Matches.js","sources":["../../src/Matches.ts"],"sourcesContent":["import type { AnyRoute, StaticDataRouteOption } from './route'\nimport type {\n AllContext,\n AllLoaderData,\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteIds,\n} from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { Constrain, ControlledPromise } from './utils'\n\nexport type AnyMatchAndValue = { match: any; value: any }\n\nexport type FindValueByIndex<\n TKey,\n TValue extends ReadonlyArray<any>,\n> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never\n\nexport type FindValueByKey<TKey, TValue> =\n TValue extends ReadonlyArray<any>\n ? FindValueByIndex<TKey, TValue>\n : TValue[TKey & keyof TValue]\n\nexport type CreateMatchAndValue<TMatch, TValue> = TValue extends any\n ? {\n match: TMatch\n value: TValue\n }\n : never\n\nexport type NextMatchAndValue<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? CreateMatchAndValue<\n TMatchAndValue['match'],\n FindValueByKey<TKey, TMatchAndValue['value']>\n >\n : never\n\nexport type IsMatchKeyOf<TValue> =\n TValue extends ReadonlyArray<any>\n ? number extends TValue['length']\n ? `${number}`\n : keyof TValue & `${number}`\n : TValue extends object\n ? keyof TValue & string\n : never\n\nexport type IsMatchPath<\n TParentPath extends string,\n TMatchAndValue extends AnyMatchAndValue,\n> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`\n\nexport type IsMatchResult<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? TKey extends keyof TMatchAndValue['value']\n ? TMatchAndValue['match']\n : never\n : never\n\nexport type IsMatchParse<\n TPath,\n TMatchAndValue extends AnyMatchAndValue,\n TParentPath extends string = '',\n> = TPath extends `${string}.${string}`\n ? TPath extends `${infer TFirst}.${infer TRest}`\n ? IsMatchParse<\n TRest,\n NextMatchAndValue<TFirst, TMatchAndValue>,\n `${TParentPath}${TFirst}.`\n >\n : never\n : {\n path: IsMatchPath<TParentPath, TMatchAndValue>\n result: IsMatchResult<TPath, TMatchAndValue>\n }\n\nexport type IsMatch<TMatch, TPath> = IsMatchParse<\n TPath,\n TMatch extends any ? { match: TMatch; value: TMatch } : never\n>\n\n/**\n * Narrows matches based on a path\n * @experimental\n */\nexport const isMatch = <TMatch, TPath extends string>(\n match: TMatch,\n path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,\n): match is IsMatch<TMatch, TPath>['result'] => {\n const parts = (path as string).split('.')\n let part\n let value: any = match\n\n while ((part = parts.shift()) != null && value != null) {\n value = value[part]\n }\n\n return value != null\n}\n\nexport interface DefaultRouteMatchExtensions {\n scripts?: unknown\n links?: unknown\n headScripts?: unknown\n meta?: unknown\n}\n\nexport interface RouteMatchExtensions extends DefaultRouteMatchExtensions {}\n\nexport interface RouteMatch<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n out TLoaderData,\n out TAllContext,\n out TLoaderDeps,\n> extends RouteMatchExtensions {\n id: string\n routeId: TRouteId\n fullPath: TFullPath\n index: number\n pathname: string\n params: TAllParams\n _strictParams: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: ControlledPromise<void>\n beforeLoadPromise?: ControlledPromise<void>\n loaderPromise?: ControlledPromise<void>\n loaderData?: TLoaderData\n __routeContext: Record<string, unknown>\n __beforeLoadContext: Record<string, unknown>\n context: TAllContext\n search: TFullSearchSchema\n _strictSearch: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n pendingTimeout?: ReturnType<typeof setTimeout>\n}\n\nexport type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<\n TRoute['types']['id'],\n TRoute['types']['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n>\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n> = RouteMatch<\n TRouteId,\n RouteById<TRouteTree, TRouteId>['types']['fullPath'],\n TStrict extends false\n ? AllParams<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allParams'],\n TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],\n TStrict extends false\n ? AllLoaderData<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['loaderData'],\n TStrict extends false\n ? AllContext<TRouteTree>\n : RouteById<TRouteTree, TRouteId>['types']['allContext'],\n RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport type MakeRouteMatchUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? RouteMatch<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema'],\n TRoute['types']['loaderData'],\n TRoute['types']['allContext'],\n TRoute['types']['loaderDeps']\n >\n : never\n\n/**\n * The `MatchRouteOptions` type is used to describe the options that can be used when matching a route.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#matchrouteoptions-type)\n */\nexport interface MatchRouteOptions {\n /**\n * If `true`, will match against pending location instead of the current location.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#pending-property)\n */\n pending?: boolean\n /**\n * If `true`, will match against the current location with case sensitivity.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#casesensitive-property)\n */\n caseSensitive?: boolean\n /**\n * If `true`, will match against the current location's search params using a deep inclusive check. e.g. `{ a: 1 }` will match for a current location of `{ a: 1, b: 2 }`.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#includesearch-property)\n */\n includeSearch?: boolean\n /**\n * If `true`, will match against the current location using a fuzzy match. e.g. `/posts` will match for a current location of `/posts/123`.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#fuzzy-property)\n */\n fuzzy?: boolean\n}\n"],"names":[],"mappings":"AA2Fa,MAAA,UAAU,CACrB,OACA,SAC8C;AACxC,QAAA,QAAS,KAAgB,MAAM,GAAG;AACpC,MAAA;AACJ,MAAI,QAAa;AAEjB,UAAQ,OAAO,MAAM,MAAY,MAAA,QAAQ,SAAS,MAAM;AACtD,YAAQ,MAAM,IAAI;AAAA,EAAA;AAGpB,SAAO,SAAS;AAClB;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export type { Segment } from './path.js';
|
|
|
14
14
|
export { encode, decode } from './qss.js';
|
|
15
15
|
export { rootRouteId } from './root.js';
|
|
16
16
|
export type { RootRouteId } from './root.js';
|
|
17
|
-
export
|
|
17
|
+
export { BaseRoute, BaseRouteApi, BaseRootRoute } from './route.js';
|
|
18
|
+
export type { AnyPathParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, SearchFilter, SearchMiddlewareContext, SearchMiddleware, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, InferAllParams, InferAllContext, MetaDescriptor, RouteLinkEntry, SearchValidator, AnySearchValidator, DefaultSearchValidator, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ParseSplatParams, SplatParams, ResolveParams, ParseParamsFn, StringifyParamsFn, ParamsOptions, UpdatableStaticRouteOption, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveRouteContext, ResolveLoaderData, RoutePrefix, TrimPath, TrimPathLeft, TrimPathRight, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchemaFn, ResolveSearchSchema, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllContext, BeforeLoadContextParameter, RouteContextParameter, ResolveAllParamsFromParent, AnyRoute, Route, RouteTypes, FullSearchSchemaOption, RemountDepsOptions, MakeRemountDepsOptionsUnion, ResolveFullPath, AnyRouteWithContext, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, RouteContextFn, BeforeLoadFn, ContextOptions, RouteContextOptions, BeforeLoadContextOptions, RootRouteOptions, UpdatableRouteOptionsExtensions, RouteConstraints, RouteTypesById, RouteMask, RouteExtensions, RouteLazyFn, RouteAddChildrenFn, RouteAddFileChildrenFn, RouteAddFileTypesFn, } from './route.js';
|
|
18
19
|
export { defaultSerializeError, getLocationChangeInfo } from './router.js';
|
|
19
20
|
export type { ViewTransitionOptions, ExtractedBaseEntry, ExtractedStream, ExtractedPromise, ExtractedEntry, StreamState, TrailingSlashOption, Register, AnyRouter, AnyRouterWithContext, RegisteredRouter, RouterState, BuildNextOptions, RouterListener, RouterEvent, ListenerFn, RouterEvents, MatchRoutesOpts, RouterOptionsExtensions, Router, DefaultRemountDepsFn, PreloadRouteFn, MatchRouteFn, RouterContextOptions, RouterOptions, RouterConstructorOptions, UpdateFn, ParseLocationFn, InvalidateFn, ControllablePromise, InjectedHtmlEntry, RouterErrorSerializer, MatchedRoutesResult, EmitFn, LoadFn, GetMatchFn, SubscribeFn, UpdateMatchFn, CommitLocationFn, GetMatchRoutesFn, MatchRoutesFn, StartTransitionFn, LoadRouteChunkFn, ServerSrr, ClearCacheFn, } from './router.js';
|
|
20
21
|
export type { MatchLocation, CommitLocationOptions, NavigateFn, BuildLocationFn, } from './RouterProvider.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { isMatch } from "./Matches.js";
|
|
|
4
4
|
import { cleanPath, exactPathTest, interpolatePath, joinPaths, matchByPath, matchPathname, parsePathname, removeBasepath, removeTrailingSlash, resolvePath, trimPath, trimPathLeft, trimPathRight } from "./path.js";
|
|
5
5
|
import { decode, encode } from "./qss.js";
|
|
6
6
|
import { rootRouteId } from "./root.js";
|
|
7
|
+
import { BaseRootRoute, BaseRoute, BaseRouteApi } from "./route.js";
|
|
7
8
|
import { defaultSerializeError, getLocationChangeInfo } from "./router.js";
|
|
8
9
|
import { retainSearchParams, stripSearchParams } from "./searchMiddleware.js";
|
|
9
10
|
import { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith } from "./searchParams.js";
|
|
@@ -12,6 +13,9 @@ import { isRedirect, isResolvedRedirect, redirect } from "./redirect.js";
|
|
|
12
13
|
import { isNotFound, notFound } from "./not-found.js";
|
|
13
14
|
import { defaultGetScrollRestorationKey, getCssSelector, restoreScroll, scrollRestorationCache, setupScrollRestoration, storageKey } from "./scroll-restoration.js";
|
|
14
15
|
export {
|
|
16
|
+
BaseRootRoute,
|
|
17
|
+
BaseRoute,
|
|
18
|
+
BaseRouteApi,
|
|
15
19
|
TSR_DEFERRED_PROMISE,
|
|
16
20
|
cleanPath,
|
|
17
21
|
createControlledPromise,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/dist/esm/link.d.ts
CHANGED
|
@@ -22,15 +22,64 @@ export type RelativeToCurrentPath<TRouter extends AnyRouter, TFrom extends strin
|
|
|
22
22
|
export type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> = (string extends TFrom ? CurrentPath<TRouter> : TFrom extends `/` ? never : CurrentPath<TRouter>) | (string extends TFrom ? ParentPath<TRouter> : TFrom extends `/` ? never : ParentPath<TRouter>) | RouteToPath<TRouter> | (TFrom extends '/' ? never : string extends TFrom ? never : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>);
|
|
23
23
|
export type RelativeToPathAutoComplete<TRouter extends AnyRouter, TFrom extends string, TTo extends string> = string extends TTo ? string : string extends TFrom ? AbsoluteToPath<TRouter, TFrom> : TTo & `..${string}` extends never ? TTo & `.${string}` extends never ? AbsoluteToPath<TRouter, TFrom> : RelativeToCurrentPath<TRouter, TFrom, TTo> : RelativeToParentPath<TRouter, TFrom, TTo>;
|
|
24
24
|
export type NavigateOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.', TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps;
|
|
25
|
+
/**
|
|
26
|
+
* The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.
|
|
27
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)
|
|
28
|
+
*/
|
|
25
29
|
export interface NavigateOptionProps {
|
|
30
|
+
/**
|
|
31
|
+
* If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.
|
|
32
|
+
* If set to `false`, the router will not scroll the element with an id matching the hash into view.
|
|
33
|
+
* If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.
|
|
34
|
+
* @default true
|
|
35
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)
|
|
36
|
+
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
|
|
37
|
+
*/
|
|
26
38
|
hashScrollIntoView?: boolean | ScrollIntoViewOptions;
|
|
39
|
+
/**
|
|
40
|
+
* `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
|
|
41
|
+
* @default false
|
|
42
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)
|
|
43
|
+
*/
|
|
27
44
|
replace?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
|
|
47
|
+
* If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.
|
|
48
|
+
* @default true
|
|
49
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)
|
|
50
|
+
*/
|
|
28
51
|
resetScroll?: boolean;
|
|
29
52
|
/** @deprecated All navigations now use startTransition under the hood */
|
|
30
53
|
startTransition?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.
|
|
56
|
+
* If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`
|
|
57
|
+
* where `types` will be the strings array passed with `ViewTransitionOptions["types"]`.
|
|
58
|
+
* If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.
|
|
59
|
+
*
|
|
60
|
+
* If the browser does not support this api, this option will be ignored.
|
|
61
|
+
* @default false
|
|
62
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)
|
|
63
|
+
* @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)
|
|
64
|
+
* @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)
|
|
65
|
+
*/
|
|
31
66
|
viewTransition?: boolean | ViewTransitionOptions;
|
|
67
|
+
/**
|
|
68
|
+
* If `true`, navigation will ignore any blockers that might prevent it.
|
|
69
|
+
* @default false
|
|
70
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)
|
|
71
|
+
*/
|
|
32
72
|
ignoreBlocker?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.
|
|
75
|
+
* @default false
|
|
76
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)
|
|
77
|
+
*/
|
|
33
78
|
reloadDocument?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.
|
|
81
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)
|
|
82
|
+
*/
|
|
34
83
|
href?: string;
|
|
35
84
|
}
|
|
36
85
|
export type ToOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = '.', TMaskFrom extends string = TFrom, TMaskTo extends string = '.'> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>;
|
|
@@ -83,10 +132,30 @@ export type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> = IsRequir
|
|
|
83
132
|
export type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> = IsRequired<TRouter, 'PATH', TFrom, TTo> extends never ? MakeOptionalPathParams<TRouter, TFrom, TTo> : MakeRequiredPathParams<TRouter, TFrom, TTo>;
|
|
84
133
|
export type ToPathOption<TRouter extends AnyRouter = AnyRouter, TFrom extends string = string, TTo extends string | undefined = string> = ConstrainLiteral<TTo, RelativeToPathAutoComplete<TRouter, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>>;
|
|
85
134
|
export type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<TFrom, RoutePaths<TRouter['routeTree']>>;
|
|
135
|
+
/**
|
|
136
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)
|
|
137
|
+
*/
|
|
86
138
|
export interface ActiveOptions {
|
|
139
|
+
/**
|
|
140
|
+
* If true, the link will be active if the current route matches the `to` route path exactly (no children routes)
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
87
143
|
exact?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* If true, the link will only be active if the current URL hash matches the `hash` prop
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
88
148
|
includeHash?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* If true, the link will only be active if the current URL search params inclusively match the `search` prop
|
|
151
|
+
* @default true
|
|
152
|
+
*/
|
|
89
153
|
includeSearch?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* This modifies the `includeSearch` behavior.
|
|
156
|
+
* If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.
|
|
157
|
+
* @default false
|
|
158
|
+
*/
|
|
90
159
|
explicitUndefined?: boolean;
|
|
91
160
|
}
|
|
92
161
|
export interface LinkOptionsProps {
|
package/dist/esm/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../src/link.ts"],"sourcesContent":["import type { HistoryState, ParsedHistoryState } from '@tanstack/history'\nimport type {\n AllParams,\n CatchAllPaths,\n CurrentPath,\n FullSearchSchema,\n FullSearchSchemaInput,\n ParentPath,\n RouteByPath,\n RouteByToPath,\n RoutePaths,\n RouteToPath,\n ToPath,\n} from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ViewTransitionOptions,\n} from './router'\nimport type {\n ConstrainLiteral,\n Expand,\n MakeDifferenceOptional,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n Updater,\n WithoutEmpty,\n} from './utils'\nimport type { ParsedLocation } from './location'\n\nexport type IsRequiredParams<TParams> =\n Record<never, never> extends TParams ? never : true\n\nexport type ParsePathParams<T extends string, TAcc = never> = T &\n `${string}$${string}` extends never\n ? TAcc\n : T extends `${string}$${infer TPossiblyParam}`\n ? TPossiblyParam extends ''\n ? TAcc\n : TPossiblyParam & `${string}/${string}` extends never\n ? TPossiblyParam | TAcc\n : TPossiblyParam extends `${infer TParam}/${infer TRest}`\n ? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>\n : never\n : TAcc\n\nexport type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`\n\nexport type RemoveTrailingSlashes<T> = T & `${string}/` extends never\n ? T\n : T extends `${infer R}/`\n ? R\n : T\n\nexport type AddLeadingSlash<T> = T & `/${string}` extends never\n ? `/${T & string}`\n : T\n\nexport type RemoveLeadingSlashes<T> = T & `/${string}` extends never\n ? T\n : T extends `/${infer R}`\n ? R\n : T\n\ntype JoinPath<TLeft extends string, TRight extends string> = TRight extends ''\n ? TLeft\n : TLeft extends ''\n ? TRight\n : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`\n\ntype RemoveLastSegment<\n T extends string,\n TAcc extends string = '',\n> = T extends `${infer TSegment}/${infer TRest}`\n ? TRest & `${string}/${string}` extends never\n ? TRest extends ''\n ? TAcc\n : `${TAcc}${TSegment}`\n : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>\n : TAcc\n\nexport type ResolveCurrentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '.'\n ? TFrom\n : TTo extends './'\n ? AddTrailingSlash<TFrom>\n : TTo & `./${string}` extends never\n ? never\n : TTo extends `./${infer TRest}`\n ? AddLeadingSlash<JoinPath<TFrom, TRest>>\n : never\n\nexport type ResolveParentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '../' | '..'\n ? TFrom extends '' | '/'\n ? never\n : AddLeadingSlash<RemoveLastSegment<TFrom>>\n : TTo & `../${string}` extends never\n ? AddLeadingSlash<JoinPath<TFrom, TTo>>\n : TFrom extends '' | '/'\n ? never\n : TTo extends `../${infer ToRest}`\n ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom\n ? TTo\n : string extends TTo\n ? TFrom\n : undefined extends TTo\n ? TFrom\n : TTo extends string\n ? TFrom extends string\n ? TTo extends `/${string}`\n ? TTo\n : TTo extends `..${string}`\n ? ResolveParentPath<TFrom, TTo>\n : TTo extends `.${string}`\n ? ResolveCurrentPath<TFrom, TTo>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n : never\n : never\n\nexport type FindDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n> = `${TPrefix}/${string}` & RouteToPath<TRouter>\n\nexport type InferDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n TPaths = FindDescendantToPaths<TRouter, TPrefix>,\n> = TPaths extends `${TPrefix}/`\n ? never\n : TPaths extends `${TPrefix}/${infer TRest}`\n ? TRest\n : never\n\nexport type RelativeToPath<\n TRouter extends AnyRouter,\n TTo extends string,\n TResolvedPath extends string,\n> =\n | (TResolvedPath & RouteToPath<TRouter> extends never\n ? never\n : ToPath<TRouter, TTo>)\n | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`\n\nexport type RelativeToParentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> =\n | RelativeToPath<TRouter, TTo, TResolvedPath>\n | (TTo extends `${string}..` | `${string}../`\n ? TResolvedPath extends '/' | ''\n ? never\n : FindDescendantToPaths<\n TRouter,\n RemoveTrailingSlashes<TResolvedPath>\n > extends never\n ? never\n : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`\n : never)\n\nexport type RelativeToCurrentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>\n\nexport type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =\n | (string extends TFrom\n ? CurrentPath<TRouter>\n : TFrom extends `/`\n ? never\n : CurrentPath<TRouter>)\n | (string extends TFrom\n ? ParentPath<TRouter>\n : TFrom extends `/`\n ? never\n : ParentPath<TRouter>)\n | RouteToPath<TRouter>\n | (TFrom extends '/'\n ? never\n : string extends TFrom\n ? never\n : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)\n\nexport type RelativeToPathAutoComplete<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n> = string extends TTo\n ? string\n : string extends TFrom\n ? AbsoluteToPath<TRouter, TFrom>\n : TTo & `..${string}` extends never\n ? TTo & `.${string}` extends never\n ? AbsoluteToPath<TRouter, TFrom>\n : RelativeToCurrentPath<TRouter, TFrom, TTo>\n : RelativeToParentPath<TRouter, TFrom, TTo>\n\nexport type NavigateOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps\n\nexport interface NavigateOptionProps {\n // if set to `true`, the router will scroll the element with an id matching the hash into view with default ScrollIntoViewOptions.\n // if set to `false`, the router will not scroll the element with an id matching the hash into view.\n // if set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.\n hashScrollIntoView?: boolean | ScrollIntoViewOptions\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n /** @deprecated All navigations now use startTransition under the hood */\n startTransition?: boolean\n // if set to `true`, the router will wrap the resulting navigation in a document.startViewTransition() call.\n // if set to `ViewTransitionOptions`, the router will pass the `types` field to document.startViewTransition({update: fn, types: viewTransition.types}) call\n viewTransition?: boolean | ViewTransitionOptions\n ignoreBlocker?: boolean\n reloadDocument?: boolean\n href?: string\n}\n\nexport type ToOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>\n\nexport interface MaskOptions<\n in out TRouter extends AnyRouter,\n in out TMaskFrom extends string,\n in out TMaskTo extends string,\n> {\n _fromLocation?: ParsedLocation\n mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TMaskFrom extends string = string,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n SearchParamOptions<TRouter, TFrom, TTo> &\n PathParamOptions<TRouter, TFrom, TTo>\n\nexport interface RequiredToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport interface OptionalToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to?: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport type MakeToRequired<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string | undefined,\n> = string extends TFrom\n ? string extends TTo\n ? OptionalToOptions<TRouter, TFrom, TTo>\n : TTo & CatchAllPaths<TRouter> extends never\n ? RequiredToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n\nexport type ToSubOptionsProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n> = MakeToRequired<TRouter, TFrom, TTo> & {\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>\n from?: FromPathOption<TRouter, TFrom> & {}\n}\n\nexport type ParamsReducerFn<\n in out TRouter extends AnyRouter,\n in out TParamVariant extends ParamVariant,\n in out TFrom,\n in out TTo,\n> = (\n current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,\n) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n\ntype ParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})\n\ntype ParamVariant = 'PATH' | 'SEARCH'\n\nexport type ResolveRoute<\n TRouter extends AnyRouter,\n TFrom,\n TTo,\n TPath = ResolveRelativePath<TFrom, TTo>,\n> = TPath extends string\n ? TFrom extends TPath\n ? RouteByPath<TRouter['routeTree'], TPath>\n : RouteByToPath<TRouter, TPath>\n : never\n\ntype ResolveFromParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'\n\ntype ResolveFromAllParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchema<TRouter['routeTree']>\n\ntype ResolveFromParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n> = string extends TFrom\n ? ResolveFromAllParams<TRouter, TParamVariant>\n : RouteByPath<\n TRouter['routeTree'],\n TFrom\n >['types'][ResolveFromParamType<TParamVariant>]\n\ntype ResolveToParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'\n\ntype ResolveAllToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchemaInput<TRouter['routeTree']>\n\nexport type ResolveToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : string extends TPath\n ? ResolveAllToParams<TRouter, TParamVariant>\n : TPath extends CatchAllPaths<TRouter>\n ? ResolveAllToParams<TRouter, TParamVariant>\n : ResolveRoute<\n TRouter,\n TFrom,\n TTo\n >['types'][ResolveToParamType<TParamVariant>]\n : never\n\ntype ResolveRelativeToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,\n> = TParamVariant extends 'SEARCH'\n ? TToParams\n : string extends TFrom\n ? TToParams\n : MakeDifferenceOptional<\n ResolveFromParams<TRouter, TParamVariant, TFrom>,\n TToParams\n >\n\nexport interface MakeOptionalSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})\n}\n\nexport interface MakeOptionalPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})\n}\n\ntype MakeRequiredParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | (string extends TFrom\n ? never\n : ResolveFromParams<TRouter, TParamVariant, TFrom> extends WithoutEmpty<\n PickRequired<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n >\n ? true\n : never)\n | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})\n\nexport interface MakeRequiredPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}\n}\n\nexport interface MakeRequiredSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}\n}\n\nexport type IsRequired<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : TPath extends CatchAllPaths<TRouter>\n ? never\n : IsRequiredParams<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n : never\n\nexport type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never\n ? MakeOptionalSearchParams<TRouter, TFrom, TTo>\n : MakeRequiredSearchParams<TRouter, TFrom, TTo>\n\nexport type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'PATH', TFrom, TTo> extends never\n ? MakeOptionalPathParams<TRouter, TFrom, TTo>\n : MakeRequiredPathParams<TRouter, TFrom, TTo>\n\nexport type ToPathOption<\n TRouter extends AnyRouter = AnyRouter,\n TFrom extends string = string,\n TTo extends string | undefined = string,\n> = ConstrainLiteral<\n TTo,\n RelativeToPathAutoComplete<\n TRouter,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n>\n\nexport type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<\n TFrom,\n RoutePaths<TRouter['routeTree']>\n>\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n explicitUndefined?: boolean\n}\n\nexport interface LinkOptionsProps {\n /**\n * The standard anchor tag target attribute\n */\n target?: HTMLAnchorElement['target']\n /**\n * Configurable options to determine if the link should be considered active or not\n * @default {exact:true,includeHash:true}\n */\n activeOptions?: ActiveOptions\n /**\n * The preloading strategy for this link\n * - `false` - No preloading\n * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n * - `'viewport'` - Preload the linked route when it enters the viewport\n */\n preload?: false | 'intent' | 'viewport' | 'render'\n /**\n * When a preload strategy is set, this delays the preload by this many milliseconds.\n * If the user exits the link before this delay, the preload will be cancelled.\n */\n preloadDelay?: number\n /**\n * Control whether the link should be disabled or not\n * If set to `true`, the link will be rendered without an `href` attribute\n * @default false\n */\n disabled?: boolean\n}\n\nexport type LinkOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps\n\nexport type LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nexport const preloadWarning = 'Error preloading route! ☝️'\n"],"names":[],"mappings":"AAkiBO,MAAM,iBAAiB;"}
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../src/link.ts"],"sourcesContent":["import type { HistoryState, ParsedHistoryState } from '@tanstack/history'\nimport type {\n AllParams,\n CatchAllPaths,\n CurrentPath,\n FullSearchSchema,\n FullSearchSchemaInput,\n ParentPath,\n RouteByPath,\n RouteByToPath,\n RoutePaths,\n RouteToPath,\n ToPath,\n} from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ViewTransitionOptions,\n} from './router'\nimport type {\n ConstrainLiteral,\n Expand,\n MakeDifferenceOptional,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n Updater,\n WithoutEmpty,\n} from './utils'\nimport type { ParsedLocation } from './location'\n\nexport type IsRequiredParams<TParams> =\n Record<never, never> extends TParams ? never : true\n\nexport type ParsePathParams<T extends string, TAcc = never> = T &\n `${string}$${string}` extends never\n ? TAcc\n : T extends `${string}$${infer TPossiblyParam}`\n ? TPossiblyParam extends ''\n ? TAcc\n : TPossiblyParam & `${string}/${string}` extends never\n ? TPossiblyParam | TAcc\n : TPossiblyParam extends `${infer TParam}/${infer TRest}`\n ? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>\n : never\n : TAcc\n\nexport type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`\n\nexport type RemoveTrailingSlashes<T> = T & `${string}/` extends never\n ? T\n : T extends `${infer R}/`\n ? R\n : T\n\nexport type AddLeadingSlash<T> = T & `/${string}` extends never\n ? `/${T & string}`\n : T\n\nexport type RemoveLeadingSlashes<T> = T & `/${string}` extends never\n ? T\n : T extends `/${infer R}`\n ? R\n : T\n\ntype JoinPath<TLeft extends string, TRight extends string> = TRight extends ''\n ? TLeft\n : TLeft extends ''\n ? TRight\n : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`\n\ntype RemoveLastSegment<\n T extends string,\n TAcc extends string = '',\n> = T extends `${infer TSegment}/${infer TRest}`\n ? TRest & `${string}/${string}` extends never\n ? TRest extends ''\n ? TAcc\n : `${TAcc}${TSegment}`\n : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>\n : TAcc\n\nexport type ResolveCurrentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '.'\n ? TFrom\n : TTo extends './'\n ? AddTrailingSlash<TFrom>\n : TTo & `./${string}` extends never\n ? never\n : TTo extends `./${infer TRest}`\n ? AddLeadingSlash<JoinPath<TFrom, TRest>>\n : never\n\nexport type ResolveParentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '../' | '..'\n ? TFrom extends '' | '/'\n ? never\n : AddLeadingSlash<RemoveLastSegment<TFrom>>\n : TTo & `../${string}` extends never\n ? AddLeadingSlash<JoinPath<TFrom, TTo>>\n : TFrom extends '' | '/'\n ? never\n : TTo extends `../${infer ToRest}`\n ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom\n ? TTo\n : string extends TTo\n ? TFrom\n : undefined extends TTo\n ? TFrom\n : TTo extends string\n ? TFrom extends string\n ? TTo extends `/${string}`\n ? TTo\n : TTo extends `..${string}`\n ? ResolveParentPath<TFrom, TTo>\n : TTo extends `.${string}`\n ? ResolveCurrentPath<TFrom, TTo>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n : never\n : never\n\nexport type FindDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n> = `${TPrefix}/${string}` & RouteToPath<TRouter>\n\nexport type InferDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n TPaths = FindDescendantToPaths<TRouter, TPrefix>,\n> = TPaths extends `${TPrefix}/`\n ? never\n : TPaths extends `${TPrefix}/${infer TRest}`\n ? TRest\n : never\n\nexport type RelativeToPath<\n TRouter extends AnyRouter,\n TTo extends string,\n TResolvedPath extends string,\n> =\n | (TResolvedPath & RouteToPath<TRouter> extends never\n ? never\n : ToPath<TRouter, TTo>)\n | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`\n\nexport type RelativeToParentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> =\n | RelativeToPath<TRouter, TTo, TResolvedPath>\n | (TTo extends `${string}..` | `${string}../`\n ? TResolvedPath extends '/' | ''\n ? never\n : FindDescendantToPaths<\n TRouter,\n RemoveTrailingSlashes<TResolvedPath>\n > extends never\n ? never\n : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`\n : never)\n\nexport type RelativeToCurrentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>\n\nexport type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =\n | (string extends TFrom\n ? CurrentPath<TRouter>\n : TFrom extends `/`\n ? never\n : CurrentPath<TRouter>)\n | (string extends TFrom\n ? ParentPath<TRouter>\n : TFrom extends `/`\n ? never\n : ParentPath<TRouter>)\n | RouteToPath<TRouter>\n | (TFrom extends '/'\n ? never\n : string extends TFrom\n ? never\n : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)\n\nexport type RelativeToPathAutoComplete<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n> = string extends TTo\n ? string\n : string extends TFrom\n ? AbsoluteToPath<TRouter, TFrom>\n : TTo & `..${string}` extends never\n ? TTo & `.${string}` extends never\n ? AbsoluteToPath<TRouter, TFrom>\n : RelativeToCurrentPath<TRouter, TFrom, TTo>\n : RelativeToParentPath<TRouter, TFrom, TTo>\n\nexport type NavigateOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps\n\n/**\n * The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)\n */\nexport interface NavigateOptionProps {\n /**\n * If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.\n * If set to `false`, the router will not scroll the element with an id matching the hash into view.\n * If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)\n */\n hashScrollIntoView?: boolean | ScrollIntoViewOptions\n /**\n * `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)\n */\n replace?: boolean\n /**\n * Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.\n * If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)\n */\n resetScroll?: boolean\n /** @deprecated All navigations now use startTransition under the hood */\n startTransition?: boolean\n /**\n * If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.\n * If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`\n * where `types` will be the strings array passed with `ViewTransitionOptions[\"types\"]`.\n * If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.\n *\n * If the browser does not support this api, this option will be ignored.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)\n * @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)\n */\n viewTransition?: boolean | ViewTransitionOptions\n /**\n * If `true`, navigation will ignore any blockers that might prevent it.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)\n */\n ignoreBlocker?: boolean\n /**\n * If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)\n */\n reloadDocument?: boolean\n /**\n * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)\n */\n href?: string\n}\n\nexport type ToOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>\n\nexport interface MaskOptions<\n in out TRouter extends AnyRouter,\n in out TMaskFrom extends string,\n in out TMaskTo extends string,\n> {\n _fromLocation?: ParsedLocation\n mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TMaskFrom extends string = string,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n SearchParamOptions<TRouter, TFrom, TTo> &\n PathParamOptions<TRouter, TFrom, TTo>\n\nexport interface RequiredToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport interface OptionalToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to?: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport type MakeToRequired<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string | undefined,\n> = string extends TFrom\n ? string extends TTo\n ? OptionalToOptions<TRouter, TFrom, TTo>\n : TTo & CatchAllPaths<TRouter> extends never\n ? RequiredToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n\nexport type ToSubOptionsProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n> = MakeToRequired<TRouter, TFrom, TTo> & {\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>\n from?: FromPathOption<TRouter, TFrom> & {}\n}\n\nexport type ParamsReducerFn<\n in out TRouter extends AnyRouter,\n in out TParamVariant extends ParamVariant,\n in out TFrom,\n in out TTo,\n> = (\n current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,\n) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n\ntype ParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})\n\ntype ParamVariant = 'PATH' | 'SEARCH'\n\nexport type ResolveRoute<\n TRouter extends AnyRouter,\n TFrom,\n TTo,\n TPath = ResolveRelativePath<TFrom, TTo>,\n> = TPath extends string\n ? TFrom extends TPath\n ? RouteByPath<TRouter['routeTree'], TPath>\n : RouteByToPath<TRouter, TPath>\n : never\n\ntype ResolveFromParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'\n\ntype ResolveFromAllParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchema<TRouter['routeTree']>\n\ntype ResolveFromParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n> = string extends TFrom\n ? ResolveFromAllParams<TRouter, TParamVariant>\n : RouteByPath<\n TRouter['routeTree'],\n TFrom\n >['types'][ResolveFromParamType<TParamVariant>]\n\ntype ResolveToParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'\n\ntype ResolveAllToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchemaInput<TRouter['routeTree']>\n\nexport type ResolveToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : string extends TPath\n ? ResolveAllToParams<TRouter, TParamVariant>\n : TPath extends CatchAllPaths<TRouter>\n ? ResolveAllToParams<TRouter, TParamVariant>\n : ResolveRoute<\n TRouter,\n TFrom,\n TTo\n >['types'][ResolveToParamType<TParamVariant>]\n : never\n\ntype ResolveRelativeToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,\n> = TParamVariant extends 'SEARCH'\n ? TToParams\n : string extends TFrom\n ? TToParams\n : MakeDifferenceOptional<\n ResolveFromParams<TRouter, TParamVariant, TFrom>,\n TToParams\n >\n\nexport interface MakeOptionalSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})\n}\n\nexport interface MakeOptionalPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})\n}\n\ntype MakeRequiredParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | (string extends TFrom\n ? never\n : ResolveFromParams<TRouter, TParamVariant, TFrom> extends WithoutEmpty<\n PickRequired<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n >\n ? true\n : never)\n | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})\n\nexport interface MakeRequiredPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}\n}\n\nexport interface MakeRequiredSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}\n}\n\nexport type IsRequired<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : TPath extends CatchAllPaths<TRouter>\n ? never\n : IsRequiredParams<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n : never\n\nexport type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never\n ? MakeOptionalSearchParams<TRouter, TFrom, TTo>\n : MakeRequiredSearchParams<TRouter, TFrom, TTo>\n\nexport type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'PATH', TFrom, TTo> extends never\n ? MakeOptionalPathParams<TRouter, TFrom, TTo>\n : MakeRequiredPathParams<TRouter, TFrom, TTo>\n\nexport type ToPathOption<\n TRouter extends AnyRouter = AnyRouter,\n TFrom extends string = string,\n TTo extends string | undefined = string,\n> = ConstrainLiteral<\n TTo,\n RelativeToPathAutoComplete<\n TRouter,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n>\n\nexport type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<\n TFrom,\n RoutePaths<TRouter['routeTree']>\n>\n\n/**\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)\n */\nexport interface ActiveOptions {\n /**\n * If true, the link will be active if the current route matches the `to` route path exactly (no children routes)\n * @default false\n */\n exact?: boolean\n /**\n * If true, the link will only be active if the current URL hash matches the `hash` prop\n * @default false\n */\n includeHash?: boolean\n /**\n * If true, the link will only be active if the current URL search params inclusively match the `search` prop\n * @default true\n */\n includeSearch?: boolean\n /**\n * This modifies the `includeSearch` behavior.\n * If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.\n * @default false\n */\n explicitUndefined?: boolean\n}\n\nexport interface LinkOptionsProps {\n /**\n * The standard anchor tag target attribute\n */\n target?: HTMLAnchorElement['target']\n /**\n * Configurable options to determine if the link should be considered active or not\n * @default {exact:true,includeHash:true}\n */\n activeOptions?: ActiveOptions\n /**\n * The preloading strategy for this link\n * - `false` - No preloading\n * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n * - `'viewport'` - Preload the linked route when it enters the viewport\n */\n preload?: false | 'intent' | 'viewport' | 'render'\n /**\n * When a preload strategy is set, this delays the preload by this many milliseconds.\n * If the user exits the link before this delay, the preload will be cancelled.\n */\n preloadDelay?: number\n /**\n * Control whether the link should be disabled or not\n * If set to `true`, the link will be rendered without an `href` attribute\n * @default false\n */\n disabled?: boolean\n}\n\nexport type LinkOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps\n\nexport type LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nexport const preloadWarning = 'Error preloading route! ☝️'\n"],"names":[],"mappings":"AAimBO,MAAM,iBAAiB;"}
|
package/dist/esm/redirect.d.ts
CHANGED
|
@@ -3,14 +3,29 @@ import { RoutePaths } from './routeInfo.js';
|
|
|
3
3
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
4
4
|
import { PickAsRequired } from './utils.js';
|
|
5
5
|
export type AnyRedirect = Redirect<any, any, any, any, any>;
|
|
6
|
+
/**
|
|
7
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)
|
|
8
|
+
*/
|
|
6
9
|
export type Redirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = '/', TTo extends string | undefined = '.', TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = '.'> = {
|
|
7
10
|
href?: string;
|
|
8
11
|
/**
|
|
9
12
|
* @deprecated Use `statusCode` instead
|
|
10
13
|
**/
|
|
11
14
|
code?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The HTTP status code to use when redirecting.
|
|
17
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)
|
|
18
|
+
*/
|
|
12
19
|
statusCode?: number;
|
|
20
|
+
/**
|
|
21
|
+
* If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.
|
|
22
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)
|
|
23
|
+
*/
|
|
13
24
|
throw?: any;
|
|
25
|
+
/**
|
|
26
|
+
* The HTTP headers to use when redirecting.
|
|
27
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)
|
|
28
|
+
*/
|
|
14
29
|
headers?: HeadersInit;
|
|
15
30
|
} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;
|
|
16
31
|
export type ResolvedRedirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = ''> = PickAsRequired<Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>, 'code' | 'statusCode' | 'headers'> & {
|
package/dist/esm/redirect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { PickAsRequired } from './utils'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = '/',\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n statusCode?: number\n throw?: any\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = PickAsRequired<\n Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n 'code' | 'statusCode' | 'headers'\n> & {\n href: string\n}\n\nexport function redirect<\n TRouter extends RegisteredRouter,\n const TTo extends string | undefined,\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n ;(opts as any).isRedirect = true\n opts.statusCode = opts.statusCode || opts.code || 307\n opts.headers = opts.headers || {}\n if (!opts.reloadDocument) {\n opts.reloadDocument = false\n try {\n new URL(`${opts.href}`)\n opts.reloadDocument = true\n } catch {}\n }\n\n if (opts.throw) {\n throw opts\n }\n\n return opts\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return !!obj?.isRedirect\n}\n\nexport function isResolvedRedirect(obj: any): obj is ResolvedRedirect {\n return !!obj?.isRedirect && obj.href\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redirect.js","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { PickAsRequired } from './utils'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = '/',\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = PickAsRequired<\n Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n 'code' | 'statusCode' | 'headers'\n> & {\n href: string\n}\n\nexport function redirect<\n TRouter extends RegisteredRouter,\n const TTo extends string | undefined,\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n ;(opts as any).isRedirect = true\n opts.statusCode = opts.statusCode || opts.code || 307\n opts.headers = opts.headers || {}\n if (!opts.reloadDocument) {\n opts.reloadDocument = false\n try {\n new URL(`${opts.href}`)\n opts.reloadDocument = true\n } catch {}\n }\n\n if (opts.throw) {\n throw opts\n }\n\n return opts\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return !!obj?.isRedirect\n}\n\nexport function isResolvedRedirect(obj: any): obj is ResolvedRedirect {\n return !!obj?.isRedirect && obj.href\n}\n"],"names":[],"mappings":"AAoDO,SAAS,SAOd,MACmD;AACjD,OAAa,aAAa;AAC5B,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAC7C,OAAA,UAAU,KAAK,WAAW,CAAC;AAC5B,MAAA,CAAC,KAAK,gBAAgB;AACxB,SAAK,iBAAiB;AAClB,QAAA;AACF,UAAI,IAAI,GAAG,KAAK,IAAI,EAAE;AACtB,WAAK,iBAAiB;AAAA,IAAA,QAChB;AAAA,IAAA;AAAA,EAAC;AAGX,MAAI,KAAK,OAAO;AACR,UAAA;AAAA,EAAA;AAGD,SAAA;AACT;AAEO,SAAS,WAAW,KAA8B;AAChD,SAAA,CAAC,EAAC,2BAAK;AAChB;AAEO,SAAS,mBAAmB,KAAmC;AACpE,SAAO,CAAC,EAAC,2BAAK,eAAc,IAAI;AAClC;"}
|
package/dist/esm/route.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LazyRoute } from './fileRoute.js';
|
|
2
|
+
import { NotFoundError } from './not-found.js';
|
|
2
3
|
import { NavigateOptions, ParsePathParams } from './link.js';
|
|
3
4
|
import { ParsedLocation } from './location.js';
|
|
4
5
|
import { AnyRouteMatch, MakeRouteMatchFromRoute, MakeRouteMatchUnion, RouteMatch } from './Matches.js';
|
|
@@ -366,4 +367,57 @@ export type ErrorComponentProps = {
|
|
|
366
367
|
export type NotFoundRouteProps = {
|
|
367
368
|
data: unknown;
|
|
368
369
|
};
|
|
370
|
+
export declare class BaseRoute<in out TParentRoute extends AnyRoute = AnyRoute, in out TPath extends string = '/', in out TFullPath extends string = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends string = string, in out TId extends string = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> implements Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
371
|
+
isRoot: TParentRoute extends AnyRoute ? true : false;
|
|
372
|
+
options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>;
|
|
373
|
+
parentRoute: TParentRoute;
|
|
374
|
+
private _id;
|
|
375
|
+
private _path;
|
|
376
|
+
private _fullPath;
|
|
377
|
+
private _to;
|
|
378
|
+
private _ssr;
|
|
379
|
+
get to(): TrimPathRight<TFullPath>;
|
|
380
|
+
get id(): TId;
|
|
381
|
+
get path(): TPath;
|
|
382
|
+
get fullPath(): TFullPath;
|
|
383
|
+
get ssr(): boolean;
|
|
384
|
+
children?: TChildren;
|
|
385
|
+
originalIndex?: number;
|
|
386
|
+
rank: number;
|
|
387
|
+
lazyFn?: () => Promise<LazyRoute>;
|
|
388
|
+
_lazyPromise?: Promise<void>;
|
|
389
|
+
_componentsPromise?: Promise<Array<void>>;
|
|
390
|
+
constructor(options?: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>);
|
|
391
|
+
types: RouteTypes<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes>;
|
|
392
|
+
init: (opts: {
|
|
393
|
+
originalIndex: number;
|
|
394
|
+
defaultSsr?: boolean;
|
|
395
|
+
}) => void;
|
|
396
|
+
addChildren: RouteAddChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
397
|
+
_addFileChildren: RouteAddFileChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
398
|
+
_addFileTypes: RouteAddFileTypesFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
399
|
+
updateLoader: <TNewLoaderFn>(options: {
|
|
400
|
+
loader: Constrain<TNewLoaderFn, RouteLoaderFn<TParentRoute, TCustomId, TParams, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>>;
|
|
401
|
+
}) => BaseRoute<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TNewLoaderFn, TChildren, TFileRouteTypes>;
|
|
402
|
+
update: (options: UpdatableRouteOptions<TParentRoute, TCustomId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>) => this;
|
|
403
|
+
lazy: RouteLazyFn<this>;
|
|
404
|
+
}
|
|
405
|
+
export declare class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
406
|
+
id: TId;
|
|
407
|
+
constructor({ id }: {
|
|
408
|
+
id: TId;
|
|
409
|
+
});
|
|
410
|
+
notFound: (opts?: NotFoundError) => NotFoundError;
|
|
411
|
+
}
|
|
412
|
+
export declare class BaseRootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRoute<any, // TParentRoute
|
|
413
|
+
'/', // TPath
|
|
414
|
+
'/', // TFullPath
|
|
415
|
+
string, // TCustomId
|
|
416
|
+
RootRouteId, // TId
|
|
417
|
+
TSearchValidator, // TSearchValidator
|
|
418
|
+
{}, // TParams
|
|
419
|
+
TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, // TChildren
|
|
420
|
+
TFileRouteTypes> {
|
|
421
|
+
constructor(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>);
|
|
422
|
+
}
|
|
369
423
|
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { trimPathLeft, joinPaths } from "./path.js";
|
|
2
|
+
import { notFound } from "./not-found.js";
|
|
3
|
+
import { rootRouteId } from "./root.js";
|
|
4
|
+
class BaseRoute {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.init = (opts) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
this.originalIndex = opts.originalIndex;
|
|
9
|
+
const options2 = this.options;
|
|
10
|
+
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
|
|
11
|
+
this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a);
|
|
12
|
+
if (isRoot) {
|
|
13
|
+
this._path = rootRouteId;
|
|
14
|
+
} else if (!this.parentRoute) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
let path = isRoot ? rootRouteId : options2 == null ? void 0 : options2.path;
|
|
20
|
+
if (path && path !== "/") {
|
|
21
|
+
path = trimPathLeft(path);
|
|
22
|
+
}
|
|
23
|
+
const customId = (options2 == null ? void 0 : options2.id) || path;
|
|
24
|
+
let id = isRoot ? rootRouteId : joinPaths([
|
|
25
|
+
this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id,
|
|
26
|
+
customId
|
|
27
|
+
]);
|
|
28
|
+
if (path === rootRouteId) {
|
|
29
|
+
path = "/";
|
|
30
|
+
}
|
|
31
|
+
if (id !== rootRouteId) {
|
|
32
|
+
id = joinPaths(["/", id]);
|
|
33
|
+
}
|
|
34
|
+
const fullPath = id === rootRouteId ? "/" : joinPaths([this.parentRoute.fullPath, path]);
|
|
35
|
+
this._path = path;
|
|
36
|
+
this._id = id;
|
|
37
|
+
this._fullPath = fullPath;
|
|
38
|
+
this._to = fullPath;
|
|
39
|
+
this._ssr = (options2 == null ? void 0 : options2.ssr) ?? opts.defaultSsr ?? true;
|
|
40
|
+
};
|
|
41
|
+
this.addChildren = (children) => {
|
|
42
|
+
return this._addFileChildren(children);
|
|
43
|
+
};
|
|
44
|
+
this._addFileChildren = (children) => {
|
|
45
|
+
if (Array.isArray(children)) {
|
|
46
|
+
this.children = children;
|
|
47
|
+
}
|
|
48
|
+
if (typeof children === "object" && children !== null) {
|
|
49
|
+
this.children = Object.values(children);
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
};
|
|
53
|
+
this._addFileTypes = () => {
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
this.updateLoader = (options2) => {
|
|
57
|
+
Object.assign(this.options, options2);
|
|
58
|
+
return this;
|
|
59
|
+
};
|
|
60
|
+
this.update = (options2) => {
|
|
61
|
+
Object.assign(this.options, options2);
|
|
62
|
+
return this;
|
|
63
|
+
};
|
|
64
|
+
this.lazy = (lazyFn) => {
|
|
65
|
+
this.lazyFn = lazyFn;
|
|
66
|
+
return this;
|
|
67
|
+
};
|
|
68
|
+
this.options = options || {};
|
|
69
|
+
this.isRoot = !(options == null ? void 0 : options.getParentRoute);
|
|
70
|
+
if ((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)) {
|
|
71
|
+
throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
get to() {
|
|
75
|
+
return this._to;
|
|
76
|
+
}
|
|
77
|
+
get id() {
|
|
78
|
+
return this._id;
|
|
79
|
+
}
|
|
80
|
+
get path() {
|
|
81
|
+
return this._path;
|
|
82
|
+
}
|
|
83
|
+
get fullPath() {
|
|
84
|
+
return this._fullPath;
|
|
85
|
+
}
|
|
86
|
+
get ssr() {
|
|
87
|
+
return this._ssr;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class BaseRouteApi {
|
|
91
|
+
constructor({ id }) {
|
|
92
|
+
this.notFound = (opts) => {
|
|
93
|
+
return notFound({ routeId: this.id, ...opts });
|
|
94
|
+
};
|
|
95
|
+
this.id = id;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class BaseRootRoute extends BaseRoute {
|
|
99
|
+
constructor(options) {
|
|
100
|
+
super(options);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
BaseRootRoute,
|
|
105
|
+
BaseRoute,
|
|
106
|
+
BaseRouteApi
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=route.js.map
|