@tanstack/react-router 0.0.1-beta.214 → 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;
@@ -1169,10 +1169,12 @@
1169
1169
  const latestLocationRef = React__namespace.useRef(parseLocation());
1170
1170
  const [preState, setState] = React__namespace.useState(() => getInitialRouterState(latestLocationRef.current));
1171
1171
  const [isTransitioning, startReactTransition] = React__namespace.useTransition();
1172
+ const pendingMatchesRef = React__namespace.useRef([]);
1172
1173
  const state = React__namespace.useMemo(() => ({
1173
1174
  ...preState,
1174
1175
  status: isTransitioning ? 'pending' : 'idle',
1175
- location: isTransitioning ? latestLocationRef.current : preState.location
1176
+ location: isTransitioning ? latestLocationRef.current : preState.location,
1177
+ pendingMatches: pendingMatchesRef.current
1176
1178
  }), [preState, isTransitioning]);
1177
1179
  React__namespace.useLayoutEffect(() => {
1178
1180
  if (!isTransitioning && state.resolvedLocation !== state.location) {
@@ -1182,6 +1184,7 @@
1182
1184
  toLocation: state.location,
1183
1185
  pathChanged: state.location.href !== state.resolvedLocation?.href
1184
1186
  });
1187
+ pendingMatchesRef.current = [];
1185
1188
  setState(s => ({
1186
1189
  ...s,
1187
1190
  resolvedLocation: s.location
@@ -1335,7 +1338,7 @@
1335
1338
  }
1336
1339
 
1337
1340
  // Create a fresh route match
1338
- 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));
1339
1342
  const routeMatch = {
1340
1343
  id: matchId,
1341
1344
  routeId: route.id,
@@ -1666,9 +1669,6 @@
1666
1669
  matchPromises.push((async () => {
1667
1670
  const parentMatchPromise = matchPromises[index - 1];
1668
1671
  const route = looseRoutesById[match.routeId];
1669
- if (match.isFetching) {
1670
- return getRouteMatch(state, match.id)?.loadPromise;
1671
- }
1672
1672
  const handleIfRedirect = err => {
1673
1673
  if (isRedirect(err)) {
1674
1674
  if (!preload) {
@@ -1678,73 +1678,85 @@
1678
1678
  }
1679
1679
  return false;
1680
1680
  };
1681
- const load = async () => {
1682
- try {
1683
- const componentsPromise = Promise.all(componentTypes.map(async type => {
1684
- const component = route.options[type];
1685
- if (component?.preload) {
1686
- await component.preload();
1687
- }
1688
- }));
1689
- const loaderPromise = route.options.load?.({
1690
- params: match.params,
1691
- search: match.search,
1692
- preload: !!preload,
1693
- parentMatchPromise,
1694
- abortController: match.abortController,
1695
- context: match.context,
1696
- location: state.location,
1697
- navigate: opts => navigate({
1698
- ...opts,
1699
- from: match.pathname
1700
- })
1701
- });
1702
- const [_, loaderContext] = await Promise.all([componentsPromise, loaderPromise]);
1703
- if (latestPromise = checkLatest()) return await latestPromise;
1704
- matches[index] = match = {
1705
- ...match,
1706
- error: undefined,
1707
- status: 'success',
1708
- isFetching: false,
1709
- updatedAt: Date.now()
1710
- };
1711
- } catch (error) {
1712
- if (latestPromise = checkLatest()) return await latestPromise;
1713
- if (handleIfRedirect(error)) return;
1714
- try {
1715
- route.options.onError?.(error);
1716
- } catch (onErrorError) {
1717
- error = onErrorError;
1718
- if (handleIfRedirect(onErrorError)) return;
1719
- }
1720
- matches[index] = match = {
1721
- ...match,
1722
- error,
1723
- status: 'error',
1724
- isFetching: false,
1725
- updatedAt: Date.now()
1726
- };
1727
- }
1728
- if (!preload) {
1729
- setState(s => ({
1730
- ...s,
1731
- matches: s.matches.map(d => d.id === match.id ? match : d)
1732
- }));
1733
- }
1734
- };
1735
1681
  let loadPromise;
1736
1682
  matches[index] = match = {
1737
1683
  ...match,
1738
- isFetching: true,
1739
1684
  fetchedAt: Date.now(),
1740
1685
  invalid: false
1741
1686
  };
1742
- 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
+ }
1743
1715
  matches[index] = match = {
1744
1716
  ...match,
1745
1717
  loadPromise
1746
1718
  };
1747
- 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
+ }
1748
1760
  })());
1749
1761
  });
1750
1762
  await Promise.all(matchPromises);
@@ -1770,6 +1782,7 @@
1770
1782
  let matches = matchRoutes(next.pathname, next.search, {
1771
1783
  debug: true
1772
1784
  });
1785
+ pendingMatchesRef.current = matches;
1773
1786
  const previousMatches = state.matches;
1774
1787
 
1775
1788
  // Ingest the new matches
@@ -1795,9 +1808,9 @@
1795
1808
  if (latestPromise = checkLatest(promise)) {
1796
1809
  return latestPromise;
1797
1810
  }
1798
- const exitingMatchIds = previousMatches.filter(id => !state.pendingMatches.includes(id));
1799
- const enteringMatchIds = state.pendingMatches.filter(id => !previousMatches.includes(id));
1800
- 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))
1801
1814
 
1802
1815
  // setState((s) => ({
1803
1816
  // ...s,
@@ -1977,9 +1990,7 @@
1977
1990
  unsub();
1978
1991
  };
1979
1992
  }, [history]);
1980
- const initialLoad = React__namespace.useRef(true);
1981
- if (initialLoad.current) {
1982
- initialLoad.current = false;
1993
+ React__namespace.useLayoutEffect(() => {
1983
1994
  startReactTransition(() => {
1984
1995
  try {
1985
1996
  load();
@@ -1987,7 +1998,7 @@
1987
1998
  console.error(err);
1988
1999
  }
1989
2000
  });
1990
- }
2001
+ }, []);
1991
2002
  const matchRoute = useStableCallback((location, opts) => {
1992
2003
  location = {
1993
2004
  ...location,
@@ -2083,6 +2094,9 @@
2083
2094
  }) : null));
2084
2095
  }
2085
2096
  const defaultPending = () => null;
2097
+ function SafeFragment(props) {
2098
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
2099
+ }
2086
2100
  function Match({
2087
2101
  matches
2088
2102
  }) {
@@ -2096,9 +2110,7 @@
2096
2110
  const locationKey = useRouterState().location.state?.key;
2097
2111
  const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
2098
2112
  const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
2099
- const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? React__namespace.Suspense;
2100
- // const ResolvedSuspenseBoundary = SafeFragment
2101
-
2113
+ const ResolvedSuspenseBoundary = route.options.wrapInSuspense ? React__namespace.Suspense : SafeFragment;
2102
2114
  const errorComponent = React__namespace.useCallback(props => {
2103
2115
  return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
2104
2116
  ...props,
@@ -2148,7 +2160,8 @@
2148
2160
  useMatch: route.useMatch,
2149
2161
  useRouteContext: route.useRouteContext,
2150
2162
  useSearch: route.useSearch,
2151
- useParams: route.useParams
2163
+ useParams: route.useParams,
2164
+ useLoaderData: route.useLoaderData
2152
2165
  });
2153
2166
  }
2154
2167
  return /*#__PURE__*/React__namespace.createElement(Outlet, null);
@@ -2219,6 +2232,13 @@
2219
2232
  }
2220
2233
  });
2221
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
+ }
2222
2242
 
2223
2243
  function useParams(opts) {
2224
2244
  return useRouterState({
@@ -2324,6 +2344,12 @@
2324
2344
  from: this.id
2325
2345
  });
2326
2346
  };
2347
+ useLoaderData = opts => {
2348
+ return useLoaderData({
2349
+ ...opts,
2350
+ from: this.id
2351
+ });
2352
+ };
2327
2353
  }
2328
2354
  function rootRouteWithContext() {
2329
2355
  return options => {
@@ -2760,6 +2786,7 @@
2760
2786
  exports.useBlocker = useBlocker;
2761
2787
  exports.useLayoutEffect = useLayoutEffect$1;
2762
2788
  exports.useLinkProps = useLinkProps;
2789
+ exports.useLoaderData = useLoaderData;
2763
2790
  exports.useMatch = useMatch;
2764
2791
  exports.useMatchRoute = useMatchRoute;
2765
2792
  exports.useMatches = useMatches;