@tanstack/router-core 0.0.1-alpha.0
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/_virtual/_rollupPluginBabelHelpers.js +33 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/cjs/packages/location-core/src/index.js +1313 -0
- package/build/cjs/packages/location-core/src/index.js.map +1 -0
- package/build/cjs/packages/location-core/src/qss.js +70 -0
- package/build/cjs/packages/location-core/src/qss.js.map +1 -0
- package/build/cjs/packages/router-core/src/createRoutes.js +106 -0
- package/build/cjs/packages/router-core/src/createRoutes.js.map +1 -0
- package/build/cjs/packages/router-core/src/createRoutes.test.js +160 -0
- package/build/cjs/packages/router-core/src/createRoutes.test.js.map +1 -0
- package/build/cjs/packages/router-core/src/index.js +1444 -0
- package/build/cjs/packages/router-core/src/index.js.map +1 -0
- package/build/cjs/packages/router-core/src/qss.js +70 -0
- package/build/cjs/packages/router-core/src/qss.js.map +1 -0
- package/build/esm/index.js +2297 -0
- package/build/esm/index.js.map +1 -0
- package/build/stats-html.html +4034 -0
- package/build/stats-react.json +157 -0
- package/build/types/createRoutes.d.ts +10 -0
- package/build/types/createRoutes.test.d.ts +1 -0
- package/build/types/index.d.ts +517 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/react-router/src/createRoutes.test.d.ts +0 -0
- package/build/types/react-router/src/index.d.ts +59 -0
- package/build/types/router-core/src/createRoutes.test.d.ts +1 -0
- package/build/types/router-core/src/index.d.ts +504 -0
- package/build/types/router-core/src/qss.d.ts +2 -0
- package/build/umd/index.development.js +2322 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +12 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +48 -0
- package/src/createRoutes.test.ts +318 -0
- package/src/index.ts +2974 -0
- package/src/package.json +48 -0
- package/src/qss.ts +53 -0
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* router-core
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { BrowserHistory, MemoryHistory, HashHistory, History } from 'history';
|
|
12
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
13
|
+
|
|
14
|
+
declare type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
15
|
+
declare type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
|
|
16
|
+
declare type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
|
|
17
|
+
declare type IsKnown<T, Y, N> = unknown extends T ? N : Y;
|
|
18
|
+
declare type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
19
|
+
declare type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
20
|
+
declare type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
|
|
21
|
+
declare type PickExtra<T, K> = Expand<{
|
|
22
|
+
[TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
|
|
23
|
+
}>;
|
|
24
|
+
declare type PickRequired<T> = {
|
|
25
|
+
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
26
|
+
};
|
|
27
|
+
declare type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
|
|
28
|
+
declare type Expand<T> = T extends object ? T extends infer O ? {
|
|
29
|
+
[K in keyof O]: O[K];
|
|
30
|
+
} : never : T;
|
|
31
|
+
interface FrameworkGenerics {
|
|
32
|
+
}
|
|
33
|
+
interface RouteConfig<TId extends string = string, TPath extends string = string, TFullPath extends string = string, 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> {
|
|
34
|
+
id: TId;
|
|
35
|
+
path: NoInfer<TPath>;
|
|
36
|
+
fullPath: TFullPath;
|
|
37
|
+
options: RouteOptions<TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
38
|
+
children?: TKnownChildren;
|
|
39
|
+
addChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
|
|
40
|
+
error: 'Invalid route detected';
|
|
41
|
+
route: TNewChildren;
|
|
42
|
+
}) => RouteConfig<TId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
43
|
+
}
|
|
44
|
+
declare type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentAllLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <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[]>(options?: TIsRoot extends true ? Omit<RouteOptions<TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
|
|
45
|
+
path?: never;
|
|
46
|
+
} : RouteOptions<TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, children?: TKnownChildren, isRoot?: boolean, parentId?: string) => RouteConfig<RouteId<TParentId, TPath>, TPath, RouteIdToPath<RouteId<TParentId, TPath>>, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
|
|
47
|
+
declare const createRouteConfig: CreateRouteConfigFn<true>;
|
|
48
|
+
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
49
|
+
}
|
|
50
|
+
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
51
|
+
}
|
|
52
|
+
interface AnyAllRouteInfo {
|
|
53
|
+
routeConfig: AnyRouteConfig;
|
|
54
|
+
routeInfo: AnyRouteInfo;
|
|
55
|
+
routeInfoById: Record<string, AnyRouteInfo>;
|
|
56
|
+
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
57
|
+
fullPath: string;
|
|
58
|
+
}
|
|
59
|
+
interface DefaultAllRouteInfo {
|
|
60
|
+
routeConfig: RouteConfig;
|
|
61
|
+
routeInfo: RouteInfo;
|
|
62
|
+
routeInfoById: Record<string, RouteInfo>;
|
|
63
|
+
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
64
|
+
fullPath: string;
|
|
65
|
+
}
|
|
66
|
+
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
67
|
+
}
|
|
68
|
+
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any> = RouteInfo> {
|
|
69
|
+
routeConfig: TRouteConfig;
|
|
70
|
+
routeInfo: TRouteInfo;
|
|
71
|
+
routeInfoById: {
|
|
72
|
+
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
73
|
+
};
|
|
74
|
+
routeInfoByFullPath: {
|
|
75
|
+
[TInfo in TRouteInfo as TInfo['id'] extends RootRouteId ? never : RouteIdToPath<TInfo['id']>]: TInfo;
|
|
76
|
+
};
|
|
77
|
+
fullPath: RouteIdToPath<TRouteInfo['id']>;
|
|
78
|
+
}
|
|
79
|
+
interface AnyRoute extends Route<any, any> {
|
|
80
|
+
}
|
|
81
|
+
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
82
|
+
}
|
|
83
|
+
declare type RouteIdToPath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
|
|
84
|
+
declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
|
|
85
|
+
declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
|
|
86
|
+
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
87
|
+
}> : never : never;
|
|
88
|
+
declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
89
|
+
id: TId;
|
|
90
|
+
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
91
|
+
declare type Values<O> = O[ValueKeys<O>];
|
|
92
|
+
declare type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
93
|
+
declare type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TPath, infer TFullPath, infer TRouteLoaderData, infer TLoaderData, infer TActionPayload, infer TActionResponse, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TId ? never : RouteInfo<TId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
|
|
94
|
+
interface RouteInfo<TId extends string = string, TPath extends string = string, TFullPath extends {} = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends 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 = {}> {
|
|
95
|
+
id: TId;
|
|
96
|
+
path: TPath;
|
|
97
|
+
fullPath: TFullPath;
|
|
98
|
+
routeLoaderData: TRouteLoaderData;
|
|
99
|
+
loaderData: TLoaderData;
|
|
100
|
+
actionPayload: TActionPayload;
|
|
101
|
+
actionResponse: TActionResponse;
|
|
102
|
+
searchSchema: TSearchSchema;
|
|
103
|
+
fullSearchSchema: TFullSearchSchema;
|
|
104
|
+
parentParams: TParentParams;
|
|
105
|
+
params: TParams;
|
|
106
|
+
allParams: TAllParams;
|
|
107
|
+
options: RouteOptions<TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
108
|
+
}
|
|
109
|
+
declare type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
110
|
+
[K in A]: DeepAwaited<B>;
|
|
111
|
+
} : T;
|
|
112
|
+
declare const rootRouteId: "__root__";
|
|
113
|
+
declare type RootRouteId = typeof rootRouteId;
|
|
114
|
+
declare type RouteId<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`;
|
|
115
|
+
declare 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;
|
|
116
|
+
declare type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
117
|
+
declare type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
118
|
+
declare type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
119
|
+
declare type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
|
|
120
|
+
declare 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;
|
|
121
|
+
declare type Split<S, TTrailing = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TTrailing extends true ? CleanPath<S> extends `${infer T}/` ? [T, '/'] : CleanPath<S> extends `/${infer U}` ? ['/', U] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : never : never;
|
|
122
|
+
declare 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;
|
|
123
|
+
declare type AnySearchSchema = {};
|
|
124
|
+
declare type AnyLoaderData = {};
|
|
125
|
+
declare type AnyPathParams = {};
|
|
126
|
+
interface RouteMeta {
|
|
127
|
+
}
|
|
128
|
+
interface LocationState {
|
|
129
|
+
}
|
|
130
|
+
declare type Timeout = ReturnType<typeof setTimeout>;
|
|
131
|
+
declare type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
132
|
+
declare type SearchParser = (searchStr: string) => Record<string, any>;
|
|
133
|
+
declare type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
134
|
+
interface Location<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
135
|
+
href: string;
|
|
136
|
+
pathname: string;
|
|
137
|
+
search: TSearchObj;
|
|
138
|
+
searchStr: string;
|
|
139
|
+
state: TState;
|
|
140
|
+
hash: string;
|
|
141
|
+
key?: string;
|
|
142
|
+
}
|
|
143
|
+
interface FromLocation {
|
|
144
|
+
pathname: string;
|
|
145
|
+
search?: unknown;
|
|
146
|
+
key?: string;
|
|
147
|
+
hash?: string;
|
|
148
|
+
}
|
|
149
|
+
declare type PickExtract<T, U> = {
|
|
150
|
+
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
151
|
+
};
|
|
152
|
+
declare type PickExclude<T, U> = {
|
|
153
|
+
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
154
|
+
};
|
|
155
|
+
declare type SearchSchemaValidator<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
|
|
156
|
+
error: 'Top level search params cannot be redefined by child routes!';
|
|
157
|
+
keys: keyof TReturn & keyof TParentSchema;
|
|
158
|
+
} : TReturn;
|
|
159
|
+
declare type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
160
|
+
declare type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
161
|
+
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
162
|
+
};
|
|
163
|
+
declare type RouteOptions<TPath extends string = string, 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 = {}> = {
|
|
164
|
+
path: TPath;
|
|
165
|
+
caseSensitive?: boolean;
|
|
166
|
+
validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
|
|
167
|
+
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
168
|
+
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
169
|
+
pendingMs?: number;
|
|
170
|
+
pendingMinMs?: number;
|
|
171
|
+
} & ({
|
|
172
|
+
parseParams?: never;
|
|
173
|
+
stringifyParams?: never;
|
|
174
|
+
} | {
|
|
175
|
+
parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
|
|
176
|
+
stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
177
|
+
}) & RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams> & {
|
|
178
|
+
import?: (opts: {
|
|
179
|
+
params: AnyPathParams;
|
|
180
|
+
}) => Promise<RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams>>;
|
|
181
|
+
} & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
|
|
182
|
+
interface RouteLoaders<TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
183
|
+
element?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
|
|
184
|
+
errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
|
|
185
|
+
catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
|
|
186
|
+
pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
|
|
187
|
+
loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
|
|
188
|
+
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
189
|
+
useErrorBoundary?: boolean;
|
|
190
|
+
onMatch?: (matchContext: {
|
|
191
|
+
params: TAllParams;
|
|
192
|
+
search: TFullSearchSchema;
|
|
193
|
+
}) => void | undefined | ((match: {
|
|
194
|
+
params: TAllParams;
|
|
195
|
+
search: TFullSearchSchema;
|
|
196
|
+
}) => void);
|
|
197
|
+
onTransition?: (match: {
|
|
198
|
+
params: TAllParams;
|
|
199
|
+
search: TFullSearchSchema;
|
|
200
|
+
}) => void;
|
|
201
|
+
meta?: RouteMeta;
|
|
202
|
+
}
|
|
203
|
+
declare type SearchFilter<T, U = T> = (prev: T) => U;
|
|
204
|
+
interface MatchLocation {
|
|
205
|
+
to?: string | number | null;
|
|
206
|
+
fuzzy?: boolean;
|
|
207
|
+
caseSensitive?: boolean;
|
|
208
|
+
from?: string;
|
|
209
|
+
fromCurrent?: boolean;
|
|
210
|
+
}
|
|
211
|
+
declare type SearchPredicate<TSearch extends AnySearchSchema = {}> = (search: TSearch) => any;
|
|
212
|
+
declare type LoaderFn<TRouteLoaderData extends AnyLoaderData, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: {
|
|
213
|
+
params: TAllParams;
|
|
214
|
+
search: TFullSearchSchema;
|
|
215
|
+
signal?: AbortSignal;
|
|
216
|
+
}) => Promise<TRouteLoaderData>;
|
|
217
|
+
declare type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
|
|
218
|
+
declare type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
|
|
219
|
+
interface RouterState {
|
|
220
|
+
status: 'idle' | 'loading';
|
|
221
|
+
location: Location;
|
|
222
|
+
matches: RouteMatch[];
|
|
223
|
+
lastUpdated: number;
|
|
224
|
+
loaderData: unknown;
|
|
225
|
+
action?: ActionState;
|
|
226
|
+
actions: Record<string, Action>;
|
|
227
|
+
pending?: PendingState;
|
|
228
|
+
}
|
|
229
|
+
interface PendingState {
|
|
230
|
+
location: Location;
|
|
231
|
+
matches: RouteMatch[];
|
|
232
|
+
}
|
|
233
|
+
declare type ListenerFn = () => void;
|
|
234
|
+
interface Segment {
|
|
235
|
+
type: 'pathname' | 'param' | 'wildcard';
|
|
236
|
+
value: string;
|
|
237
|
+
}
|
|
238
|
+
declare type GetFrameworkGeneric<U, TData = unknown> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
|
|
239
|
+
interface __Experimental__RouterSnapshot {
|
|
240
|
+
location: Location;
|
|
241
|
+
matches: SnapshotRouteMatch<unknown>[];
|
|
242
|
+
}
|
|
243
|
+
interface SnapshotRouteMatch<TData> {
|
|
244
|
+
matchId: string;
|
|
245
|
+
loaderData: TData;
|
|
246
|
+
}
|
|
247
|
+
interface BuildNextOptions {
|
|
248
|
+
to?: string | number | null;
|
|
249
|
+
params?: true | Updater<Record<string, any>>;
|
|
250
|
+
search?: true | Updater<unknown>;
|
|
251
|
+
hash?: true | Updater<string>;
|
|
252
|
+
key?: string;
|
|
253
|
+
from?: string;
|
|
254
|
+
fromCurrent?: boolean;
|
|
255
|
+
__preSearchFilters?: SearchFilter<any>[];
|
|
256
|
+
__postSearchFilters?: SearchFilter<any>[];
|
|
257
|
+
}
|
|
258
|
+
interface ActiveOptions {
|
|
259
|
+
exact?: boolean;
|
|
260
|
+
includeHash?: boolean;
|
|
261
|
+
}
|
|
262
|
+
declare type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
|
|
263
|
+
declare type Listener = () => void;
|
|
264
|
+
interface MatchRouteOptions {
|
|
265
|
+
pending: boolean;
|
|
266
|
+
caseSensitive?: boolean;
|
|
267
|
+
}
|
|
268
|
+
declare type LinkInfo = {
|
|
269
|
+
type: 'external';
|
|
270
|
+
href: string;
|
|
271
|
+
} | {
|
|
272
|
+
type: 'internal';
|
|
273
|
+
next: Location;
|
|
274
|
+
handleFocus: (e: any) => void;
|
|
275
|
+
handleClick: (e: any) => void;
|
|
276
|
+
handleEnter: (e: any) => void;
|
|
277
|
+
handleLeave: (e: any) => void;
|
|
278
|
+
isActive: boolean;
|
|
279
|
+
disabled?: boolean;
|
|
280
|
+
};
|
|
281
|
+
declare type PreloadCacheEntry = {
|
|
282
|
+
maxAge: number;
|
|
283
|
+
match: RouteMatch;
|
|
284
|
+
};
|
|
285
|
+
interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
286
|
+
history?: BrowserHistory | MemoryHistory | HashHistory;
|
|
287
|
+
stringifySearch?: SearchSerializer;
|
|
288
|
+
parseSearch?: SearchParser;
|
|
289
|
+
filterRoutes?: FilterRoutesFn;
|
|
290
|
+
defaultLinkPreload?: false | 'intent';
|
|
291
|
+
defaultLinkPreloadMaxAge?: number;
|
|
292
|
+
defaultLinkPreloadDelay?: number;
|
|
293
|
+
useErrorBoundary?: boolean;
|
|
294
|
+
defaultElement?: GetFrameworkGeneric<'Element'>;
|
|
295
|
+
defaultErrorElement?: GetFrameworkGeneric<'Element'>;
|
|
296
|
+
defaultCatchElement?: GetFrameworkGeneric<'Element'>;
|
|
297
|
+
defaultPendingElement?: GetFrameworkGeneric<'Element'>;
|
|
298
|
+
defaultPendingMs?: number;
|
|
299
|
+
defaultPendingMinMs?: number;
|
|
300
|
+
caseSensitive?: boolean;
|
|
301
|
+
__experimental__snapshot?: __Experimental__RouterSnapshot;
|
|
302
|
+
routeConfig?: TRouteConfig;
|
|
303
|
+
basepath?: string;
|
|
304
|
+
createRouter?: (router: Router<any, any>) => void;
|
|
305
|
+
createRoute?: (opts: {
|
|
306
|
+
route: AnyRoute;
|
|
307
|
+
router: Router<any, any>;
|
|
308
|
+
}) => void;
|
|
309
|
+
}
|
|
310
|
+
interface Action<TPayload = unknown, TResponse = unknown> {
|
|
311
|
+
submit: (submission?: TPayload) => Promise<TResponse>;
|
|
312
|
+
latest?: ActionState;
|
|
313
|
+
pending: ActionState<TPayload, TResponse>[];
|
|
314
|
+
}
|
|
315
|
+
interface ActionState<TPayload = unknown, TResponse = unknown> {
|
|
316
|
+
submittedAt: number;
|
|
317
|
+
status: 'idle' | 'pending' | 'success' | 'error';
|
|
318
|
+
submission: TPayload;
|
|
319
|
+
data?: TResponse;
|
|
320
|
+
error?: unknown;
|
|
321
|
+
}
|
|
322
|
+
declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
323
|
+
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
324
|
+
};
|
|
325
|
+
declare type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['fullPath'] ? string : TAllRouteInfo['fullPath']);
|
|
326
|
+
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
327
|
+
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
328
|
+
basepath: string;
|
|
329
|
+
allRouteInfo: TAllRouteInfo;
|
|
330
|
+
listeners: Listener[];
|
|
331
|
+
location: Location;
|
|
332
|
+
navigateTimeout?: Timeout;
|
|
333
|
+
nextAction?: 'push' | 'replace';
|
|
334
|
+
state: RouterState;
|
|
335
|
+
routeTree: Route<TAllRouteInfo, RouteInfo>;
|
|
336
|
+
routesById: RoutesById<TAllRouteInfo>;
|
|
337
|
+
navigationPromise: Promise<void>;
|
|
338
|
+
startedLoadingAt: number;
|
|
339
|
+
destroy: () => void;
|
|
340
|
+
resolveNavigation: () => void;
|
|
341
|
+
subscribe: (listener: Listener) => () => void;
|
|
342
|
+
notify: () => void;
|
|
343
|
+
mount: () => Promise<void>;
|
|
344
|
+
update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
|
|
345
|
+
buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
|
|
346
|
+
parseLocation: (location: History['location'], previousLocation?: Location) => Location;
|
|
347
|
+
buildLocation: (dest: BuildNextOptions) => Location;
|
|
348
|
+
commitLocation: (next: Location, replace?: boolean) => Promise<void>;
|
|
349
|
+
buildNext: (opts: BuildNextOptions) => Location;
|
|
350
|
+
cancelMatches: () => void;
|
|
351
|
+
loadLocation: (next?: Location) => Promise<void>;
|
|
352
|
+
preloadCache: Record<string, PreloadCacheEntry>;
|
|
353
|
+
cleanPreloadCache: () => void;
|
|
354
|
+
getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
|
|
355
|
+
loadRoute: (navigateOpts: BuildNextOptions, loaderOpts: {
|
|
356
|
+
maxAge: number;
|
|
357
|
+
}) => Promise<RouteMatch[]>;
|
|
358
|
+
matchRoutes: (pathname: string, opts?: {
|
|
359
|
+
strictParseParams?: boolean;
|
|
360
|
+
}) => RouteMatch[];
|
|
361
|
+
loadMatches: (resolvedMatches: RouteMatch[], loaderOpts?: {
|
|
362
|
+
withPending?: boolean;
|
|
363
|
+
} & ({
|
|
364
|
+
preload: true;
|
|
365
|
+
maxAge: number;
|
|
366
|
+
} | {
|
|
367
|
+
preload?: false;
|
|
368
|
+
maxAge?: never;
|
|
369
|
+
})) => Promise<RouteMatch[]>;
|
|
370
|
+
invalidateRoute: (opts: MatchLocation) => void;
|
|
371
|
+
reload: () => Promise<void>;
|
|
372
|
+
resolvePath: (from: string, path: string) => string;
|
|
373
|
+
_navigate: (location: BuildNextOptions & {
|
|
374
|
+
replace?: boolean;
|
|
375
|
+
}) => Promise<void>;
|
|
376
|
+
navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
|
|
377
|
+
matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
|
|
378
|
+
buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
|
|
379
|
+
__experimental__createSnapshot: () => __Experimental__RouterSnapshot;
|
|
380
|
+
}
|
|
381
|
+
declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
|
|
382
|
+
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
383
|
+
routeId: TRouteInfo['id'];
|
|
384
|
+
routePath: TRouteInfo['path'];
|
|
385
|
+
fullPath: TRouteInfo['fullPath'];
|
|
386
|
+
parentRoute?: AnyRoute;
|
|
387
|
+
childRoutes?: AnyRoute[];
|
|
388
|
+
options: RouteOptions;
|
|
389
|
+
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
|
|
390
|
+
buildLink: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => LinkInfo;
|
|
391
|
+
matchRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>>(matchLocation: Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>, opts?: MatchRouteOptions) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams'];
|
|
392
|
+
navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>) => Promise<void>;
|
|
393
|
+
action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
|
|
394
|
+
}
|
|
395
|
+
declare function createRoute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(routeConfig: RouteConfig, options: TRouteInfo['options'], parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>): Route<TAllRouteInfo, TRouteInfo>;
|
|
396
|
+
declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
397
|
+
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
398
|
+
...infer TToRest
|
|
399
|
+
] ? `${CleanPath<Join<[
|
|
400
|
+
...Split<TTo, false>,
|
|
401
|
+
...(TToRest | (Split<ResolveRelativePath<TFrom, TTo>, false>['length'] extends 1 ? never : ['../']))
|
|
402
|
+
]>>}` : never : TTo extends `./${infer RestTTo}` ? SplitPaths extends [
|
|
403
|
+
...Split<TFrom, false>,
|
|
404
|
+
...Split<RestTTo, false>,
|
|
405
|
+
...infer RestPath
|
|
406
|
+
] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
|
|
407
|
+
declare type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
408
|
+
replace?: boolean;
|
|
409
|
+
};
|
|
410
|
+
declare type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
411
|
+
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
|
|
412
|
+
hash?: Updater<string>;
|
|
413
|
+
from?: TFrom;
|
|
414
|
+
} & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
|
|
415
|
+
declare type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['fullPath'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
416
|
+
declare type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeInfo']['id'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
417
|
+
declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
|
|
418
|
+
target?: HTMLAnchorElement['target'];
|
|
419
|
+
activeOptions?: ActiveOptions;
|
|
420
|
+
preload?: false | 'intent';
|
|
421
|
+
preloadMaxAge?: number;
|
|
422
|
+
preloadDelay?: number;
|
|
423
|
+
disabled?: boolean;
|
|
424
|
+
};
|
|
425
|
+
declare type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['fullPath'] ? {} : {
|
|
426
|
+
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
427
|
+
'Valid Route Paths': TAllRouteInfo['fullPath'];
|
|
428
|
+
} : {} : {};
|
|
429
|
+
declare type ResolveRelativePath<TFrom, TTo = '.', TRooted = false> = 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] ? ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
|
|
430
|
+
declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
|
|
431
|
+
declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
|
|
432
|
+
declare type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
|
|
433
|
+
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
434
|
+
} : keyof PickRequired<TToSchema> extends never ? {
|
|
435
|
+
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
436
|
+
} : {
|
|
437
|
+
search: SearchReducer<TFromSchema, TToSchema>;
|
|
438
|
+
};
|
|
439
|
+
declare type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
440
|
+
declare type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
|
|
441
|
+
params?: ParamsReducer<TFromParams, TToParams>;
|
|
442
|
+
} : AnyPathParams extends TToParams ? {
|
|
443
|
+
params?: ParamsReducer<TFromParams, Record<string, never>>;
|
|
444
|
+
} : {
|
|
445
|
+
params: ParamsReducer<TFromParams, TToParams>;
|
|
446
|
+
};
|
|
447
|
+
declare type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
448
|
+
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
449
|
+
matchId: string;
|
|
450
|
+
pathname: string;
|
|
451
|
+
params: AnyPathParams;
|
|
452
|
+
parentMatch?: RouteMatch;
|
|
453
|
+
childMatches: RouteMatch[];
|
|
454
|
+
routeSearch: TRouteInfo['searchSchema'];
|
|
455
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
456
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
457
|
+
updatedAt?: number;
|
|
458
|
+
error?: unknown;
|
|
459
|
+
isInvalid: boolean;
|
|
460
|
+
loaderData: TRouteInfo['loaderData'];
|
|
461
|
+
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
462
|
+
isFetching: boolean;
|
|
463
|
+
isPending: boolean;
|
|
464
|
+
__: {
|
|
465
|
+
element?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
|
|
466
|
+
errorElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
|
|
467
|
+
catchElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
|
|
468
|
+
pendingElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
|
|
469
|
+
loadPromise?: Promise<void>;
|
|
470
|
+
loaderPromise?: Promise<void>;
|
|
471
|
+
importPromise?: Promise<void>;
|
|
472
|
+
elementsPromise?: Promise<void>;
|
|
473
|
+
dataPromise?: Promise<void>;
|
|
474
|
+
pendingTimeout?: Timeout;
|
|
475
|
+
pendingMinTimeout?: Timeout;
|
|
476
|
+
pendingMinPromise?: Promise<void>;
|
|
477
|
+
onExit?: void | ((matchContext: {
|
|
478
|
+
params: TRouteInfo['allParams'];
|
|
479
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
480
|
+
}) => void);
|
|
481
|
+
abortController: AbortController;
|
|
482
|
+
latestId: string;
|
|
483
|
+
setParentMatch: (parentMatch: RouteMatch) => void;
|
|
484
|
+
addChildMatch: (childMatch: RouteMatch) => void;
|
|
485
|
+
validate: () => void;
|
|
486
|
+
startPending: () => void;
|
|
487
|
+
cancelPending: () => void;
|
|
488
|
+
notify: () => void;
|
|
489
|
+
resolve: () => void;
|
|
490
|
+
};
|
|
491
|
+
cancel: () => void;
|
|
492
|
+
load: () => Promise<void>;
|
|
493
|
+
}
|
|
494
|
+
declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
495
|
+
matchId: string;
|
|
496
|
+
params: TRouteInfo['allParams'];
|
|
497
|
+
pathname: string;
|
|
498
|
+
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
499
|
+
declare function matchPathname(currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
500
|
+
declare function warning(cond: any, message: string): cond is true;
|
|
501
|
+
declare function functionalUpdate<TResult>(updater?: Updater<TResult>, previous?: TResult): TResult | undefined;
|
|
502
|
+
declare function matchByPath(from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
|
503
|
+
declare function parsePathname(pathname?: string): Segment[];
|
|
504
|
+
declare function resolvePath(basepath: string, base: string, to: string): string;
|
|
505
|
+
/**
|
|
506
|
+
* This function returns `a` if `b` is deeply equal.
|
|
507
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
508
|
+
* This can be used for structural sharing between JSON values for example.
|
|
509
|
+
*/
|
|
510
|
+
declare function replaceEqualDeep(prev: any, next: any): any;
|
|
511
|
+
declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
|
|
512
|
+
declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
513
|
+
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
514
|
+
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
515
|
+
declare function last<T>(arr: T[]): T | undefined;
|
|
516
|
+
|
|
517
|
+
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckRelativePath, DefaultAllRouteInfo, DefinedPathParamWarning, FilterRoutesFn, FrameworkGenerics, FromLocation, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, LoaderFn, Location, LocationState, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickUnsafe, PreloadCacheEntry, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteLoaders, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesInfoInner, SearchFilter, SearchParser, SearchPredicate, SearchSchemaValidator, SearchSerializer, Segment, SnapshotRouteMatch, ToIdOption, ToOptions, ToPathOption, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, __Experimental__RouterSnapshot, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, warning };
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Router, RouterOptions, RouteMatch, RouteParams, NavigateOptions, MatchLocation, MatchRouteOptions, LinkOptions, RouteDef, RoutesInfo } from '@tanstack/router-core';
|
|
3
|
+
export * from '@tanstack/router-core';
|
|
4
|
+
declare module '@tanstack/router-core' {
|
|
5
|
+
interface FrameworkGenerics {
|
|
6
|
+
Element: React.ReactNode;
|
|
7
|
+
AsyncElement: (opts: {
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
}) => Promise<React.ReactNode>;
|
|
10
|
+
SyncOrAsyncElement: React.ReactNode | FrameworkGenerics['AsyncElement'];
|
|
11
|
+
LinkProps: React.HTMLAttributes<unknown>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare type PromptProps = {
|
|
15
|
+
message: string;
|
|
16
|
+
when?: boolean | any;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
};
|
|
19
|
+
export declare type MatchesProviderProps = {
|
|
20
|
+
value: RouteMatch[];
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
};
|
|
23
|
+
export declare function MatchesProvider(props: MatchesProviderProps): JSX.Element;
|
|
24
|
+
export declare type RouterProps<TRouteDefs extends RouteDef = RouteDef> = RouterOptions<TRouteDefs> & {
|
|
25
|
+
router: Router<TRouteDefs>;
|
|
26
|
+
children?: React.ReactNode;
|
|
27
|
+
};
|
|
28
|
+
export declare class ReactRouter<TRouteDefs extends RouteDef = RouteDef, TRoutesInfo extends RoutesInfo<TRouteDefs> = RoutesInfo<TRouteDefs>> extends Router<TRouteDefs, TRoutesInfo> {
|
|
29
|
+
constructor(options: RouterOptions<TRouteDefs>);
|
|
30
|
+
}
|
|
31
|
+
export declare function RouterProvider<TRouteDefs extends RouteDef = RouteDef>({ children, router, ...rest }: RouterProps<TRouteDefs>): JSX.Element;
|
|
32
|
+
export declare function useRouter(): Router;
|
|
33
|
+
export declare function useMatches(): RouteMatch[];
|
|
34
|
+
export declare function useParentMatches(): RouteMatch[];
|
|
35
|
+
export declare function useMatch<T>(): RouteMatch;
|
|
36
|
+
export declare function useLoaderData(): unknown;
|
|
37
|
+
export declare function useAction<TPayload = unknown, TResponse = unknown, TError = unknown>(opts?: Pick<NavigateOptions, 'to' | 'from'>): import("@tanstack/router-core").Action<TPayload, TResponse>;
|
|
38
|
+
export declare function useMatchRoute(): (matchLocation: MatchLocation, opts?: MatchRouteOptions | undefined) => RouteParams | undefined;
|
|
39
|
+
export declare type MatchRouteProps = MatchLocation & MatchRouteOptions & {
|
|
40
|
+
children: React.ReactNode | ((routeParams?: RouteParams) => React.ReactNode);
|
|
41
|
+
};
|
|
42
|
+
export declare function MatchRoute({ children, pending, caseSensitive, ...rest }: MatchRouteProps): JSX.Element;
|
|
43
|
+
export declare function useLoadRoute(): (navigateOpts: NavigateOptions, loaderOpts: {
|
|
44
|
+
maxAge: number;
|
|
45
|
+
}) => Promise<RouteMatch<string, string, {}, {}, unknown, unknown, {}, {}, Record<never, string>>[]>;
|
|
46
|
+
export declare function useInvalidateRoute(): (navigateOpts?: MatchLocation | undefined) => Promise<void>;
|
|
47
|
+
export declare function useNavigate(): (options: NavigateOptions) => Promise<void>;
|
|
48
|
+
export declare function Navigate(options: NavigateOptions): null;
|
|
49
|
+
export declare function Outlet(): JSX.Element | null;
|
|
50
|
+
export declare function useResolvePath(): (path: string) => string;
|
|
51
|
+
export declare function useSearch(): {};
|
|
52
|
+
export declare type LinkProps<TRoutesInfo extends RoutesInfo = RoutesInfo, TRouteId extends keyof TRoutesInfo['routesById'] = any> = LinkOptions & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'children' | keyof LinkOptions> & {
|
|
53
|
+
_ref?: React.Ref<HTMLAnchorElement>;
|
|
54
|
+
children?: React.ReactNode | ((state: {
|
|
55
|
+
isActive: boolean;
|
|
56
|
+
}) => React.ReactNode);
|
|
57
|
+
};
|
|
58
|
+
export declare function useLink(opts: LinkOptions): import("@tanstack/router-core").LinkInfo | null;
|
|
59
|
+
export declare function Link<TRoutesInfo>(props: LinkProps): JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|