@tanstack/router-core 0.0.1-beta.5 → 0.0.1-beta.50

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/actions.js +94 -0
  3. package/build/cjs/actions.js.map +1 -0
  4. package/build/cjs/history.js +163 -0
  5. package/build/cjs/history.js.map +1 -0
  6. package/build/cjs/{packages/router-core/src/index.js → index.js} +26 -11
  7. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  8. package/build/cjs/interop.js +175 -0
  9. package/build/cjs/interop.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/path.js → path.js} +23 -48
  11. package/build/cjs/path.js.map +1 -0
  12. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  13. package/build/cjs/qss.js.map +1 -0
  14. package/build/cjs/route.js +33 -0
  15. package/build/cjs/route.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -18
  17. package/build/cjs/routeConfig.js.map +1 -0
  18. package/build/cjs/routeMatch.js +237 -0
  19. package/build/cjs/routeMatch.js.map +1 -0
  20. package/build/cjs/router.js +821 -0
  21. package/build/cjs/router.js.map +1 -0
  22. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
  23. package/build/cjs/searchParams.js.map +1 -0
  24. package/build/cjs/store.js +54 -0
  25. package/build/cjs/store.js.map +1 -0
  26. package/build/cjs/utils.js +47 -0
  27. package/build/cjs/utils.js.map +1 -0
  28. package/build/esm/index.js +1384 -2059
  29. package/build/esm/index.js.map +1 -1
  30. package/build/stats-html.html +59 -49
  31. package/build/stats-react.json +248 -193
  32. package/build/types/index.d.ts +385 -317
  33. package/build/umd/index.development.js +1486 -2142
  34. package/build/umd/index.development.js.map +1 -1
  35. package/build/umd/index.production.js +1 -1
  36. package/build/umd/index.production.js.map +1 -1
  37. package/package.json +6 -4
  38. package/src/actions.ts +157 -0
  39. package/src/frameworks.ts +2 -2
  40. package/src/history.ts +199 -0
  41. package/src/index.ts +4 -7
  42. package/src/interop.ts +169 -0
  43. package/src/link.ts +87 -44
  44. package/src/path.ts +12 -8
  45. package/src/route.ts +36 -229
  46. package/src/routeConfig.ts +99 -102
  47. package/src/routeInfo.ts +28 -25
  48. package/src/routeMatch.ts +294 -322
  49. package/src/router.ts +1047 -884
  50. package/src/store.ts +52 -0
  51. package/src/utils.ts +14 -72
  52. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  53. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  54. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  55. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  56. package/build/cjs/node_modules/history/index.js +0 -815
  57. package/build/cjs/node_modules/history/index.js.map +0 -1
  58. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  59. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  60. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  61. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  62. package/build/cjs/packages/router-core/src/route.js +0 -161
  63. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  64. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  65. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  66. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  67. package/build/cjs/packages/router-core/src/router.js +0 -797
  68. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  69. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  70. package/build/cjs/packages/router-core/src/utils.js +0 -118
  71. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
@@ -8,57 +8,96 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { BrowserHistory, MemoryHistory, HashHistory, History } from 'history';
12
- export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
13
11
  export { default as invariant } from 'tiny-invariant';
14
12
 
13
+ interface RouterHistory {
14
+ location: RouterLocation;
15
+ listen: (cb: () => void) => () => void;
16
+ push: (path: string, state: any) => void;
17
+ replace: (path: string, state: any) => void;
18
+ go: (index: number) => void;
19
+ back: () => void;
20
+ forward: () => void;
21
+ }
22
+ interface ParsedPath {
23
+ href: string;
24
+ pathname: string;
25
+ search: string;
26
+ hash: string;
27
+ }
28
+ interface RouterLocation extends ParsedPath {
29
+ state: any;
30
+ }
31
+ declare function createBrowserHistory(opts?: {
32
+ getHref?: () => string;
33
+ createHref?: (path: string) => string;
34
+ }): RouterHistory;
35
+ declare function createHashHistory(): RouterHistory;
36
+ declare function createMemoryHistory(opts?: {
37
+ initialEntries: string[];
38
+ initialIndex?: number;
39
+ }): RouterHistory;
40
+
15
41
  interface FrameworkGenerics {
16
42
  }
17
- declare type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
43
+ type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
18
44
 
19
- declare type NoInfer<T> = [T][T extends any ? 0 : never];
20
- declare type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
21
- declare type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
22
- declare type IsKnown<T, Y, N> = unknown extends T ? N : Y;
23
- declare type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
24
- declare type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
25
- declare type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
26
- declare type PickExtra<T, K> = Expand<{
45
+ type Store<TState> = {
46
+ state: TState;
47
+ subscribe: (listener: (next: TState, prev: TState) => void) => () => void;
48
+ setState: (updater: (cb: TState) => void) => void;
49
+ };
50
+ declare function createStore<TState>(initialState: TState, debug?: boolean): Store<TState>;
51
+ declare function batch(cb: () => void): void;
52
+
53
+ type NoInfer<T> = [T][T extends any ? 0 : never];
54
+ type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
55
+ type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
56
+ type IsKnown<T, Y, N> = unknown extends T ? N : Y;
57
+ type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
58
+ type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
59
+ type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
60
+ type PickExtra<T, K> = Expand<{
27
61
  [TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
28
62
  }>;
29
- declare type PickRequired<T> = {
63
+ type PickRequired<T> = {
30
64
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
31
65
  };
32
- declare type Expand<T> = T extends object ? T extends infer O ? {
66
+ type Expand<T> = T extends object ? T extends infer O ? {
33
67
  [K in keyof O]: O[K];
34
68
  } : never : T;
35
- declare type Values<O> = O[ValueKeys<O>];
36
- declare type ValueKeys<O> = Extract<keyof O, PropertyKey>;
37
- declare type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
69
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
70
+ type Values<O> = O[ValueKeys<O>];
71
+ type ValueKeys<O> = Extract<keyof O, PropertyKey>;
72
+ type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
38
73
  [K in A]: DeepAwaited<B>;
39
74
  } : T;
40
- 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;
41
- declare type Timeout = ReturnType<typeof setTimeout>;
42
- declare type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
43
- declare type PickExtract<T, U> = {
75
+ 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;
76
+ type Timeout = ReturnType<typeof setTimeout>;
77
+ type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
78
+ type PickExtract<T, U> = {
44
79
  [K in keyof T as T[K] extends U ? K : never]: T[K];
45
80
  };
46
- declare type PickExclude<T, U> = {
81
+ type PickExclude<T, U> = {
47
82
  [K in keyof T as T[K] extends U ? never : K]: T[K];
48
83
  };
49
- /**
50
- * This function returns `a` if `b` is deeply equal.
51
- * If not, it will replace any deeply equal children of `b` with those of `a`.
52
- * This can be used for structural sharing between JSON values for example.
53
- */
54
- declare function replaceEqualDeep(prev: any, next: any): any;
55
84
  declare function last<T>(arr: T[]): T | undefined;
56
85
  declare function warning(cond: any, message: string): cond is true;
57
86
  declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
87
+ declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
58
88
 
89
+ interface RegisterRouter {
90
+ }
91
+ type AnyRouter = Router<any, any, any>;
92
+ type RegisteredRouter = RegisterRouter extends {
93
+ router: Router<infer TRouteConfig, infer TAllRouteInfo, infer TRouterContext>;
94
+ } ? Router<TRouteConfig, TAllRouteInfo, TRouterContext> : Router;
95
+ type RegisteredAllRouteInfo = RegisterRouter extends {
96
+ router: Router<infer TRouteConfig, infer TAllRouteInfo, infer TRouterContext>;
97
+ } ? TAllRouteInfo : AnyAllRouteInfo;
59
98
  interface LocationState {
60
99
  }
61
- interface Location<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
100
+ interface ParsedLocation<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
62
101
  href: string;
63
102
  pathname: string;
64
103
  search: TSearchObj;
@@ -73,11 +112,11 @@ interface FromLocation {
73
112
  key?: string;
74
113
  hash?: string;
75
114
  }
76
- declare type SearchSerializer = (searchObj: Record<string, any>) => string;
77
- declare type SearchParser = (searchStr: string) => Record<string, any>;
78
- declare type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
79
- interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
80
- history?: BrowserHistory | MemoryHistory | HashHistory;
115
+ type SearchSerializer = (searchObj: Record<string, any>) => string;
116
+ type SearchParser = (searchStr: string) => Record<string, any>;
117
+ type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
118
+ interface RouterOptions<TRouteConfig extends AnyRouteConfig, TRouterContext> {
119
+ history?: RouterHistory;
81
120
  stringifySearch?: SearchSerializer;
82
121
  parseSearch?: SearchParser;
83
122
  filterRoutes?: FilterRoutesFn;
@@ -85,38 +124,29 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
85
124
  defaultPreloadMaxAge?: number;
86
125
  defaultPreloadGcMaxAge?: number;
87
126
  defaultPreloadDelay?: number;
88
- useErrorBoundary?: boolean;
89
- defaultElement?: GetFrameworkGeneric<'Element'>;
90
- defaultErrorElement?: GetFrameworkGeneric<'Element'>;
91
- defaultCatchElement?: GetFrameworkGeneric<'Element'>;
92
- defaultPendingElement?: GetFrameworkGeneric<'Element'>;
93
- defaultPendingMs?: number;
94
- defaultPendingMinMs?: number;
127
+ defaultComponent?: GetFrameworkGeneric<'Component'>;
128
+ defaultErrorComponent?: GetFrameworkGeneric<'ErrorComponent'>;
129
+ defaultPendingComponent?: GetFrameworkGeneric<'Component'>;
95
130
  defaultLoaderMaxAge?: number;
96
131
  defaultLoaderGcMaxAge?: number;
97
132
  caseSensitive?: boolean;
98
133
  routeConfig?: TRouteConfig;
99
134
  basepath?: string;
100
- createRouter?: (router: Router<any, any>) => void;
135
+ useServerData?: boolean;
136
+ createRouter?: (router: AnyRouter) => void;
101
137
  createRoute?: (opts: {
102
138
  route: AnyRoute;
103
- router: Router<any, any>;
139
+ router: AnyRouter;
104
140
  }) => void;
105
- createElement?: (element: GetFrameworkGeneric<'SyncOrAsyncElement'>) => Promise<GetFrameworkGeneric<'Element'>>;
106
- }
107
- interface Action<TPayload = unknown, TResponse = unknown> {
108
- submit: (submission?: TPayload) => Promise<TResponse>;
109
- current?: ActionState<TPayload, TResponse>;
110
- latest?: ActionState<TPayload, TResponse>;
111
- pending: ActionState<TPayload, TResponse>[];
112
- }
113
- interface ActionState<TPayload = unknown, TResponse = unknown> {
114
- submittedAt: number;
115
- status: 'idle' | 'pending' | 'success' | 'error';
116
- submission: TPayload;
117
- data?: TResponse;
118
- error?: unknown;
141
+ context?: TRouterContext;
142
+ loadComponent?: (component: GetFrameworkGeneric<'Component'>) => Promise<GetFrameworkGeneric<'Component'>>;
143
+ onRouteChange?: () => void;
144
+ fetchServerDataFn?: FetchServerDataFn;
119
145
  }
146
+ type FetchServerDataFn = (ctx: {
147
+ router: AnyRouter;
148
+ routeMatch: RouteMatch;
149
+ }) => Promise<any>;
120
150
  interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}, TRouteLoaderData = AnyLoaderData> {
121
151
  fetch: keyof PickRequired<TFullSearchSchema> extends never ? keyof TAllParams extends never ? (loaderContext: {
122
152
  signal?: AbortSignal;
@@ -136,41 +166,37 @@ interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams exte
136
166
  latest?: LoaderState<TFullSearchSchema, TAllParams>;
137
167
  pending: LoaderState<TFullSearchSchema, TAllParams>[];
138
168
  }
139
- interface LoaderState<TFullSearchSchema = unknown, TAllParams = unknown> {
169
+ interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
140
170
  loadedAt: number;
141
171
  loaderContext: LoaderContext<TFullSearchSchema, TAllParams>;
142
172
  }
143
- interface RouterState {
173
+ interface RouterStore<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
144
174
  status: 'idle' | 'loading';
145
- location: Location;
146
- matches: RouteMatch[];
175
+ latestLocation: ParsedLocation<TSearchObj, TState>;
176
+ currentMatches: RouteMatch[];
177
+ currentLocation: ParsedLocation<TSearchObj, TState>;
178
+ pendingMatches?: RouteMatch[];
179
+ pendingLocation?: ParsedLocation<TSearchObj, TState>;
147
180
  lastUpdated: number;
148
- currentAction?: ActionState;
149
- latestAction?: ActionState;
150
- actions: Record<string, Action>;
151
181
  loaders: Record<string, Loader>;
152
- pending?: PendingState;
153
182
  isFetching: boolean;
154
183
  isPreloading: boolean;
184
+ matchCache: Record<string, MatchCacheEntry>;
155
185
  }
156
- interface PendingState {
157
- location: Location;
158
- matches: RouteMatch[];
159
- }
160
- declare type Listener = (router: Router<any, any>) => void;
161
- declare type ListenerFn = () => void;
186
+ type ListenerFn = () => void;
162
187
  interface BuildNextOptions {
163
188
  to?: string | number | null;
164
- params?: true | Updater<Record<string, any>>;
189
+ params?: true | Updater<unknown>;
165
190
  search?: true | Updater<unknown>;
166
191
  hash?: true | Updater<string>;
192
+ state?: LocationState;
167
193
  key?: string;
168
194
  from?: string;
169
195
  fromCurrent?: boolean;
170
196
  __preSearchFilters?: SearchFilter<any>[];
171
197
  __postSearchFilters?: SearchFilter<any>[];
172
198
  }
173
- declare type MatchCacheEntry = {
199
+ type MatchCacheEntry = {
174
200
  gc: number;
175
201
  match: RouteMatch;
176
202
  };
@@ -182,50 +208,60 @@ interface MatchLocation {
182
208
  fromCurrent?: boolean;
183
209
  }
184
210
  interface MatchRouteOptions {
185
- pending: boolean;
211
+ pending?: boolean;
186
212
  caseSensitive?: boolean;
213
+ fuzzy?: boolean;
214
+ }
215
+ interface DehydratedRouterState extends Pick<RouterStore, 'status' | 'latestLocation' | 'currentLocation' | 'lastUpdated'> {
216
+ currentMatches: DehydratedRouteMatch[];
217
+ }
218
+ interface DehydratedRouter<TRouterContext = unknown> {
219
+ state: DehydratedRouterState;
220
+ context: TRouterContext;
221
+ }
222
+ type MatchCache = Record<string, MatchCacheEntry>;
223
+ interface DehydratedRouteMatch {
224
+ matchId: string;
225
+ state: Pick<RouteMatchStore<any, any>, 'status' | 'routeLoaderData' | 'invalid' | 'invalidAt'>;
226
+ }
227
+ interface RouterContext {
187
228
  }
188
- interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
189
- history: BrowserHistory | MemoryHistory | HashHistory;
190
- options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
229
+ declare const defaultFetchServerDataFn: FetchServerDataFn;
230
+ declare class Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>, TRouterContext = unknown> {
231
+ #private;
232
+ types: {
233
+ RouteConfig: TRouteConfig;
234
+ AllRouteInfo: TAllRouteInfo;
235
+ };
236
+ options: PickAsRequired<RouterOptions<TRouteConfig, TRouterContext>, 'stringifySearch' | 'parseSearch' | 'context'>;
237
+ history: RouterHistory;
191
238
  basepath: string;
192
- allRouteInfo: TAllRouteInfo;
193
- listeners: Listener[];
194
- location: Location;
195
- navigateTimeout?: Timeout;
196
- nextAction?: 'push' | 'replace';
197
- state: RouterState;
198
239
  routeTree: Route<TAllRouteInfo, RouteInfo>;
199
240
  routesById: RoutesById<TAllRouteInfo>;
200
- navigationPromise: Promise<void>;
201
- removeActionQueue: {
202
- action: Action;
203
- actionState: ActionState;
204
- }[];
241
+ navigateTimeout: undefined | Timeout;
242
+ nextAction: undefined | 'push' | 'replace';
243
+ navigationPromise: undefined | Promise<void>;
244
+ store: Store<RouterStore<TAllRouteInfo['fullSearchSchema']>>;
205
245
  startedLoadingAt: number;
206
246
  resolveNavigation: () => void;
207
- subscribe: (listener: Listener) => () => void;
208
- notify: () => void;
247
+ constructor(options?: RouterOptions<TRouteConfig, TRouterContext>);
248
+ reset: () => void;
209
249
  mount: () => () => void;
210
- onFocus: () => void;
211
- update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
212
- buildNext: (opts: BuildNextOptions) => Location;
250
+ update: <TRouteConfig_1 extends RouteConfig<string, string, string, string, AnyLoaderData, AnyLoaderData, {}, AnyLoaderData, {}, {}, {}, {}, {}, {}, unknown> = RouteConfig<string, string, string, string, AnyLoaderData, AnyLoaderData, {}, AnyLoaderData, {}, {}, {}, {}, {}, {}, unknown>, TAllRouteInfo_1 extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig_1>, TRouterContext_1 = unknown>(opts?: RouterOptions<TRouteConfig_1, TRouterContext_1> | undefined) => Router<TRouteConfig_1, TAllRouteInfo_1, TRouterContext_1>;
251
+ buildNext: (opts: BuildNextOptions) => ParsedLocation<{}, LocationState>;
213
252
  cancelMatches: () => void;
214
- loadLocation: (next?: Location) => Promise<void>;
215
- matchCache: Record<string, MatchCacheEntry>;
253
+ load: (next?: ParsedLocation) => Promise<void>;
216
254
  cleanMatchCache: () => void;
217
- getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
218
- loadRoute: (navigateOpts: BuildNextOptions) => Promise<RouteMatch[]>;
219
- preloadRoute: (navigateOpts: BuildNextOptions, loaderOpts: {
255
+ getRoute: <TId extends keyof TAllRouteInfo["routeInfoById"]>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo["routeInfoById"][TId], unknown>;
256
+ loadRoute: (navigateOpts?: BuildNextOptions) => Promise<RouteMatch[]>;
257
+ preloadRoute: (navigateOpts: BuildNextOptions | undefined, loaderOpts: {
220
258
  maxAge?: number;
221
259
  gcMaxAge?: number;
222
- }) => Promise<RouteMatch[]>;
260
+ }) => Promise<RouteMatch<DefaultAllRouteInfo, RouteInfo<string, string, string, "/", {}, {}, {}, {}, {}, {}, {}, {}, {}, {}>>[]>;
223
261
  matchRoutes: (pathname: string, opts?: {
224
262
  strictParseParams?: boolean;
225
- }) => RouteMatch[];
263
+ }) => RouteMatch<DefaultAllRouteInfo, RouteInfo<string, string, string, "/", {}, {}, {}, {}, {}, {}, {}, {}, {}, {}>>[];
226
264
  loadMatches: (resolvedMatches: RouteMatch[], loaderOpts?: {
227
- withPending?: boolean;
228
- } & ({
229
265
  preload: true;
230
266
  maxAge: number;
231
267
  gcMaxAge: number;
@@ -233,71 +269,59 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
233
269
  preload?: false;
234
270
  maxAge?: never;
235
271
  gcMaxAge?: never;
236
- })) => Promise<void>;
237
- invalidateRoute: (opts: MatchLocation) => void;
238
- reload: () => Promise<void>;
272
+ }) => Promise<void>;
273
+ loadMatchData: (routeMatch: RouteMatch<any, any>) => Promise<Record<string, unknown>>;
274
+ invalidateRoute: (opts: MatchLocation) => Promise<void>;
275
+ reload: () => void;
239
276
  resolvePath: (from: string, path: string) => string;
240
- navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
241
- matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
242
- buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
243
- __: {
244
- buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
245
- parseLocation: (location: History['location'], previousLocation?: Location) => Location;
246
- buildLocation: (dest: BuildNextOptions) => Location;
247
- commitLocation: (next: Location, replace?: boolean) => Promise<void>;
248
- navigate: (location: BuildNextOptions & {
249
- replace?: boolean;
250
- }) => Promise<void>;
251
- };
277
+ navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">({ from, to, search, hash, replace, params, }: NavigateOptions<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
278
+ matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">(location: ToOptions<TAllRouteInfo, TFrom, TTo, ResolveRelativePath<TFrom, NoInfer<TTo>>>, opts?: MatchRouteOptions) => false | TAllRouteInfo["routeInfoById"][ResolveRelativePath<TFrom, NoInfer<TTo>>]["allParams"];
279
+ buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = "/", TTo extends string = ".">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadMaxAge: userPreloadMaxAge, preloadGcMaxAge: userPreloadGcMaxAge, preloadDelay: userPreloadDelay, disabled, }: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
280
+ dehydrate: () => DehydratedRouter<TRouterContext>;
281
+ hydrate: (dehydratedRouter: DehydratedRouter<TRouterContext>) => void;
282
+ getLoader: <TFrom extends keyof TAllRouteInfo["routeInfoById"] = "/">(opts: {
283
+ from: TFrom;
284
+ }) => unknown extends TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"] ? Loader<LoaderContext<TAllRouteInfo["routeInfoById"][TFrom]["fullSearchSchema"], TAllRouteInfo["routeInfoById"][TFrom]["allParams"]>, TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"], AnyLoaderData> | undefined : Loader<TAllRouteInfo["routeInfoById"][TFrom]["fullSearchSchema"], TAllRouteInfo["routeInfoById"][TFrom]["allParams"], TAllRouteInfo["routeInfoById"][TFrom]["routeLoaderData"]>;
252
285
  }
253
- declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
254
286
 
255
- interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
256
- matchId: string;
257
- pathname: string;
258
- params: TRouteInfo['params'];
259
- parentMatch?: RouteMatch;
260
- childMatches: RouteMatch[];
287
+ interface RouteMatchStore<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
261
288
  routeSearch: TRouteInfo['searchSchema'];
262
- search: TRouteInfo['fullSearchSchema'];
289
+ search: Expand<TAllRouteInfo['fullSearchSchema'] & TRouteInfo['fullSearchSchema']>;
263
290
  status: 'idle' | 'loading' | 'success' | 'error';
264
291
  updatedAt?: number;
265
292
  error?: unknown;
266
- isInvalid: boolean;
267
- getIsInvalid: () => boolean;
293
+ invalid: boolean;
268
294
  loaderData: TRouteInfo['loaderData'];
269
295
  routeLoaderData: TRouteInfo['routeLoaderData'];
270
296
  isFetching: boolean;
271
- isPending: boolean;
272
297
  invalidAt: number;
273
- __: {
274
- element?: GetFrameworkGeneric<'Element'>;
275
- errorElement?: GetFrameworkGeneric<'Element'>;
276
- catchElement?: GetFrameworkGeneric<'Element'>;
277
- pendingElement?: GetFrameworkGeneric<'Element'>;
278
- loadPromise?: Promise<void>;
279
- loaderPromise?: Promise<void>;
280
- elementsPromise?: Promise<void>;
281
- dataPromise?: Promise<void>;
282
- pendingTimeout?: Timeout;
283
- pendingMinTimeout?: Timeout;
284
- pendingMinPromise?: Promise<void>;
285
- onExit?: void | ((matchContext: {
286
- params: TRouteInfo['allParams'];
287
- search: TRouteInfo['fullSearchSchema'];
288
- }) => void);
289
- abortController: AbortController;
290
- latestId: string;
291
- validate: () => void;
292
- startPending: () => void;
293
- cancelPending: () => void;
294
- notify: () => void;
295
- resolve: () => void;
296
- };
298
+ }
299
+ declare class RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
300
+ #private;
301
+ route: Route<TAllRouteInfo, TRouteInfo>;
302
+ router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
303
+ store: Store<RouteMatchStore<TAllRouteInfo, TRouteInfo>>;
304
+ id: string;
305
+ pathname: string;
306
+ params: TRouteInfo['allParams'];
307
+ component: GetFrameworkGeneric<'Component'>;
308
+ errorComponent: GetFrameworkGeneric<'ErrorComponent'>;
309
+ pendingComponent: GetFrameworkGeneric<'Component'>;
310
+ abortController: AbortController;
311
+ onLoaderDataListeners: Set<() => void>;
312
+ parentMatch?: RouteMatch;
313
+ __loadPromise?: Promise<void>;
314
+ __onExit?: void | ((matchContext: {
315
+ params: TRouteInfo['allParams'];
316
+ search: TRouteInfo['fullSearchSchema'];
317
+ }) => void);
318
+ constructor(router: AnyRouter, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
319
+ matchId: string;
320
+ params: TRouteInfo['allParams'];
321
+ pathname: string;
322
+ });
297
323
  cancel: () => void;
298
324
  load: (loaderOpts?: {
299
- withPending?: boolean;
300
- } & ({
301
325
  preload: true;
302
326
  maxAge: number;
303
327
  gcMaxAge: number;
@@ -305,129 +329,45 @@ interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo
305
329
  preload?: false;
306
330
  maxAge?: never;
307
331
  gcMaxAge?: never;
308
- })) => Promise<TRouteInfo['routeLoaderData']>;
332
+ }) => Promise<void>;
309
333
  fetch: (opts?: {
310
334
  maxAge?: number;
311
335
  }) => Promise<TRouteInfo['routeLoaderData']>;
312
- invalidate: () => void;
313
- hasLoaders: () => boolean;
314
- }
315
- declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
316
- matchId: string;
317
- params: TRouteInfo['allParams'];
318
- pathname: string;
319
- }): RouteMatch<TAllRouteInfo, TRouteInfo>;
320
-
321
- interface AnyRoute extends Route<any, any> {
322
- }
323
- interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
324
- routeId: TRouteInfo['id'];
325
- routeRouteId: TRouteInfo['routeId'];
326
- routePath: TRouteInfo['path'];
327
- fullPath: TRouteInfo['fullPath'];
328
- parentRoute?: AnyRoute;
329
- childRoutes?: AnyRoute[];
330
- options: RouteOptions;
331
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
332
- buildLink: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => LinkInfo;
333
- matchRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>>(matchLocation: CheckRelativePath<TAllRouteInfo, TRouteInfo['fullPath'], NoInfer<TTo>> & Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>, opts?: MatchRouteOptions) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams'];
334
- navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>) => Promise<void>;
335
- action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
336
- loader: unknown extends TRouteInfo['routeLoaderData'] ? Action<LoaderContext<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams']>, TRouteInfo['routeLoaderData']> | undefined : Loader<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams'], TRouteInfo['routeLoaderData']>;
337
- }
338
- 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>;
339
- declare function cascadeLoaderData(matches: RouteMatch<any, any>[]): void;
340
-
341
- interface AnyAllRouteInfo {
342
- routeConfig: AnyRouteConfig;
343
- routeInfo: AnyRouteInfo;
344
- routeInfoById: Record<string, AnyRouteInfo>;
345
- routeInfoByFullPath: Record<string, AnyRouteInfo>;
346
- routeIds: any;
347
- routePaths: any;
348
- }
349
- interface DefaultAllRouteInfo {
350
- routeConfig: RouteConfig;
351
- routeInfo: RouteInfo;
352
- routeInfoById: Record<string, RouteInfo>;
353
- routeInfoByFullPath: Record<string, RouteInfo>;
354
- routeIds: string;
355
- routePaths: string;
356
- }
357
- interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
358
- }
359
- declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
360
- declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
361
- [TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
362
- }> : never : never;
363
- declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
364
- id: TId;
365
- } extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
366
- declare type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TRouteId, 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 TRouteId ? never : RouteInfo<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
367
- interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
368
- [TInfo in TRouteInfo as TInfo['id']]: TInfo;
369
- }, TRouteInfoByFullPath = {
370
- [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
371
- }> {
372
- routeConfig: TRouteConfig;
373
- routeInfo: TRouteInfo;
374
- routeInfoById: TRouteInfoById;
375
- routeInfoByFullPath: TRouteInfoByFullPath;
376
- routeIds: keyof TRouteInfoById;
377
- routePaths: keyof TRouteInfoByFullPath;
378
- }
379
- interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
380
- }
381
- interface RouteInfo<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = 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 = {}> {
382
- id: TId;
383
- routeId: TRouteId;
384
- path: TPath;
385
- fullPath: TFullPath;
386
- routeLoaderData: TRouteLoaderData;
387
- loaderData: TLoaderData;
388
- actionPayload: TActionPayload;
389
- actionResponse: TActionResponse;
390
- searchSchema: TSearchSchema;
391
- fullSearchSchema: TFullSearchSchema;
392
- parentParams: TParentParams;
393
- params: TParams;
394
- allParams: TAllParams;
395
- options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
336
+ invalidate: () => Promise<void>;
337
+ __hasLoaders: () => boolean;
338
+ getIsInvalid: () => boolean;
339
+ __setParentMatch: (parentMatch?: RouteMatch) => void;
340
+ __onLoaderData: (listener: () => void) => void;
341
+ __validate: () => void;
396
342
  }
397
- declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
398
- [K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
399
- };
400
- declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
401
- declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
402
343
 
403
344
  declare const rootRouteId: "__root__";
404
- declare type RootRouteId = typeof rootRouteId;
405
- declare type AnyLoaderData = {};
406
- declare type AnyPathParams = {};
407
- declare type AnySearchSchema = {};
345
+ type RootRouteId = typeof rootRouteId;
346
+ type AnyLoaderData = {};
347
+ type AnyPathParams = {};
348
+ type AnySearchSchema = {};
408
349
  interface RouteMeta {
409
350
  }
410
- declare type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
411
- declare type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
351
+ type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
352
+ type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
412
353
  parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
413
354
  };
414
- declare type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
355
+ type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
415
356
  error: 'Top level search params cannot be redefined by child routes!';
416
357
  keys: keyof TReturn & keyof TParentSchema;
417
358
  } : TReturn;
418
- declare type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
419
- declare type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
359
+ type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
360
+ type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
420
361
  [Key in keyof TParentParams]?: DefinedPathParamWarning;
421
362
  };
422
- declare type LoaderFn<TRouteLoaderData extends AnyLoaderData, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TFullSearchSchema, TAllParams>) => Promise<TRouteLoaderData>;
363
+ type LoaderFn<TRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TFullSearchSchema, TAllParams>) => TRouteLoaderData | Promise<TRouteLoaderData>;
423
364
  interface LoaderContext<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
424
365
  params: TAllParams;
425
366
  search: TFullSearchSchema;
426
367
  signal?: AbortSignal;
427
368
  }
428
- declare type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
429
- declare type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
430
- declare type RouteOptions<TRouteId extends string = string, 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 = {}> = ({
369
+ type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
370
+ type RouteOptions<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, 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 = {}> = ({
431
371
  path: TPath;
432
372
  } | {
433
373
  id: TRouteId;
@@ -436,18 +376,18 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
436
376
  validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
437
377
  preSearchFilters?: SearchFilter<TFullSearchSchema>[];
438
378
  postSearchFilters?: SearchFilter<TFullSearchSchema>[];
439
- pendingMs?: number;
440
- pendingMinMs?: number;
441
- element?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
442
- errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
443
- catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
444
- pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
379
+ component?: GetFrameworkGeneric<'Component'>;
380
+ errorComponent?: GetFrameworkGeneric<'ErrorComponent'>;
381
+ pendingComponent?: GetFrameworkGeneric<'Component'>;
445
382
  loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
446
383
  loaderMaxAge?: number;
447
384
  loaderGcMaxAge?: number;
448
- action?: ActionFn<TActionPayload, TActionResponse>;
449
- useErrorBoundary?: boolean;
450
- onMatch?: (matchContext: {
385
+ beforeLoad?: (opts: {
386
+ router: AnyRouter;
387
+ match: RouteMatch;
388
+ }) => Promise<void> | void;
389
+ onLoadError?: (err: any) => void;
390
+ onLoaded?: (matchContext: {
451
391
  params: TAllParams;
452
392
  search: TFullSearchSchema;
453
393
  }) => void | undefined | ((match: {
@@ -466,44 +406,130 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
466
406
  parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
467
407
  stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
468
408
  }) & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
469
- declare type SearchFilter<T, U = T> = (prev: T) => U;
470
- interface RouteConfig<TId extends string = string, TRouteId 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> {
409
+ type SearchFilter<T, U = T> = (prev: T) => U;
410
+ 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, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = AnyLoaderData, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends AnyPathParams = {}, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
471
411
  id: TId;
472
412
  routeId: TRouteId;
473
413
  path: NoInfer<TPath>;
474
414
  fullPath: TFullPath;
475
- options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
415
+ options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
476
416
  children?: TKnownChildren;
477
417
  addChildren: IsAny<TId, any, <TNewChildren extends any>(children: TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
478
418
  error: 'Invalid route detected';
479
419
  route: TNewChildren;
480
- }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
481
- createChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
482
- error: 'Invalid route detected';
483
- route: TNewChildren;
484
- }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
485
- createRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>;
420
+ }) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
421
+ createRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>;
422
+ generate: GenerateFn<TRouteId, TPath, TParentRouteLoaderData, TParentLoaderData, TParentSearchSchema, TParentParams>;
486
423
  }
487
- declare type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentAllLoaderData 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, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
424
+ type GenerateFn<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData, TParentLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends {} = {}, TParentParams extends AnyPathParams = {}> = <TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TSearchSchema extends 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>>(options: Omit<RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'>) => void;
425
+ 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, 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, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
488
426
  path?: never;
489
- } : RouteOptions<TRouteId, 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, parentPath?: string) => RouteConfig<RoutePrefix<TParentId, TResolvedId>, TResolvedId, TPath, string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
490
- declare type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
491
- declare type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
427
+ } : RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, 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, TParentLoaderData, Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
428
+ type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
429
+ type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
492
430
  interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
493
431
  }
494
432
  interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
495
433
  }
496
- declare type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
497
- declare type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
498
- declare type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
434
+ type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
435
+ type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
436
+ type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
499
437
  declare const createRouteConfig: CreateRouteConfigFn<true>;
500
438
 
501
- declare type LinkInfo = {
439
+ interface AnyRoute extends Route<any, any, any> {
440
+ }
441
+ declare class Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo, TRouterContext = unknown> {
442
+ routeInfo: TRouteInfo;
443
+ id: TRouteInfo['id'];
444
+ customId: TRouteInfo['customId'];
445
+ path: TRouteInfo['path'];
446
+ fullPath: TRouteInfo['fullPath'];
447
+ getParentRoute: () => undefined | AnyRoute;
448
+ childRoutes?: AnyRoute[];
449
+ options: RouteOptions;
450
+ originalIndex: number;
451
+ getRouter: () => Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>;
452
+ constructor(routeConfig: RouteConfig, options: TRouteInfo['options'], originalIndex: number, parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>);
453
+ }
454
+
455
+ interface AnyAllRouteInfo {
456
+ routeConfig: AnyRouteConfig;
457
+ routeInfo: AnyRouteInfo;
458
+ routeInfoById: Record<string, AnyRouteInfo>;
459
+ routeInfoByFullPath: Record<string, AnyRouteInfo>;
460
+ routeIds: any;
461
+ routePaths: any;
462
+ fullSearchSchema: Record<string, any>;
463
+ allParams: Record<string, any>;
464
+ }
465
+ interface DefaultAllRouteInfo {
466
+ routeConfig: RouteConfig;
467
+ routeInfo: RouteInfo;
468
+ routeInfoById: Record<string, RouteInfo>;
469
+ routeInfoByFullPath: Record<string, RouteInfo>;
470
+ routeIds: string;
471
+ routePaths: string;
472
+ fullSearchSchema: AnySearchSchema;
473
+ allParams: AnyPathParams;
474
+ }
475
+ interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
476
+ }
477
+ type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
478
+ type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
479
+ [TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
480
+ }> : never : never;
481
+ type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
482
+ id: TId;
483
+ } extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
484
+ type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TCustomId, infer TPath, infer TFullPath, infer TParentRouteLoaderData, infer TRouteLoaderData, infer TParentLoaderData, infer TLoaderData, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TCustomId ? never : RouteInfo<TId, TCustomId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
485
+ interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
486
+ '/': TRouteInfo;
487
+ } & {
488
+ [TInfo in TRouteInfo as TInfo['id']]: TInfo;
489
+ }, TRouteInfoByFullPath = {
490
+ '/': TRouteInfo;
491
+ } & {
492
+ [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
493
+ }> {
494
+ routeConfig: TRouteConfig;
495
+ routeInfo: TRouteInfo;
496
+ routeInfoById: TRouteInfoById;
497
+ routeInfoByFullPath: TRouteInfoByFullPath;
498
+ routeIds: keyof TRouteInfoById;
499
+ routePaths: keyof TRouteInfoByFullPath;
500
+ fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>;
501
+ allParams: Partial<UnionToIntersection<TRouteInfo['allParams']>>;
502
+ }
503
+ interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
504
+ }
505
+ interface RouteInfo<TId extends string = string, TCustomId extends string = string, TPath extends string = string, TFullPath extends string = '/', TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends AnyPathParams = {}, TAllParams extends AnyPathParams = {}> {
506
+ id: TId;
507
+ customId: TCustomId;
508
+ path: TPath;
509
+ fullPath: TFullPath;
510
+ parentRouteLoaderData: TParentRouteLoaderData;
511
+ routeLoaderData: TRouteLoaderData;
512
+ parentLoaderData: TParentLoaderData;
513
+ loaderData: TLoaderData;
514
+ searchSchema: TSearchSchema;
515
+ fullSearchSchema: TFullSearchSchema;
516
+ parentParams: TParentParams;
517
+ params: TParams;
518
+ allParams: TAllParams;
519
+ options: RouteOptions<TCustomId, TPath, TParentRouteLoaderData, TRouteLoaderData, TParentLoaderData, TLoaderData, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
520
+ }
521
+ type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
522
+ [K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
523
+ };
524
+ type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
525
+ type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
526
+
527
+ type LinkInfo = {
502
528
  type: 'external';
503
529
  href: string;
504
530
  } | {
505
531
  type: 'internal';
506
- next: Location;
532
+ next: ParsedLocation;
507
533
  handleFocus: (e: any) => void;
508
534
  handleClick: (e: any) => void;
509
535
  handleEnter: (e: any) => void;
@@ -511,12 +537,11 @@ declare type LinkInfo = {
511
537
  isActive: boolean;
512
538
  disabled?: boolean;
513
539
  };
514
- declare type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
515
- 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;
516
- declare 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;
517
- declare type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
518
- 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;
519
- declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
540
+ 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;
541
+ 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;
542
+ type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `$${infer V}` ? V : never : never;
543
+ 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;
544
+ type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
520
545
  ...Split<ResolveRelativePath<TFrom, TTo>, false>,
521
546
  ...infer TToRest
522
547
  ] ? `${CleanPath<Join<[
@@ -526,40 +551,39 @@ declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends s
526
551
  ...Split<TFrom, false>,
527
552
  ...Split<RestTTo, false>,
528
553
  ...infer RestPath
529
- ] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
530
- declare type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
554
+ ] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
555
+ length: 0;
556
+ } ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
557
+ type NavigateOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
531
558
  replace?: boolean;
532
559
  };
533
- declare type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
560
+ type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
534
561
  to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
535
562
  hash?: Updater<string>;
563
+ state?: LocationState;
536
564
  from?: TFrom;
537
565
  } & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>, {}> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
538
- declare type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
539
- search?: SearchReducer<TFromSchema, TToSchema>;
540
- } : keyof PickRequired<TToSchema> extends never ? {
541
- search?: SearchReducer<TFromSchema, TToSchema>;
566
+ type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & RouteInfoByPath<TAllRouteInfo, TFrom> extends never ? {} : RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']>>, TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']> & Omit<RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'], keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']>>, TFromFullSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TFromSchema>>, TToFullSchema = Expand<UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TToSchema>>> = keyof PickRequired<TToSchema> extends never ? {
567
+ search?: true | SearchReducer<TFromFullSchema, TToFullSchema>;
542
568
  } : {
543
- search: SearchReducer<TFromSchema, TToSchema>;
569
+ search: SearchReducer<TFromFullSchema, TToFullSchema>;
544
570
  };
545
- declare type SearchReducer<TFrom, TTo> = {
571
+ type SearchReducer<TFrom, TTo> = {
546
572
  [TKey in keyof TTo]: TTo[TKey];
547
573
  } | ((current: TFrom) => TTo);
548
- declare type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
549
- params?: ParamsReducer<TFromParams, TToParams>;
550
- } : AnyPathParams extends TToParams ? {
551
- params?: ParamsReducer<TFromParams, Record<string, never>>;
574
+ type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = Expand<UnionToIntersection<RouteInfoByPath<TAllRouteInfo, TFrom> extends never ? {} : RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>>, TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']> & Omit<RouteInfoByPath<TAllRouteInfo, TTo>['allParams'], keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>>, TFromFullParams = Expand<UnionToIntersection<TAllRouteInfo['allParams'] & TFromSchema>>, TToFullParams = Expand<UnionToIntersection<TAllRouteInfo['allParams'] & TToSchema>>> = keyof PickRequired<TToSchema> extends never ? {
575
+ params?: ParamsReducer<TFromFullParams, TToFullParams>;
552
576
  } : {
553
- params: ParamsReducer<TFromParams, TToParams>;
577
+ params: ParamsReducer<TFromFullParams, TToFullParams>;
554
578
  };
555
- declare type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
556
- declare 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>;
557
- declare 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>;
579
+ type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
580
+ type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routePaths'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
581
+ type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeIds'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
558
582
  interface ActiveOptions {
559
583
  exact?: boolean;
560
584
  includeHash?: boolean;
561
585
  }
562
- declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
586
+ type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends TAllRouteInfo['routePaths'] = '/', TTo extends string = '.'> = NavigateOptions<TAllRouteInfo, TFrom, TTo> & {
563
587
  target?: HTMLAnchorElement['target'];
564
588
  activeOptions?: ActiveOptions;
565
589
  preload?: false | 'intent';
@@ -568,22 +592,22 @@ declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
568
592
  preloadDelay?: number;
569
593
  disabled?: boolean;
570
594
  };
571
- declare type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
595
+ type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
572
596
  Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
573
597
  'Valid Route Paths': TAllRouteInfo['routePaths'];
574
598
  } : {} : {};
575
- declare type CheckPath<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routePaths']> extends never ? TPass : CheckPathError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routePaths']>>;
576
- declare type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
599
+ type CheckPath<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routePaths']> extends never ? TPass : CheckPathError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routePaths']>>;
600
+ type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
577
601
  Error: `${TInvalids extends string ? TInvalids : never} is not a valid route path.`;
578
602
  'Valid Route Paths': TAllRouteInfo['routePaths'];
579
603
  }>;
580
- declare type CheckId<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routeIds']> extends never ? TPass : CheckIdError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routeIds']>>;
581
- declare type CheckIdError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
604
+ type CheckId<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routeIds']> extends never ? TPass : CheckIdError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routeIds']>>;
605
+ type CheckIdError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
582
606
  Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
583
607
  'Valid Route IDs': TAllRouteInfo['routeIds'];
584
608
  }>;
585
- declare 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;
586
- declare type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
609
+ 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;
610
+ type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
587
611
 
588
612
  interface Segment {
589
613
  type: 'pathname' | 'param' | 'wildcard';
@@ -597,8 +621,8 @@ declare function trimPath(path: string): string;
597
621
  declare function resolvePath(basepath: string, base: string, to: string): string;
598
622
  declare function parsePathname(pathname?: string): Segment[];
599
623
  declare function interpolatePath(path: string | undefined, params: any, leaveWildcard?: boolean): string;
600
- declare function matchPathname(currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
601
- declare function matchByPath(from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
624
+ declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
625
+ declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
602
626
 
603
627
  declare function encode(obj: any, pfx?: string): string;
604
628
  declare function decode(str: any): {};
@@ -608,4 +632,48 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
608
632
  declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
609
633
  declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
610
634
 
611
- export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, cascadeLoaderData, cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
635
+ /**
636
+ * This function returns `a` if `b` is deeply equal.
637
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
638
+ * This can be used for structural sharing between immutable JSON values for example.
639
+ * Do not use this with signals
640
+ */
641
+ declare function replaceEqualDeep<T>(prev: any, _next: T): T;
642
+ declare function trackDeep<T>(obj: T): T;
643
+
644
+ interface ActionOptions<TKey extends string = string, TPayload = unknown, TResponse = unknown, TError = Error> {
645
+ key?: TKey;
646
+ action: (payload: TPayload) => TResponse | Promise<TResponse>;
647
+ onLatestSuccess?: ActionCallback<TPayload, TResponse, TError>;
648
+ onEachSuccess?: ActionCallback<TPayload, TResponse, TError>;
649
+ onLatestError?: ActionCallback<TPayload, TResponse, TError>;
650
+ onEachError?: ActionCallback<TPayload, TResponse, TError>;
651
+ onLatestSettled?: ActionCallback<TPayload, TResponse, TError>;
652
+ onEachSettled?: ActionCallback<TPayload, TResponse, TError>;
653
+ maxSubmissions?: number;
654
+ debug?: boolean;
655
+ }
656
+ type ActionCallback<TPayload, TResponse, TError> = (submission: ActionSubmission<TPayload, TResponse, TError>) => void | Promise<void>;
657
+ interface Action<TKey extends string = string, TPayload = unknown, TResponse = unknown, TError = Error> {
658
+ options: ActionOptions<TKey, TPayload, TResponse, TError>;
659
+ submit: (payload?: TPayload) => Promise<TResponse>;
660
+ reset: () => void;
661
+ store: Store<ActionStore<TPayload, TResponse, TError>>;
662
+ }
663
+ interface ActionStore<TPayload = unknown, TResponse = unknown, TError = Error> {
664
+ submissions: ActionSubmission<TPayload, TResponse, TError>[];
665
+ }
666
+ type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
667
+ interface ActionSubmission<TPayload = unknown, TResponse = unknown, TError = Error> {
668
+ submittedAt: number;
669
+ status: 'idle' | 'pending' | 'success' | 'error';
670
+ payload: TPayload;
671
+ response?: TResponse;
672
+ error?: TError;
673
+ isInvalid?: boolean;
674
+ invalidate: () => void;
675
+ getIsLatest: () => boolean;
676
+ }
677
+ declare function createAction<TKey extends string, TPayload, TResponse, TError>(options: ActionOptions<TKey, TPayload, TResponse, TError>): Action<TKey, TPayload, TResponse, TError>;
678
+
679
+ export { Action, ActionFn, ActionOptions, ActionStore, ActionSubmission, ActiveOptions, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnyRouter, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, LocationState, MatchCache, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptions, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, ParsedLocation, ParsedPath, PathParamMask, PathParamOptions, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RegisterRouter, RegisteredAllRouteInfo, RegisteredRouter, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMatchStore, RouteMeta, RouteOptions, Router, RouterContext, RouterHistory, RouterLocation, RouterOptions, RouterStore, RoutesById, RoutesInfoInner, SearchFilter, SearchParamOptions, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Store, Timeout, ToIdOption, ToOptions, ToPathOption, UnionToIntersection, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, batch, cleanPath, createAction, createBrowserHistory, createHashHistory, createMemoryHistory, createRouteConfig, createStore, decode, defaultFetchServerDataFn, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trackDeep, trimPath, trimPathLeft, trimPathRight, warning };