@tanstack/react-router 0.0.1-beta.213 → 0.0.1-beta.215

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.
@@ -24,8 +24,11 @@ export type MakeMatchRouteOptions<TRouteTree extends AnyRoute = RegisteredRouter
24
24
  export declare function MatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): any;
25
25
  export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatchState = RouteMatch<TRouteTree, TFrom>, TSelected = TRouteMatchState>(opts: StrictOrFrom<TFrom> & {
26
26
  select?: (match: TRouteMatchState) => TSelected;
27
- }): TStrict extends true ? TRouteMatchState : TRouteMatchState | undefined;
27
+ }): TStrict extends true ? TSelected : TSelected | undefined;
28
28
  export declare const matchesContext: React.Context<RouteMatch<AnyRoute, any>[]>;
29
29
  export declare function useMatches<T = RouteMatch[]>(opts?: {
30
30
  select?: (matches: RouteMatch[]) => T;
31
31
  }): T;
32
+ export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = TRouteMatch['loaderData']>(opts: StrictOrFrom<TFrom> & {
33
+ select?: (match: TRouteMatch) => TSelected;
34
+ }): TStrict extends true ? TSelected : TSelected | undefined;
@@ -19,7 +19,7 @@ export interface MatchLocation {
19
19
  from?: string;
20
20
  }
21
21
  export type BuildLinkFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''>(dest: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
22
- export type NavigateFn<TRouteTree extends AnyRoute> = <TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>({ from, to, ...rest }: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
22
+ export type NavigateFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
23
23
  export type MatchRouteFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
24
24
  export type LoadFn = (opts?: {
25
25
  next?: ParsedLocation;
@@ -70,6 +70,7 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
70
70
  searchError: unknown;
71
71
  updatedAt: number;
72
72
  loadPromise?: Promise<void>;
73
+ loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData'];
73
74
  __resolveLoadPromise?: () => void;
74
75
  context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
75
76
  routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
@@ -12,12 +12,12 @@ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends strin
12
12
  export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
13
13
  path: TFilePath;
14
14
  constructor(path: TFilePath);
15
- createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = Expand<Assign<import("./route").InferFullSearchSchema<TParentRoute>, TSearchSchema>>, TParams extends Record<string, any> = (TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never) extends never ? AnyPathParams : Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never, string>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext>, "path" | "id" | "getParentRoute"> & {
15
+ createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = Expand<Assign<import("./route").InferFullSearchSchema<TParentRoute>, TSearchSchema>>, TParams extends Record<string, any> = (TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never) extends never ? AnyPathParams : Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never, string>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TLoaderData>, "path" | "id" | "getParentRoute"> & {
16
16
  meta?: import("./route").RouteMeta | undefined;
17
17
  } & {
18
18
  caseSensitive?: boolean | undefined;
19
19
  wrapInSuspense?: boolean | undefined;
20
- component?: import("./route").RouteComponent<TFullSearchSchema, TAllParams, TContext> | undefined;
20
+ component?: import("./route").RouteComponent<TFullSearchSchema, TAllParams, TContext, TLoaderData> | undefined;
21
21
  errorComponent?: import("./route").ErrorRouteComponent<TFullSearchSchema, TAllParams, {}> | undefined;
22
22
  pendingComponent?: import("./route").PendingRouteComponent<TFullSearchSchema, TAllParams, TContext> | undefined;
23
23
  preSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
@@ -27,6 +27,6 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
27
27
  onTransition?: ((match: import("./RouterProvider").AnyRouteMatch) => void) | undefined;
28
28
  onLeave?: ((match: import("./RouterProvider").AnyRouteMatch) => void) | undefined;
29
29
  reloadOnWindowFocus?: boolean | undefined;
30
- }) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TChildren, TRouteTree>;
30
+ }) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
31
31
  }
32
32
  export {};
@@ -29,9 +29,9 @@ export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
29
29
  } : {
30
30
  meta: RouteMeta;
31
31
  };
32
- export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams, TAllContext>>;
32
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData> & NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>>;
33
33
  export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
34
- export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
34
+ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
35
35
  getParentRoute: () => TParentRoute;
36
36
  validateSearch?: SearchSchemaValidator<TSearchSchema>;
37
37
  } & (keyof PickRequired<RouteContext> extends never ? {
@@ -39,7 +39,7 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
39
39
  } : {
40
40
  beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
41
41
  }) & {
42
- load?: RouteLoadFn<TAllParams, TFullSearchSchema, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
42
+ loader?: RouteLoadFn<TAllParams, TFullSearchSchema, NoInfer<TAllContext>, NoInfer<TRouteContext>, TLoaderData>;
43
43
  } & ({
44
44
  parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
45
45
  stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
@@ -57,10 +57,10 @@ type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute ex
57
57
  navigate: NavigateFn<AnyRoute>;
58
58
  buildLocation: BuildLocationFn<AnyRoute>;
59
59
  }) => Promise<TRouteContext> | TRouteContext | void;
60
- export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext> = MetaOptions & {
60
+ export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext, TLoaderData extends any = unknown> = MetaOptions & {
61
61
  caseSensitive?: boolean;
62
62
  wrapInSuspense?: boolean;
63
- component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
63
+ component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>;
64
64
  errorComponent?: ErrorRouteComponent<TFullSearchSchema, TAllParams, {}>;
65
65
  pendingComponent?: PendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
66
66
  preSearchFilters?: SearchFilter<TFullSearchSchema>[];
@@ -85,10 +85,10 @@ export type DefinedPathParamWarning = 'Path params cannot be redefined by child
85
85
  export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
86
86
  [Key in keyof TParentParams]?: DefinedPathParamWarning;
87
87
  };
88
- export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> = (match: LoadFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext> & {
88
+ export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = (match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext> & {
89
89
  parentMatchPromise?: Promise<void>;
90
- }) => any;
91
- export interface LoadFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
90
+ }) => Promise<TLoaderData> | TLoaderData;
91
+ export interface LoaderFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
92
92
  abortController: AbortController;
93
93
  preload: boolean;
94
94
  params: TAllParams;
@@ -134,9 +134,9 @@ export type RouteConstraints = {
134
134
  TChildren: unknown;
135
135
  TRouteTree: AnyRoute;
136
136
  };
137
- export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
137
+ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
138
138
  isRoot: TParentRoute extends Route<any> ? true : false;
139
- options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>;
139
+ options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData>;
140
140
  test: Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>;
141
141
  parentRoute: TParentRoute;
142
142
  id: TId;
@@ -147,7 +147,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
147
147
  originalIndex?: number;
148
148
  router?: AnyRouter;
149
149
  rank: number;
150
- constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>);
150
+ constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData>);
151
151
  types: {
152
152
  parentRoute: TParentRoute;
153
153
  path: TPath;
@@ -164,12 +164,13 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
164
164
  children: TChildren;
165
165
  routeTree: TRouteTree;
166
166
  routerContext: TRouterContext;
167
+ loaderData: TLoaderData;
167
168
  };
168
169
  init: (opts: {
169
170
  originalIndex: number;
170
171
  }) => void;
171
- addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
172
- update: (options: UpdatableRouteOptions<TFullSearchSchema, TAllParams, Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>>) => this;
172
+ addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree, AnyRoute>;
173
+ update: (options: UpdatableRouteOptions<TFullSearchSchema, TAllParams, Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TLoaderData>) => this;
173
174
  static __onInit: (route: any) => void;
174
175
  useMatch: <TSelected = TAllContext>(opts?: {
175
176
  select?: ((search: TAllContext) => TSelected) | undefined;
@@ -183,10 +184,13 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
183
184
  useParams: <TSelected = TAllParams>(opts?: {
184
185
  select?: ((search: TAllParams) => TSelected) | undefined;
185
186
  } | undefined) => TSelected;
187
+ useLoaderData: <TSelected = TLoaderData>(opts?: {
188
+ select?: ((search: TLoaderData) => TSelected) | undefined;
189
+ } | undefined) => TSelected;
186
190
  }
187
191
  export type AnyRootRoute = RootRoute<any, any, any>;
188
- export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteContext, TRouterContext>;
189
- export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, // TParentRoute
192
+ export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteContext, TRouterContext, unknown>;
193
+ export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
190
194
  '/', // TPath
191
195
  '/', // TFullPath
192
196
  string, // TCustomId
@@ -198,7 +202,7 @@ TSearchSchema, // TFullSearchSchema
198
202
  TRouteContext, // TRouteContext
199
203
  Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
200
204
  TRouterContext, // TRouterContext
201
- any, // TChildren
205
+ TLoaderData, any, // TChildren
202
206
  any> {
203
207
  constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
204
208
  RootRouteId, // TCustomId
@@ -208,7 +212,8 @@ any> {
208
212
  {}, // TParams
209
213
  {}, // TAllParams
210
214
  TRouteContext, // TRouteContext
211
- Assign<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
215
+ Assign<TRouterContext, TRouteContext>, // TAllContext
216
+ TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
212
217
  }
213
218
  export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
214
219
  type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
@@ -228,7 +233,7 @@ export type RouteMask<TRouteTree extends AnyRoute> = {
228
233
  export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
229
234
  routeTree: TRouteTree;
230
235
  } & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
231
- export type RouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = {
236
+ export type RouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = {
232
237
  useMatch: <TSelected = TAllContext>(opts?: {
233
238
  select?: (search: TAllContext) => TSelected;
234
239
  }) => TSelected;
@@ -241,6 +246,9 @@ export type RouteProps<TFullSearchSchema extends Record<string, any> = AnySearch
241
246
  useParams: <TSelected = TAllParams>(opts?: {
242
247
  select?: (search: TAllParams) => TSelected;
243
248
  }) => TSelected;
249
+ useLoaderData: <TSelected = TLoaderData>(opts?: {
250
+ select?: (search: TLoaderData) => TSelected;
251
+ }) => TSelected;
244
252
  };
245
253
  export type ErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = {
246
254
  error: unknown;
@@ -254,8 +262,8 @@ export type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.
254
262
  export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
255
263
  preload?: () => Promise<void>;
256
264
  };
257
- export type RouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = AsyncRouteComponent<RouteProps<TFullSearchSchema, TAllParams, TAllContext>>;
265
+ export type RouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>, TLoaderData extends any = unknown> = AsyncRouteComponent<RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>>;
258
266
  export type ErrorRouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = AsyncRouteComponent<ErrorRouteProps<TFullSearchSchema, TAllParams, TAllContext>>;
259
267
  export type PendingRouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = AsyncRouteComponent<PendingRouteProps<TFullSearchSchema, TAllParams, TAllContext>>;
260
- export type AnyRouteComponent = RouteComponent<any, any, any>;
268
+ export type AnyRouteComponent = RouteComponent<any, any, any, any>;
261
269
  export {};
@@ -17,7 +17,7 @@ declare global {
17
17
  }
18
18
  export interface Register {
19
19
  }
20
- export type AnyRouter = Router<any, any>;
20
+ export type AnyRouter = Router<AnyRoute, any>;
21
21
  export type RegisteredRouter = Register extends {
22
22
  router: infer TRouter extends AnyRouter;
23
23
  } ? TRouter : AnyRouter;
@@ -377,6 +377,7 @@
377
377
  }
378
378
  }
379
379
  componentDidCatch(error) {
380
+ console.error(error);
380
381
  this.props.onCatch?.(error);
381
382
  }
382
383
  render() {
@@ -1168,10 +1169,12 @@
1168
1169
  const latestLocationRef = React__namespace.useRef(parseLocation());
1169
1170
  const [preState, setState] = React__namespace.useState(() => getInitialRouterState(latestLocationRef.current));
1170
1171
  const [isTransitioning, startReactTransition] = React__namespace.useTransition();
1172
+ const pendingMatchesRef = React__namespace.useRef([]);
1171
1173
  const state = React__namespace.useMemo(() => ({
1172
1174
  ...preState,
1173
1175
  status: isTransitioning ? 'pending' : 'idle',
1174
- location: isTransitioning ? latestLocationRef.current : preState.location
1176
+ location: isTransitioning ? latestLocationRef.current : preState.location,
1177
+ pendingMatches: pendingMatchesRef.current
1175
1178
  }), [preState, isTransitioning]);
1176
1179
  React__namespace.useLayoutEffect(() => {
1177
1180
  if (!isTransitioning && state.resolvedLocation !== state.location) {
@@ -1181,6 +1184,7 @@
1181
1184
  toLocation: state.location,
1182
1185
  pathChanged: state.location.href !== state.resolvedLocation?.href
1183
1186
  });
1187
+ pendingMatchesRef.current = [];
1184
1188
  setState(s => ({
1185
1189
  ...s,
1186
1190
  resolvedLocation: s.location
@@ -1334,7 +1338,7 @@
1334
1338
  }
1335
1339
 
1336
1340
  // Create a fresh route match
1337
- const hasLoaders = !!(route.options.load || componentTypes.some(d => route.options[d]?.preload));
1341
+ const hasLoaders = !!(route.options.loader || componentTypes.some(d => route.options[d]?.preload));
1338
1342
  const routeMatch = {
1339
1343
  id: matchId,
1340
1344
  routeId: route.id,
@@ -1665,9 +1669,6 @@
1665
1669
  matchPromises.push((async () => {
1666
1670
  const parentMatchPromise = matchPromises[index - 1];
1667
1671
  const route = looseRoutesById[match.routeId];
1668
- if (match.isFetching) {
1669
- return getRouteMatch(state, match.id)?.loadPromise;
1670
- }
1671
1672
  const handleIfRedirect = err => {
1672
1673
  if (isRedirect(err)) {
1673
1674
  if (!preload) {
@@ -1677,73 +1678,85 @@
1677
1678
  }
1678
1679
  return false;
1679
1680
  };
1680
- const load = async () => {
1681
- try {
1682
- const componentsPromise = Promise.all(componentTypes.map(async type => {
1683
- const component = route.options[type];
1684
- if (component?.preload) {
1685
- await component.preload();
1686
- }
1687
- }));
1688
- const loaderPromise = route.options.load?.({
1689
- params: match.params,
1690
- search: match.search,
1691
- preload: !!preload,
1692
- parentMatchPromise,
1693
- abortController: match.abortController,
1694
- context: match.context,
1695
- location: state.location,
1696
- navigate: opts => navigate({
1697
- ...opts,
1698
- from: match.pathname
1699
- })
1700
- });
1701
- const [_, loaderContext] = await Promise.all([componentsPromise, loaderPromise]);
1702
- if (latestPromise = checkLatest()) return await latestPromise;
1703
- matches[index] = match = {
1704
- ...match,
1705
- error: undefined,
1706
- status: 'success',
1707
- isFetching: false,
1708
- updatedAt: Date.now()
1709
- };
1710
- } catch (error) {
1711
- if (latestPromise = checkLatest()) return await latestPromise;
1712
- if (handleIfRedirect(error)) return;
1713
- try {
1714
- route.options.onError?.(error);
1715
- } catch (onErrorError) {
1716
- error = onErrorError;
1717
- if (handleIfRedirect(onErrorError)) return;
1718
- }
1719
- matches[index] = match = {
1720
- ...match,
1721
- error,
1722
- status: 'error',
1723
- isFetching: false,
1724
- updatedAt: Date.now()
1725
- };
1726
- }
1727
- if (!preload) {
1728
- setState(s => ({
1729
- ...s,
1730
- matches: s.matches.map(d => d.id === match.id ? match : d)
1731
- }));
1732
- }
1733
- };
1734
1681
  let loadPromise;
1735
1682
  matches[index] = match = {
1736
1683
  ...match,
1737
- isFetching: true,
1738
1684
  fetchedAt: Date.now(),
1739
1685
  invalid: false
1740
1686
  };
1741
- loadPromise = load();
1687
+ if (match.isFetching) {
1688
+ loadPromise = getRouteMatch(state, match.id)?.loadPromise;
1689
+ } else {
1690
+ matches[index] = match = {
1691
+ ...match,
1692
+ isFetching: true
1693
+ };
1694
+ const componentsPromise = Promise.all(componentTypes.map(async type => {
1695
+ const component = route.options[type];
1696
+ if (component?.preload) {
1697
+ await component.preload();
1698
+ }
1699
+ }));
1700
+ const loaderPromise = route.options.loader?.({
1701
+ params: match.params,
1702
+ search: match.search,
1703
+ preload: !!preload,
1704
+ parentMatchPromise,
1705
+ abortController: match.abortController,
1706
+ context: match.context,
1707
+ location: state.location,
1708
+ navigate: opts => navigate({
1709
+ ...opts,
1710
+ from: match.pathname
1711
+ })
1712
+ });
1713
+ loadPromise = Promise.all([componentsPromise, loaderPromise]).then(d => d[1]);
1714
+ }
1742
1715
  matches[index] = match = {
1743
1716
  ...match,
1744
1717
  loadPromise
1745
1718
  };
1746
- await loadPromise;
1719
+ if (!preload) {
1720
+ setState(s => ({
1721
+ ...s,
1722
+ matches: s.matches.map(d => d.id === match.id ? match : d)
1723
+ }));
1724
+ }
1725
+ try {
1726
+ const loaderData = await loadPromise;
1727
+ if (latestPromise = checkLatest()) return await latestPromise;
1728
+ matches[index] = match = {
1729
+ ...match,
1730
+ error: undefined,
1731
+ status: 'success',
1732
+ isFetching: false,
1733
+ updatedAt: Date.now(),
1734
+ loaderData,
1735
+ loadPromise: undefined
1736
+ };
1737
+ } catch (error) {
1738
+ if (latestPromise = checkLatest()) return await latestPromise;
1739
+ if (handleIfRedirect(error)) return;
1740
+ try {
1741
+ route.options.onError?.(error);
1742
+ } catch (onErrorError) {
1743
+ error = onErrorError;
1744
+ if (handleIfRedirect(onErrorError)) return;
1745
+ }
1746
+ matches[index] = match = {
1747
+ ...match,
1748
+ error,
1749
+ status: 'error',
1750
+ isFetching: false,
1751
+ updatedAt: Date.now()
1752
+ };
1753
+ }
1754
+ if (!preload) {
1755
+ setState(s => ({
1756
+ ...s,
1757
+ matches: s.matches.map(d => d.id === match.id ? match : d)
1758
+ }));
1759
+ }
1747
1760
  })());
1748
1761
  });
1749
1762
  await Promise.all(matchPromises);
@@ -1769,6 +1782,7 @@
1769
1782
  let matches = matchRoutes(next.pathname, next.search, {
1770
1783
  debug: true
1771
1784
  });
1785
+ pendingMatchesRef.current = matches;
1772
1786
  const previousMatches = state.matches;
1773
1787
 
1774
1788
  // Ingest the new matches
@@ -1794,9 +1808,9 @@
1794
1808
  if (latestPromise = checkLatest(promise)) {
1795
1809
  return latestPromise;
1796
1810
  }
1797
- const exitingMatchIds = previousMatches.filter(id => !state.pendingMatches.includes(id));
1798
- const enteringMatchIds = state.pendingMatches.filter(id => !previousMatches.includes(id));
1799
- const stayingMatchIds = previousMatches.filter(id => state.pendingMatches.includes(id))
1811
+ const exitingMatchIds = previousMatches.filter(id => !pendingMatchesRef.current.includes(id));
1812
+ const enteringMatchIds = pendingMatchesRef.current.filter(id => !previousMatches.includes(id));
1813
+ const stayingMatchIds = previousMatches.filter(id => pendingMatchesRef.current.includes(id))
1800
1814
 
1801
1815
  // setState((s) => ({
1802
1816
  // ...s,
@@ -1976,9 +1990,7 @@
1976
1990
  unsub();
1977
1991
  };
1978
1992
  }, [history]);
1979
- const initialLoad = React__namespace.useRef(true);
1980
- if (initialLoad.current) {
1981
- initialLoad.current = false;
1993
+ React__namespace.useLayoutEffect(() => {
1982
1994
  startReactTransition(() => {
1983
1995
  try {
1984
1996
  load();
@@ -1986,7 +1998,7 @@
1986
1998
  console.error(err);
1987
1999
  }
1988
2000
  });
1989
- }
2001
+ }, []);
1990
2002
  const matchRoute = useStableCallback((location, opts) => {
1991
2003
  location = {
1992
2004
  ...location,
@@ -2082,6 +2094,9 @@
2082
2094
  }) : null));
2083
2095
  }
2084
2096
  const defaultPending = () => null;
2097
+ function SafeFragment(props) {
2098
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
2099
+ }
2085
2100
  function Match({
2086
2101
  matches
2087
2102
  }) {
@@ -2095,9 +2110,7 @@
2095
2110
  const locationKey = useRouterState().location.state?.key;
2096
2111
  const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
2097
2112
  const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
2098
- const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? React__namespace.Suspense;
2099
- // const ResolvedSuspenseBoundary = SafeFragment
2100
-
2113
+ const ResolvedSuspenseBoundary = route.options.wrapInSuspense ? React__namespace.Suspense : SafeFragment;
2101
2114
  const errorComponent = React__namespace.useCallback(props => {
2102
2115
  return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
2103
2116
  ...props,
@@ -2147,7 +2160,8 @@
2147
2160
  useMatch: route.useMatch,
2148
2161
  useRouteContext: route.useRouteContext,
2149
2162
  useSearch: route.useSearch,
2150
- useParams: route.useParams
2163
+ useParams: route.useParams,
2164
+ useLoaderData: route.useLoaderData
2151
2165
  });
2152
2166
  }
2153
2167
  return /*#__PURE__*/React__namespace.createElement(Outlet, null);
@@ -2218,6 +2232,13 @@
2218
2232
  }
2219
2233
  });
2220
2234
  }
2235
+ function useLoaderData(opts) {
2236
+ const match = useMatch({
2237
+ ...opts,
2238
+ select: undefined
2239
+ });
2240
+ return typeof opts.select === 'function' ? opts.select(match?.loaderData) : match?.loaderData;
2241
+ }
2221
2242
 
2222
2243
  function useParams(opts) {
2223
2244
  return useRouterState({
@@ -2323,6 +2344,12 @@
2323
2344
  from: this.id
2324
2345
  });
2325
2346
  };
2347
+ useLoaderData = opts => {
2348
+ return useLoaderData({
2349
+ ...opts,
2350
+ from: this.id
2351
+ });
2352
+ };
2326
2353
  }
2327
2354
  function rootRouteWithContext() {
2328
2355
  return options => {
@@ -2759,6 +2786,7 @@
2759
2786
  exports.useBlocker = useBlocker;
2760
2787
  exports.useLayoutEffect = useLayoutEffect$1;
2761
2788
  exports.useLinkProps = useLinkProps;
2789
+ exports.useLoaderData = useLoaderData;
2762
2790
  exports.useMatch = useMatch;
2763
2791
  exports.useMatchRoute = useMatchRoute;
2764
2792
  exports.useMatches = useMatches;