@tanstack/router-core 0.0.1-beta.16 → 0.0.1-beta.19
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/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +24 -35
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +38 -1
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/esm/index.js +62 -36
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +130 -130
- package/build/types/index.d.ts +87 -81
- package/build/umd/index.development.js +62 -36
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/routeConfig.ts +1 -4
- package/src/routeInfo.ts +2 -2
- package/src/routeMatch.ts +24 -31
- package/src/router.ts +57 -7
package/build/types/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { default as invariant } from 'tiny-invariant';
|
|
|
14
14
|
|
|
15
15
|
interface FrameworkGenerics {
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
|
|
18
18
|
|
|
19
19
|
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
20
20
|
matchId: string;
|
|
@@ -73,34 +73,34 @@ declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = Defaul
|
|
|
73
73
|
pathname: string;
|
|
74
74
|
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
77
|
+
type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
|
|
78
|
+
type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
|
|
79
|
+
type IsKnown<T, Y, N> = unknown extends T ? N : Y;
|
|
80
|
+
type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
81
|
+
type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
82
|
+
type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
|
|
83
|
+
type PickExtra<T, K> = Expand<{
|
|
84
84
|
[TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
|
|
85
85
|
}>;
|
|
86
|
-
|
|
86
|
+
type PickRequired<T> = {
|
|
87
87
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
88
88
|
};
|
|
89
|
-
|
|
89
|
+
type Expand<T> = T extends object ? T extends infer O ? {
|
|
90
90
|
[K in keyof O]: O[K];
|
|
91
91
|
} : never : T;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
type Values<O> = O[ValueKeys<O>];
|
|
93
|
+
type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
94
|
+
type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
95
95
|
[K in A]: DeepAwaited<B>;
|
|
96
96
|
} : T;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
type PathParamMask<TRoutePath extends string> = TRoutePath extends `${infer L}/:${infer C}/${infer R}` ? PathParamMask<`${L}/${string}/${R}`> : TRoutePath extends `${infer L}/:${infer C}` ? PathParamMask<`${L}/${string}`> : TRoutePath;
|
|
98
|
+
type Timeout = ReturnType<typeof setTimeout>;
|
|
99
|
+
type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
100
|
+
type PickExtract<T, U> = {
|
|
101
101
|
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
102
102
|
};
|
|
103
|
-
|
|
103
|
+
type PickExclude<T, U> = {
|
|
104
104
|
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
@@ -131,9 +131,9 @@ interface FromLocation {
|
|
|
131
131
|
key?: string;
|
|
132
132
|
hash?: string;
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
135
|
+
type SearchParser = (searchStr: string) => Record<string, any>;
|
|
136
|
+
type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
|
|
137
137
|
interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
138
138
|
history?: BrowserHistory | MemoryHistory | HashHistory;
|
|
139
139
|
stringifySearch?: SearchSerializer;
|
|
@@ -143,7 +143,6 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
143
143
|
defaultPreloadMaxAge?: number;
|
|
144
144
|
defaultPreloadGcMaxAge?: number;
|
|
145
145
|
defaultPreloadDelay?: number;
|
|
146
|
-
useErrorBoundary?: boolean;
|
|
147
146
|
defaultComponent?: GetFrameworkGeneric<'Component'>;
|
|
148
147
|
defaultErrorComponent?: GetFrameworkGeneric<'Component'>;
|
|
149
148
|
defaultPendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
@@ -152,6 +151,7 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
152
151
|
caseSensitive?: boolean;
|
|
153
152
|
routeConfig?: TRouteConfig;
|
|
154
153
|
basepath?: string;
|
|
154
|
+
useServerData?: boolean;
|
|
155
155
|
createRouter?: (router: Router<any, any>) => void;
|
|
156
156
|
createRoute?: (opts: {
|
|
157
157
|
route: AnyRoute;
|
|
@@ -195,9 +195,9 @@ interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams exte
|
|
|
195
195
|
latest?: LoaderState<TFullSearchSchema, TAllParams>;
|
|
196
196
|
pending: LoaderState<TFullSearchSchema, TAllParams>[];
|
|
197
197
|
}
|
|
198
|
-
interface LoaderState<TFullSearchSchema =
|
|
198
|
+
interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
199
199
|
loadedAt: number;
|
|
200
|
-
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>;
|
|
200
|
+
loaderContext: LoaderContext<AnyLoaderData, TFullSearchSchema, TAllParams>;
|
|
201
201
|
}
|
|
202
202
|
interface RouterState {
|
|
203
203
|
status: 'idle' | 'loading';
|
|
@@ -214,8 +214,8 @@ interface PendingState {
|
|
|
214
214
|
location: Location;
|
|
215
215
|
matches: RouteMatch[];
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
type Listener = (router: Router<any, any>) => void;
|
|
218
|
+
type ListenerFn = () => void;
|
|
219
219
|
interface BuildNextOptions {
|
|
220
220
|
to?: string | number | null;
|
|
221
221
|
params?: true | Updater<Record<string, any>>;
|
|
@@ -228,7 +228,7 @@ interface BuildNextOptions {
|
|
|
228
228
|
__preSearchFilters?: SearchFilter<any>[];
|
|
229
229
|
__postSearchFilters?: SearchFilter<any>[];
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
type MatchCacheEntry = {
|
|
232
232
|
gc: number;
|
|
233
233
|
match: RouteMatch;
|
|
234
234
|
};
|
|
@@ -249,10 +249,13 @@ interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location'
|
|
|
249
249
|
interface DehydratedRouteMatch extends Pick<RouteMatch<any, any>, 'matchId' | 'status' | 'routeLoaderData' | 'loaderData' | 'isInvalid' | 'invalidAt'> {
|
|
250
250
|
}
|
|
251
251
|
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
252
|
+
types: {
|
|
253
|
+
RouteConfig: TRouteConfig;
|
|
254
|
+
AllRouteInfo: TAllRouteInfo;
|
|
255
|
+
};
|
|
252
256
|
history: BrowserHistory | MemoryHistory | HashHistory;
|
|
253
257
|
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
254
258
|
basepath: string;
|
|
255
|
-
allRouteInfo: TAllRouteInfo;
|
|
256
259
|
listeners: Listener[];
|
|
257
260
|
location: Location;
|
|
258
261
|
navigateTimeout?: Timeout;
|
|
@@ -292,6 +295,7 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
292
295
|
maxAge?: never;
|
|
293
296
|
gcMaxAge?: never;
|
|
294
297
|
}) => Promise<void>;
|
|
298
|
+
loadMatchData: (routeMatch: RouteMatch<any, any>) => Promise<Record<string, unknown>>;
|
|
295
299
|
invalidateRoute: (opts: MatchLocation) => void;
|
|
296
300
|
reload: () => Promise<void>;
|
|
297
301
|
resolvePath: (from: string, path: string) => string;
|
|
@@ -349,17 +353,21 @@ interface DefaultAllRouteInfo {
|
|
|
349
353
|
}
|
|
350
354
|
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
351
355
|
}
|
|
352
|
-
|
|
353
|
-
|
|
356
|
+
type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
|
|
357
|
+
type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
|
|
354
358
|
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
355
359
|
}> : never : never;
|
|
356
|
-
|
|
360
|
+
type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
357
361
|
id: TId;
|
|
358
362
|
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
359
|
-
|
|
363
|
+
type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TRouteId, infer TPath, infer TFullPath, infer TParentLoaderData, infer TRouteLoaderData, infer TLoaderData, infer TActionPayload, infer TActionResponse, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TRouteId ? never : RouteInfo<TId, TRouteId, TPath, TFullPath, TParentLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
|
|
360
364
|
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
|
|
365
|
+
'/': TRouteInfo;
|
|
366
|
+
} & {
|
|
361
367
|
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
362
368
|
}, TRouteInfoByFullPath = {
|
|
369
|
+
'/': TRouteInfo;
|
|
370
|
+
} & {
|
|
363
371
|
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
|
|
364
372
|
}> {
|
|
365
373
|
routeConfig: TRouteConfig;
|
|
@@ -388,41 +396,40 @@ interface RouteInfo<TId extends string = string, TRouteId extends string = strin
|
|
|
388
396
|
allParams: TAllParams;
|
|
389
397
|
options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
390
398
|
}
|
|
391
|
-
|
|
399
|
+
type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
392
400
|
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
393
401
|
};
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
|
|
403
|
+
type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
|
|
396
404
|
|
|
397
405
|
declare const rootRouteId: "__root__";
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
406
|
+
type RootRouteId = typeof rootRouteId;
|
|
407
|
+
type AnyLoaderData = {};
|
|
408
|
+
type AnyPathParams = {};
|
|
409
|
+
type AnySearchSchema = {};
|
|
402
410
|
interface RouteMeta {
|
|
403
411
|
}
|
|
404
|
-
|
|
405
|
-
|
|
412
|
+
type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
413
|
+
type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
|
|
406
414
|
parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
407
415
|
};
|
|
408
|
-
|
|
416
|
+
type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
|
|
409
417
|
error: 'Top level search params cannot be redefined by child routes!';
|
|
410
418
|
keys: keyof TReturn & keyof TParentSchema;
|
|
411
419
|
} : TReturn;
|
|
412
|
-
|
|
413
|
-
|
|
420
|
+
type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
421
|
+
type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
414
422
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
415
423
|
};
|
|
416
|
-
|
|
424
|
+
type LoaderFn<TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TParentRouteLoaderData, TFullSearchSchema, TAllParams>) => Promise<TRouteLoaderData>;
|
|
417
425
|
interface LoaderContext<TParentRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
418
426
|
params: TAllParams;
|
|
419
427
|
search: TFullSearchSchema;
|
|
420
428
|
signal?: AbortSignal;
|
|
421
|
-
parentLoaderPromise?: Promise<TParentRouteLoaderData>;
|
|
422
429
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
430
|
+
type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
|
|
431
|
+
type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
|
|
432
|
+
type RouteOptions<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> = ({
|
|
426
433
|
path: TPath;
|
|
427
434
|
} | {
|
|
428
435
|
id: TRouteId;
|
|
@@ -438,7 +445,6 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
438
445
|
loaderMaxAge?: number;
|
|
439
446
|
loaderGcMaxAge?: number;
|
|
440
447
|
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
441
|
-
useErrorBoundary?: boolean;
|
|
442
448
|
onMatch?: (matchContext: {
|
|
443
449
|
params: TAllParams;
|
|
444
450
|
search: TFullSearchSchema;
|
|
@@ -458,7 +464,7 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
458
464
|
parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
|
|
459
465
|
stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
460
466
|
}) & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
|
|
461
|
-
|
|
467
|
+
type SearchFilter<T, U = T> = (prev: T) => U;
|
|
462
468
|
interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = AnyLoaderData, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
|
|
463
469
|
id: TId;
|
|
464
470
|
routeId: TRouteId;
|
|
@@ -476,21 +482,21 @@ interface RouteConfig<TId extends string = string, TRouteId extends string = str
|
|
|
476
482
|
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
477
483
|
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
478
484
|
}
|
|
479
|
-
|
|
485
|
+
type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TRouteId extends string, TPath extends string, TRouteLoaderData extends AnyLoaderData, TActionPayload, TActionResponse, TSearchSchema extends AnySearchSchema = AnySearchSchema, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams> = AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams>, TKnownChildren extends RouteConfig[] = RouteConfig[], TResolvedId extends string = string extends TRouteId ? string extends TPath ? string : TPath : TRouteId>(options?: TIsRoot extends true ? Omit<RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
|
|
480
486
|
path?: never;
|
|
481
487
|
} : RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, children?: TKnownChildren, isRoot?: boolean, parentId?: string, parentPath?: string) => RouteConfig<RoutePrefix<TParentId, TResolvedId>, TResolvedId, TPath, string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
|
|
482
|
-
|
|
483
|
-
|
|
488
|
+
type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
|
|
489
|
+
type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
|
|
484
490
|
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
485
491
|
}
|
|
486
492
|
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
487
493
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
494
|
+
type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
495
|
+
type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
496
|
+
type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
491
497
|
declare const createRouteConfig: CreateRouteConfigFn<true>;
|
|
492
498
|
|
|
493
|
-
|
|
499
|
+
type LinkInfo = {
|
|
494
500
|
type: 'external';
|
|
495
501
|
href: string;
|
|
496
502
|
} | {
|
|
@@ -503,12 +509,12 @@ declare type LinkInfo = {
|
|
|
503
509
|
isActive: boolean;
|
|
504
510
|
disabled?: boolean;
|
|
505
511
|
};
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
+
type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
|
|
513
|
+
type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
|
|
514
|
+
type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
|
|
515
|
+
type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
|
|
516
|
+
type Join<T> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}/${Join<Tail>}`> : never;
|
|
517
|
+
type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
512
518
|
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
513
519
|
...infer TToRest
|
|
514
520
|
] ? `${CleanPath<Join<[
|
|
@@ -519,40 +525,40 @@ declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends s
|
|
|
519
525
|
...Split<RestTTo, false>,
|
|
520
526
|
...infer RestPath
|
|
521
527
|
] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
|
|
522
|
-
|
|
528
|
+
type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
523
529
|
replace?: boolean;
|
|
524
530
|
};
|
|
525
|
-
|
|
531
|
+
type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
526
532
|
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
|
|
527
533
|
hash?: Updater<string>;
|
|
528
534
|
state?: LocationState;
|
|
529
535
|
from?: TFrom;
|
|
530
536
|
} & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>, {}> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
|
|
531
|
-
|
|
537
|
+
type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
|
|
532
538
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
533
539
|
} : keyof PickRequired<TToSchema> extends never ? {
|
|
534
540
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
535
541
|
} : {
|
|
536
542
|
search: SearchReducer<TFromSchema, TToSchema>;
|
|
537
543
|
};
|
|
538
|
-
|
|
544
|
+
type SearchReducer<TFrom, TTo> = {
|
|
539
545
|
[TKey in keyof TTo]: TTo[TKey];
|
|
540
546
|
} | ((current: TFrom) => TTo);
|
|
541
|
-
|
|
547
|
+
type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
|
|
542
548
|
params?: ParamsReducer<TFromParams, TToParams>;
|
|
543
549
|
} : AnyPathParams extends TToParams ? {
|
|
544
550
|
params?: ParamsReducer<TFromParams, Record<string, never>>;
|
|
545
551
|
} : {
|
|
546
552
|
params: ParamsReducer<TFromParams, TToParams>;
|
|
547
553
|
};
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
554
|
+
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
555
|
+
type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routePaths'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
556
|
+
type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeIds'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
551
557
|
interface ActiveOptions {
|
|
552
558
|
exact?: boolean;
|
|
553
559
|
includeHash?: boolean;
|
|
554
560
|
}
|
|
555
|
-
|
|
561
|
+
type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
|
|
556
562
|
target?: HTMLAnchorElement['target'];
|
|
557
563
|
activeOptions?: ActiveOptions;
|
|
558
564
|
preload?: false | 'intent';
|
|
@@ -561,22 +567,22 @@ declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
|
|
|
561
567
|
preloadDelay?: number;
|
|
562
568
|
disabled?: boolean;
|
|
563
569
|
};
|
|
564
|
-
|
|
570
|
+
type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
|
|
565
571
|
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
566
572
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
567
573
|
} : {} : {};
|
|
568
|
-
|
|
569
|
-
|
|
574
|
+
type CheckPath<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routePaths']> extends never ? TPass : CheckPathError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routePaths']>>;
|
|
575
|
+
type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
570
576
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route path.`;
|
|
571
577
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
572
578
|
}>;
|
|
573
|
-
|
|
574
|
-
|
|
579
|
+
type CheckId<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routeIds']> extends never ? TPass : CheckIdError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routeIds']>>;
|
|
580
|
+
type CheckIdError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
575
581
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
|
|
576
582
|
'Valid Route IDs': TAllRouteInfo['routeIds'];
|
|
577
583
|
}>;
|
|
578
|
-
|
|
579
|
-
|
|
584
|
+
type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
|
|
585
|
+
type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
|
|
580
586
|
|
|
581
587
|
interface Segment {
|
|
582
588
|
type: 'pathname' | 'param' | 'wildcard';
|
|
@@ -1488,11 +1488,19 @@
|
|
|
1488
1488
|
}
|
|
1489
1489
|
},
|
|
1490
1490
|
fetch: async opts => {
|
|
1491
|
-
const
|
|
1492
|
-
routeMatch.__.latestId =
|
|
1491
|
+
const loadId = '' + Date.now() + Math.random();
|
|
1492
|
+
routeMatch.__.latestId = loadId;
|
|
1493
|
+
|
|
1494
|
+
const checkLatest = async () => {
|
|
1495
|
+
if (loadId !== routeMatch.__.latestId) {
|
|
1496
|
+
// warning(true, 'Data loader is out of date!')
|
|
1497
|
+
return new Promise(() => {});
|
|
1498
|
+
}
|
|
1499
|
+
}; // If the match was in an error state, set it
|
|
1493
1500
|
// to a loading state again. Otherwise, keep it
|
|
1494
1501
|
// as loading or resolved
|
|
1495
1502
|
|
|
1503
|
+
|
|
1496
1504
|
if (routeMatch.status === 'idle') {
|
|
1497
1505
|
routeMatch.status = 'loading';
|
|
1498
1506
|
} // We started loading the route, so it's no longer invalid
|
|
@@ -1524,19 +1532,8 @@
|
|
|
1524
1532
|
var _ref, _ref2, _opts$maxAge;
|
|
1525
1533
|
|
|
1526
1534
|
if (routeMatch.options.loader) {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
const data = await routeMatch.options.loader({
|
|
1530
|
-
parentLoaderPromise: (_routeMatch$parentMat3 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat3.__.dataPromise,
|
|
1531
|
-
params: routeMatch.params,
|
|
1532
|
-
search: routeMatch.routeSearch,
|
|
1533
|
-
signal: routeMatch.__.abortController.signal
|
|
1534
|
-
});
|
|
1535
|
-
|
|
1536
|
-
if (id !== routeMatch.__.latestId) {
|
|
1537
|
-
return routeMatch.__.loadPromise;
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1535
|
+
const data = await router.loadMatchData(routeMatch);
|
|
1536
|
+
await checkLatest();
|
|
1540
1537
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1541
1538
|
}
|
|
1542
1539
|
|
|
@@ -1546,9 +1543,7 @@
|
|
|
1546
1543
|
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1547
1544
|
return routeMatch.routeLoaderData;
|
|
1548
1545
|
} catch (err) {
|
|
1549
|
-
|
|
1550
|
-
return routeMatch.__.loadPromise;
|
|
1551
|
-
}
|
|
1546
|
+
await checkLatest();
|
|
1552
1547
|
|
|
1553
1548
|
{
|
|
1554
1549
|
console.error(err);
|
|
@@ -1561,29 +1556,23 @@
|
|
|
1561
1556
|
}
|
|
1562
1557
|
});
|
|
1563
1558
|
|
|
1564
|
-
|
|
1565
|
-
await
|
|
1566
|
-
|
|
1567
|
-
if (id !== routeMatch.__.latestId) {
|
|
1568
|
-
return routeMatch.__.loadPromise;
|
|
1569
|
-
}
|
|
1570
|
-
} finally {
|
|
1571
|
-
if (id !== routeMatch.__.latestId) {
|
|
1572
|
-
return routeMatch.__.loadPromise;
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1559
|
+
const after = async () => {
|
|
1560
|
+
await checkLatest();
|
|
1575
1561
|
routeMatch.isFetching = false;
|
|
1562
|
+
delete routeMatch.__.loadPromise;
|
|
1576
1563
|
|
|
1577
1564
|
routeMatch.__.notify();
|
|
1565
|
+
};
|
|
1566
|
+
|
|
1567
|
+
try {
|
|
1568
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1569
|
+
after();
|
|
1570
|
+
} catch (_unused) {
|
|
1571
|
+
after();
|
|
1578
1572
|
}
|
|
1579
1573
|
});
|
|
1580
1574
|
await routeMatch.__.loadPromise;
|
|
1581
|
-
|
|
1582
|
-
if (id !== routeMatch.__.latestId) {
|
|
1583
|
-
return routeMatch.__.loadPromise;
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
delete routeMatch.__.loadPromise;
|
|
1575
|
+
await checkLatest();
|
|
1587
1576
|
}
|
|
1588
1577
|
});
|
|
1589
1578
|
|
|
@@ -1677,6 +1666,8 @@
|
|
|
1677
1666
|
});
|
|
1678
1667
|
|
|
1679
1668
|
let router = {
|
|
1669
|
+
types: undefined,
|
|
1670
|
+
// public api
|
|
1680
1671
|
history,
|
|
1681
1672
|
options: originalOptions,
|
|
1682
1673
|
listeners: [],
|
|
@@ -1685,7 +1676,6 @@
|
|
|
1685
1676
|
routeTree: undefined,
|
|
1686
1677
|
routesById: {},
|
|
1687
1678
|
location: undefined,
|
|
1688
|
-
allRouteInfo: undefined,
|
|
1689
1679
|
//
|
|
1690
1680
|
navigationPromise: Promise.resolve(),
|
|
1691
1681
|
resolveNavigation: () => {},
|
|
@@ -2068,6 +2058,11 @@
|
|
|
2068
2058
|
match.__.validate();
|
|
2069
2059
|
|
|
2070
2060
|
match.load(loaderOpts);
|
|
2061
|
+
const search = match.search;
|
|
2062
|
+
|
|
2063
|
+
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2071
2066
|
|
|
2072
2067
|
if (match.__.loadPromise) {
|
|
2073
2068
|
// Wait for the first sign of activity from the match
|
|
@@ -2077,6 +2072,37 @@
|
|
|
2077
2072
|
router.notify();
|
|
2078
2073
|
await Promise.all(matchPromises);
|
|
2079
2074
|
},
|
|
2075
|
+
loadMatchData: async routeMatch => {
|
|
2076
|
+
if (isServer || !router.options.useServerData) {
|
|
2077
|
+
var _await$routeMatch$opt;
|
|
2078
|
+
|
|
2079
|
+
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
2080
|
+
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
2081
|
+
params: routeMatch.params,
|
|
2082
|
+
search: routeMatch.routeSearch,
|
|
2083
|
+
signal: routeMatch.__.abortController.signal
|
|
2084
|
+
}))) != null ? _await$routeMatch$opt : {};
|
|
2085
|
+
} else {
|
|
2086
|
+
const next = router.buildNext({
|
|
2087
|
+
to: '.',
|
|
2088
|
+
search: d => _extends({}, d != null ? d : {}, {
|
|
2089
|
+
__data: {
|
|
2090
|
+
matchId: routeMatch.matchId
|
|
2091
|
+
}
|
|
2092
|
+
})
|
|
2093
|
+
});
|
|
2094
|
+
const res = await fetch(next.href, {
|
|
2095
|
+
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
2096
|
+
|
|
2097
|
+
});
|
|
2098
|
+
|
|
2099
|
+
if (res.ok) {
|
|
2100
|
+
return res.json();
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
throw new Error('Failed to fetch match data');
|
|
2104
|
+
}
|
|
2105
|
+
},
|
|
2080
2106
|
invalidateRoute: opts => {
|
|
2081
2107
|
var _router$state$pending5, _router$state$pending6;
|
|
2082
2108
|
|