@tanstack/router-core 0.0.1-beta.15 → 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 +40 -3
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/esm/index.js +64 -38
- 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 +89 -81
- package/build/umd/index.development.js +64 -38
- 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/link.ts +3 -1
- package/src/routeConfig.ts +1 -4
- package/src/routeInfo.ts +2 -2
- package/src/routeMatch.ts +24 -31
- package/src/router.ts +59 -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,20 +214,21 @@ 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>>;
|
|
222
222
|
search?: true | Updater<unknown>;
|
|
223
223
|
hash?: true | Updater<string>;
|
|
224
|
+
state?: LocationState;
|
|
224
225
|
key?: string;
|
|
225
226
|
from?: string;
|
|
226
227
|
fromCurrent?: boolean;
|
|
227
228
|
__preSearchFilters?: SearchFilter<any>[];
|
|
228
229
|
__postSearchFilters?: SearchFilter<any>[];
|
|
229
230
|
}
|
|
230
|
-
|
|
231
|
+
type MatchCacheEntry = {
|
|
231
232
|
gc: number;
|
|
232
233
|
match: RouteMatch;
|
|
233
234
|
};
|
|
@@ -248,10 +249,13 @@ interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location'
|
|
|
248
249
|
interface DehydratedRouteMatch extends Pick<RouteMatch<any, any>, 'matchId' | 'status' | 'routeLoaderData' | 'loaderData' | 'isInvalid' | 'invalidAt'> {
|
|
249
250
|
}
|
|
250
251
|
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
252
|
+
types: {
|
|
253
|
+
RouteConfig: TRouteConfig;
|
|
254
|
+
AllRouteInfo: TAllRouteInfo;
|
|
255
|
+
};
|
|
251
256
|
history: BrowserHistory | MemoryHistory | HashHistory;
|
|
252
257
|
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
253
258
|
basepath: string;
|
|
254
|
-
allRouteInfo: TAllRouteInfo;
|
|
255
259
|
listeners: Listener[];
|
|
256
260
|
location: Location;
|
|
257
261
|
navigateTimeout?: Timeout;
|
|
@@ -291,6 +295,7 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
291
295
|
maxAge?: never;
|
|
292
296
|
gcMaxAge?: never;
|
|
293
297
|
}) => Promise<void>;
|
|
298
|
+
loadMatchData: (routeMatch: RouteMatch<any, any>) => Promise<Record<string, unknown>>;
|
|
294
299
|
invalidateRoute: (opts: MatchLocation) => void;
|
|
295
300
|
reload: () => Promise<void>;
|
|
296
301
|
resolvePath: (from: string, path: string) => string;
|
|
@@ -348,17 +353,21 @@ interface DefaultAllRouteInfo {
|
|
|
348
353
|
}
|
|
349
354
|
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
350
355
|
}
|
|
351
|
-
|
|
352
|
-
|
|
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<{
|
|
353
358
|
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
354
359
|
}> : never : never;
|
|
355
|
-
|
|
360
|
+
type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
356
361
|
id: TId;
|
|
357
362
|
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
358
|
-
|
|
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;
|
|
359
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
|
+
} & {
|
|
360
367
|
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
361
368
|
}, TRouteInfoByFullPath = {
|
|
369
|
+
'/': TRouteInfo;
|
|
370
|
+
} & {
|
|
362
371
|
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
|
|
363
372
|
}> {
|
|
364
373
|
routeConfig: TRouteConfig;
|
|
@@ -387,41 +396,40 @@ interface RouteInfo<TId extends string = string, TRouteId extends string = strin
|
|
|
387
396
|
allParams: TAllParams;
|
|
388
397
|
options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
389
398
|
}
|
|
390
|
-
|
|
399
|
+
type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
391
400
|
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
392
401
|
};
|
|
393
|
-
|
|
394
|
-
|
|
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;
|
|
395
404
|
|
|
396
405
|
declare const rootRouteId: "__root__";
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
406
|
+
type RootRouteId = typeof rootRouteId;
|
|
407
|
+
type AnyLoaderData = {};
|
|
408
|
+
type AnyPathParams = {};
|
|
409
|
+
type AnySearchSchema = {};
|
|
401
410
|
interface RouteMeta {
|
|
402
411
|
}
|
|
403
|
-
|
|
404
|
-
|
|
412
|
+
type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
413
|
+
type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
|
|
405
414
|
parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
406
415
|
};
|
|
407
|
-
|
|
416
|
+
type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
|
|
408
417
|
error: 'Top level search params cannot be redefined by child routes!';
|
|
409
418
|
keys: keyof TReturn & keyof TParentSchema;
|
|
410
419
|
} : TReturn;
|
|
411
|
-
|
|
412
|
-
|
|
420
|
+
type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
421
|
+
type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
413
422
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
414
423
|
};
|
|
415
|
-
|
|
424
|
+
type LoaderFn<TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TParentRouteLoaderData, TFullSearchSchema, TAllParams>) => Promise<TRouteLoaderData>;
|
|
416
425
|
interface LoaderContext<TParentRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
417
426
|
params: TAllParams;
|
|
418
427
|
search: TFullSearchSchema;
|
|
419
428
|
signal?: AbortSignal;
|
|
420
|
-
parentLoaderPromise?: Promise<TParentRouteLoaderData>;
|
|
421
429
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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 = {}> = ({
|
|
425
433
|
path: TPath;
|
|
426
434
|
} | {
|
|
427
435
|
id: TRouteId;
|
|
@@ -437,7 +445,6 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
437
445
|
loaderMaxAge?: number;
|
|
438
446
|
loaderGcMaxAge?: number;
|
|
439
447
|
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
440
|
-
useErrorBoundary?: boolean;
|
|
441
448
|
onMatch?: (matchContext: {
|
|
442
449
|
params: TAllParams;
|
|
443
450
|
search: TFullSearchSchema;
|
|
@@ -457,7 +464,7 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
457
464
|
parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
|
|
458
465
|
stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
459
466
|
}) & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
|
|
460
|
-
|
|
467
|
+
type SearchFilter<T, U = T> = (prev: T) => U;
|
|
461
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> {
|
|
462
469
|
id: TId;
|
|
463
470
|
routeId: TRouteId;
|
|
@@ -475,21 +482,21 @@ interface RouteConfig<TId extends string = string, TRouteId extends string = str
|
|
|
475
482
|
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
476
483
|
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
477
484
|
}
|
|
478
|
-
|
|
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'> & {
|
|
479
486
|
path?: never;
|
|
480
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>;
|
|
481
|
-
|
|
482
|
-
|
|
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;
|
|
483
490
|
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
484
491
|
}
|
|
485
492
|
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
486
493
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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;
|
|
490
497
|
declare const createRouteConfig: CreateRouteConfigFn<true>;
|
|
491
498
|
|
|
492
|
-
|
|
499
|
+
type LinkInfo = {
|
|
493
500
|
type: 'external';
|
|
494
501
|
href: string;
|
|
495
502
|
} | {
|
|
@@ -502,12 +509,12 @@ declare type LinkInfo = {
|
|
|
502
509
|
isActive: boolean;
|
|
503
510
|
disabled?: boolean;
|
|
504
511
|
};
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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 [
|
|
511
518
|
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
512
519
|
...infer TToRest
|
|
513
520
|
] ? `${CleanPath<Join<[
|
|
@@ -518,39 +525,40 @@ declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends s
|
|
|
518
525
|
...Split<RestTTo, false>,
|
|
519
526
|
...infer RestPath
|
|
520
527
|
] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
|
|
521
|
-
|
|
528
|
+
type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
522
529
|
replace?: boolean;
|
|
523
530
|
};
|
|
524
|
-
|
|
531
|
+
type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
525
532
|
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
|
|
526
533
|
hash?: Updater<string>;
|
|
534
|
+
state?: LocationState;
|
|
527
535
|
from?: TFrom;
|
|
528
536
|
} & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>, {}> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
|
|
529
|
-
|
|
537
|
+
type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
|
|
530
538
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
531
539
|
} : keyof PickRequired<TToSchema> extends never ? {
|
|
532
540
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
533
541
|
} : {
|
|
534
542
|
search: SearchReducer<TFromSchema, TToSchema>;
|
|
535
543
|
};
|
|
536
|
-
|
|
544
|
+
type SearchReducer<TFrom, TTo> = {
|
|
537
545
|
[TKey in keyof TTo]: TTo[TKey];
|
|
538
546
|
} | ((current: TFrom) => TTo);
|
|
539
|
-
|
|
547
|
+
type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
|
|
540
548
|
params?: ParamsReducer<TFromParams, TToParams>;
|
|
541
549
|
} : AnyPathParams extends TToParams ? {
|
|
542
550
|
params?: ParamsReducer<TFromParams, Record<string, never>>;
|
|
543
551
|
} : {
|
|
544
552
|
params: ParamsReducer<TFromParams, TToParams>;
|
|
545
553
|
};
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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>;
|
|
549
557
|
interface ActiveOptions {
|
|
550
558
|
exact?: boolean;
|
|
551
559
|
includeHash?: boolean;
|
|
552
560
|
}
|
|
553
|
-
|
|
561
|
+
type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
|
|
554
562
|
target?: HTMLAnchorElement['target'];
|
|
555
563
|
activeOptions?: ActiveOptions;
|
|
556
564
|
preload?: false | 'intent';
|
|
@@ -559,22 +567,22 @@ declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
|
|
|
559
567
|
preloadDelay?: number;
|
|
560
568
|
disabled?: boolean;
|
|
561
569
|
};
|
|
562
|
-
|
|
570
|
+
type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
|
|
563
571
|
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
564
572
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
565
573
|
} : {} : {};
|
|
566
|
-
|
|
567
|
-
|
|
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<{
|
|
568
576
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route path.`;
|
|
569
577
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
570
578
|
}>;
|
|
571
|
-
|
|
572
|
-
|
|
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<{
|
|
573
581
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
|
|
574
582
|
'Valid Route IDs': TAllRouteInfo['routeIds'];
|
|
575
583
|
}>;
|
|
576
|
-
|
|
577
|
-
|
|
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']);
|
|
578
586
|
|
|
579
587
|
interface Segment {
|
|
580
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
|
|
|
@@ -2405,9 +2431,9 @@
|
|
|
2405
2431
|
pathname: next.pathname,
|
|
2406
2432
|
hash: next.hash,
|
|
2407
2433
|
search: next.searchStr
|
|
2408
|
-
}, {
|
|
2434
|
+
}, _extends({
|
|
2409
2435
|
id
|
|
2410
|
-
});
|
|
2436
|
+
}, next.state));
|
|
2411
2437
|
} else {
|
|
2412
2438
|
history.push({
|
|
2413
2439
|
pathname: next.pathname,
|