@tanstack/router-core 0.0.1-beta.193 → 0.0.1-beta.195

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.
@@ -8,6 +8,7 @@ export interface RouterHistory {
8
8
  forward: () => void;
9
9
  createHref: (href: string) => string;
10
10
  block: (blockerFn: BlockerFn) => () => void;
11
+ flush: () => void;
11
12
  }
12
13
  export interface HistoryLocation extends ParsedPath {
13
14
  state: HistoryState;
@@ -24,6 +25,22 @@ export interface HistoryState {
24
25
  __tempKey?: string;
25
26
  }
26
27
  type BlockerFn = (retry: () => void, cancel: () => void) => void;
28
+ /**
29
+ * Creates a history object that can be used to interact with the browser's
30
+ * navigation. This is a lightweight API wrapping the browser's native methods.
31
+ * It is designed to work with TanStack Router, but could be used as a standalone API as well.
32
+ * IMPORTANT: This API implements history throttling via a microtask to prevent
33
+ * excessive calls to the history API. In some browsers, calling history.pushState or
34
+ * history.replaceState in quick succession can cause the browser to ignore subsequent
35
+ * calls. This API smooths out those differences and ensures that your application
36
+ * state will *eventually* match the browser state. In most cases, this is not a problem,
37
+ * but if you need to ensure that the browser state is up to date, you can use the
38
+ * `history.flush` method to immediately flush all pending state changes to the browser URL.
39
+ * @param opts
40
+ * @param opts.getHref A function that returns the current href (path + search + hash)
41
+ * @param opts.createHref A function that takes a path and returns a href (path + search + hash)
42
+ * @returns A history instance
43
+ */
27
44
  export declare function createBrowserHistory(opts?: {
28
45
  getHref?: () => string;
29
46
  createHref?: (path: string) => string;
@@ -11,34 +11,34 @@ export interface RouteMeta {
11
11
  }
12
12
  export interface RouteContext {
13
13
  }
14
- export interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
14
+ export interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
15
15
  }
16
- export interface RegisterErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
16
+ export interface RegisterErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
17
17
  }
18
- export interface RegisterPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
18
+ export interface RegisterPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
19
19
  }
20
- export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
20
+ export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
21
21
  }
22
- export interface RegisterErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
22
+ export interface RegisterErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
23
23
  }
24
- export interface RegisterPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
24
+ export interface RegisterPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> {
25
25
  }
26
- export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
26
+ export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TAllContext> extends {
27
27
  RouteComponent: infer T;
28
28
  } ? T : () => unknown;
29
- export type RegisteredErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
29
+ export type RegisteredErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TAllContext> extends {
30
30
  ErrorRouteComponent: infer T;
31
31
  } ? T : () => unknown;
32
- export type RegisteredPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
32
+ export type RegisteredPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext> extends {
33
33
  PendingRouteComponent: infer T;
34
34
  } ? T : () => unknown;
35
- export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
35
+ export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TAllContext> extends {
36
36
  RouteProps: infer T;
37
37
  } ? T : {};
38
- export type RegisteredErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
38
+ export type RegisteredErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TAllContext> extends {
39
39
  ErrorRouteProps: infer T;
40
40
  } ? T : {};
41
- export type RegisteredPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
41
+ export type RegisteredPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TAllContext> extends {
42
42
  PendingRouteProps: infer T;
43
43
  } ? T : {};
44
44
  export type PreloadableObj = {
@@ -55,19 +55,19 @@ export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
55
55
  } : {
56
56
  meta: RouteMeta;
57
57
  };
58
- export type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
59
- export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
58
+ export type AnyRouteProps = RegisteredRouteProps<any, any, any, any>;
59
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, 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, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>;
60
60
  export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
61
- export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
61
+ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, 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> & {
62
62
  getParentRoute: () => TParentRoute;
63
63
  validateSearch?: SearchSchemaValidator<TSearchSchema>;
64
64
  loaderContext?: (opts: {
65
65
  search: TFullSearchSchema;
66
66
  }) => TLoaderContext;
67
67
  } & (keyof PickRequired<RouteContext> extends never ? {
68
- beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
68
+ beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
69
69
  } : {
70
- beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
70
+ beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
71
71
  }) & {
72
72
  loader?: LoaderFn<TLoader, TAllParams, NoInfer<TLoaderContext>, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
73
73
  } & ([TLoader] extends [never] ? {
@@ -79,18 +79,18 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
79
79
  stringifyParams?: never;
80
80
  parseParams?: never;
81
81
  });
82
- type BeforeLoadFn<TParentRoute, TAllParams, TParentContext, TLoaderContext, TRouteContext> = (opts: {
82
+ type BeforeLoadFn<TParentRoute extends AnyRoute, TAllParams, TLoaderContext, TRouteContext> = (opts: {
83
83
  abortController: AbortController;
84
84
  preload: boolean;
85
85
  params: TAllParams;
86
- context: Expand<TParentContext & TLoaderContext>;
86
+ context: Expand<TParentRoute['types']['context'] & TLoaderContext>;
87
87
  }) => Promise<TRouteContext> | TRouteContext | void;
88
- export type UpdatableRouteOptions<TLoader, TSearchSchema extends Record<string, any>, TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TRouteContext extends Record<string, any>, TAllContext extends Record<string, any>> = MetaOptions & {
88
+ export type UpdatableRouteOptions<TLoader, TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = MetaOptions & {
89
89
  caseSensitive?: boolean;
90
90
  wrapInSuspense?: boolean;
91
- component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
92
- errorComponent?: RegisteredErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
93
- pendingComponent?: RegisteredPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
91
+ component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TAllContext>;
92
+ errorComponent?: RegisteredErrorRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
93
+ pendingComponent?: RegisteredPendingRouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
94
94
  preSearchFilters?: SearchFilter<TFullSearchSchema>[];
95
95
  postSearchFilters?: SearchFilter<TFullSearchSchema>[];
96
96
  preloadMaxAge?: number;
@@ -123,7 +123,7 @@ export interface LoaderContext<TAllParams = {}, TLoaderContext = {}, TAllContext
123
123
  abortController: AbortController;
124
124
  preload: boolean;
125
125
  params: TAllParams;
126
- context: DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>;
126
+ context: Expand<DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>>;
127
127
  }
128
128
  export type SearchFilter<T, U = T> = (prev: T) => U;
129
129
  export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
@@ -135,7 +135,7 @@ export type InferFullSearchSchema<TRoute> = TRoute extends {
135
135
  };
136
136
  } ? TFullSearchSchema : {};
137
137
  export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
138
- export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
138
+ export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
139
139
  }
140
140
  export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
141
141
  export type UseLoaderResult<T> = T;
@@ -158,14 +158,17 @@ export type RouteConstraints = {
158
158
  TParams: Record<string, any>;
159
159
  TAllParams: Record<string, any>;
160
160
  TParentContext: AnyContext;
161
- TAllParentContext: AnyContext;
162
161
  TRouteContext: RouteContext;
163
162
  TAllContext: AnyContext;
164
163
  TRouterContext: AnyContext;
165
164
  TChildren: unknown;
166
165
  TRouteTree: AnyRoute;
167
166
  };
168
- 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>, TLoaderContext extends RouteConstraints['TLoaderContext'] = AnyContext, TLoader = unknown, 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>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
167
+ 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>, TLoaderContext extends RouteConstraints['TLoaderContext'] = {}, TLoader = unknown, 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 RouteConstraints['TAllContext'] = Expand<DeepMergeAll<[
168
+ IsAny<TParentRoute['types']['context'], {}>,
169
+ TLoaderContext,
170
+ TRouteContext
171
+ ]>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
169
172
  types: {
170
173
  parentRoute: TParentRoute;
171
174
  path: TPath;
@@ -178,8 +181,6 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
178
181
  fullSearchSchema: TFullSearchSchema;
179
182
  params: TParams;
180
183
  allParams: TAllParams;
181
- parentContext: TParentContext;
182
- allParentContext: TAllParentContext;
183
184
  routeContext: TRouteContext;
184
185
  context: TAllContext;
185
186
  children: TChildren;
@@ -187,7 +188,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
187
188
  routerContext: TRouterContext;
188
189
  };
189
190
  isRoot: TParentRoute extends Route<any> ? true : false;
190
- options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext>;
191
+ options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>;
191
192
  parentRoute: TParentRoute;
192
193
  id: TId;
193
194
  path: TPath;
@@ -197,22 +198,47 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
197
198
  originalIndex?: number;
198
199
  router?: AnyRouter;
199
200
  rank: number;
200
- constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
201
+ constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>);
201
202
  init: (opts: {
202
203
  originalIndex: number;
203
204
  router: AnyRouter;
204
205
  }) => void;
205
- addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
206
- update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>) => this;
206
+ addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
207
+ update: (options: UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TAllContext>) => this;
207
208
  static __onInit: (route: any) => void;
208
209
  }
209
210
  export type AnyRootRoute = RootRoute<any, any, any, any>;
210
211
  export declare class RouterContext<TRouterContext extends {}> {
211
212
  constructor();
212
- createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
213
+ createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouteContext, DeepMerge<TRouterContext, DeepMerge<TLoaderContext, DeepMerge<TRouteContext, {}>>>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
213
214
  }
214
- export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>, TRouterContext, any, any> {
215
- constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
215
+ export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, // TParentRoute
216
+ '/', // TPath
217
+ '/', // TFullPath
218
+ string, // TCustomId
219
+ RootRouteId, // TId
220
+ TLoaderContext, // TLoaderContext
221
+ TLoader, // TLoader
222
+ TSearchSchema, // TSearchSchema
223
+ TSearchSchema, // TFullSearchSchema
224
+ {}, // TParams
225
+ {}, // TAllParams
226
+ TRouteContext, // TRouteContext
227
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>, // TAllContext
228
+ TRouterContext, // TRouterContext
229
+ any, // TChildren
230
+ any> {
231
+ constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
232
+ RootRouteId, // TCustomId
233
+ '', // TPath
234
+ TLoaderContext, // TLoaderContext
235
+ TLoader, // TLoader
236
+ TSearchSchema, // TSearchSchema
237
+ TSearchSchema, // TFullSearchSchema
238
+ {}, // TParams
239
+ {}, // TAllParams
240
+ TRouteContext, // TRouteContext
241
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
216
242
  }
217
243
  export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
218
244
  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;
@@ -1,7 +1,7 @@
1
1
  import { AnyRoute, Route } from './route';
2
2
  import { Expand, UnionToIntersection } from './utils';
3
3
  export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
4
- export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
4
+ export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
5
5
  [TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
6
6
  }[string] : never : never;
7
7
  export type RoutesById<TRouteTree extends AnyRoute> = {
@@ -18,5 +18,5 @@ export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<ParseRoute
18
18
  fullPath: TPath;
19
19
  }>;
20
20
  export type RoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['fullPath'] | '/';
21
- export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']> & {}>>;
21
+ export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>>;
22
22
  export type AllParams<TRouteTree extends AnyRoute> = Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>>;
@@ -75,9 +75,9 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
75
75
  defaultPreload?: false | 'intent';
76
76
  defaultPreloadDelay?: number;
77
77
  reloadOnWindowFocus?: boolean;
78
- defaultComponent?: RegisteredRouteComponent<unknown, AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
79
- defaultErrorComponent?: RegisteredErrorRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
80
- defaultPendingComponent?: RegisteredPendingRouteComponent<AnySearchSchema, AnyPathParams, AnyContext, AnyContext>;
78
+ defaultComponent?: RegisteredRouteComponent<unknown, AnySearchSchema, AnyPathParams, AnyContext>;
79
+ defaultErrorComponent?: RegisteredErrorRouteComponent<AnySearchSchema, AnyPathParams, AnyContext>;
80
+ defaultPendingComponent?: RegisteredPendingRouteComponent<AnySearchSchema, AnyPathParams, AnyContext>;
81
81
  defaultMaxAge?: number;
82
82
  defaultGcMaxAge?: number;
83
83
  defaultPreloadMaxAge?: number;
@@ -1,5 +1,5 @@
1
1
  export type NoInfer<T> = [T][T extends any ? 0 : never];
2
- export type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
2
+ export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N;
3
3
  export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
4
4
  export type IsKnown<T, Y, N> = unknown extends T ? N : Y;
5
5
  export type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
@@ -107,13 +107,13 @@
107
107
  push: (path, state) => {
108
108
  assignKey(state);
109
109
  queueTask(() => {
110
- opts.pushState(path, state);
110
+ opts.pushState(path, state, onUpdate);
111
111
  });
112
112
  },
113
113
  replace: (path, state) => {
114
114
  assignKey(state);
115
115
  queueTask(() => {
116
- opts.replaceState(path, state);
116
+ opts.replaceState(path, state, onUpdate);
117
117
  });
118
118
  },
119
119
  go: index => {
@@ -145,7 +145,8 @@
145
145
  stopBlocking();
146
146
  }
147
147
  };
148
- }
148
+ },
149
+ flush: () => opts.flush?.()
149
150
  };
150
151
  }
151
152
  function assignKey(state) {
@@ -158,25 +159,100 @@
158
159
  // }
159
160
  }
160
161
 
162
+ /**
163
+ * Creates a history object that can be used to interact with the browser's
164
+ * navigation. This is a lightweight API wrapping the browser's native methods.
165
+ * It is designed to work with TanStack Router, but could be used as a standalone API as well.
166
+ * IMPORTANT: This API implements history throttling via a microtask to prevent
167
+ * excessive calls to the history API. In some browsers, calling history.pushState or
168
+ * history.replaceState in quick succession can cause the browser to ignore subsequent
169
+ * calls. This API smooths out those differences and ensures that your application
170
+ * state will *eventually* match the browser state. In most cases, this is not a problem,
171
+ * but if you need to ensure that the browser state is up to date, you can use the
172
+ * `history.flush` method to immediately flush all pending state changes to the browser URL.
173
+ * @param opts
174
+ * @param opts.getHref A function that returns the current href (path + search + hash)
175
+ * @param opts.createHref A function that takes a path and returns a href (path + search + hash)
176
+ * @returns A history instance
177
+ */
161
178
  function createBrowserHistory(opts) {
162
179
  const getHref = opts?.getHref ?? (() => `${window.location.pathname}${window.location.search}${window.location.hash}`);
163
180
  const createHref = opts?.createHref ?? (path => path);
164
- const getLocation = () => parseLocation(getHref(), window.history.state);
181
+ let currentLocation = parseLocation(getHref(), window.history.state);
182
+ const getLocation = () => currentLocation;
183
+ let next;
184
+
185
+ // Because we are proactively updating the location
186
+ // in memory before actually updating the browser history,
187
+ // we need to track when we are doing this so we don't
188
+ // notify subscribers twice on the last update.
189
+ let tracking = true;
190
+
191
+ // We need to track the current scheduled update to prevent
192
+ // multiple updates from being scheduled at the same time.
193
+ let scheduled;
194
+
195
+ // This function is a wrapper to prevent any of the callback's
196
+ // side effects from causing a subscriber notification
197
+ const untrack = fn => {
198
+ tracking = false;
199
+ fn();
200
+ tracking = true;
201
+ };
202
+
203
+ // This function flushes the next update to the browser history
204
+ const flush = () => {
205
+ // Do not notify subscribers about this push/replace call
206
+ untrack(() => {
207
+ if (!next) return;
208
+ window.history[next.isPush ? 'pushState' : 'replaceState'](next.state, '', next.href);
209
+ // Reset the nextIsPush flag and clear the scheduled update
210
+ next = undefined;
211
+ scheduled = undefined;
212
+ });
213
+ };
214
+
215
+ // This function queues up a call to update the browser history
216
+ const queueHistoryAction = (type, path, state, onUpdate) => {
217
+ const href = createHref(path);
218
+
219
+ // Update the location in memory
220
+ currentLocation = parseLocation(href, state);
221
+
222
+ // Keep track of the next location we need to flush to the URL
223
+ next = {
224
+ href,
225
+ state,
226
+ isPush: next?.isPush || type === 'push'
227
+ };
228
+ // Notify subscribers
229
+ onUpdate();
230
+ if (!scheduled) {
231
+ // Schedule an update to the browser history
232
+ scheduled = Promise.resolve().then(() => flush());
233
+ }
234
+ };
165
235
  return createHistory({
166
236
  getLocation,
167
237
  subscriber: onUpdate => {
168
- window.addEventListener(pushStateEvent, onUpdate);
169
- window.addEventListener(popStateEvent, onUpdate);
238
+ window.addEventListener(pushStateEvent, () => {
239
+ currentLocation = parseLocation(getHref(), window.history.state);
240
+ onUpdate();
241
+ });
242
+ window.addEventListener(popStateEvent, () => {
243
+ currentLocation = parseLocation(getHref(), window.history.state);
244
+ onUpdate();
245
+ });
170
246
  var pushState = window.history.pushState;
171
247
  window.history.pushState = function () {
172
248
  let res = pushState.apply(history, arguments);
173
- onUpdate();
249
+ if (tracking) onUpdate();
174
250
  return res;
175
251
  };
176
252
  var replaceState = window.history.replaceState;
177
253
  window.history.replaceState = function () {
178
254
  let res = replaceState.apply(history, arguments);
179
- onUpdate();
255
+ if (tracking) onUpdate();
180
256
  return res;
181
257
  };
182
258
  return () => {
@@ -186,16 +262,13 @@
186
262
  window.removeEventListener(popStateEvent, onUpdate);
187
263
  };
188
264
  },
189
- pushState: (path, state) => {
190
- window.history.pushState(state, '', createHref(path));
191
- },
192
- replaceState: (path, state) => {
193
- window.history.replaceState(state, '', createHref(path));
194
- },
265
+ pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
266
+ replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
195
267
  back: () => window.history.back(),
196
268
  forward: () => window.history.forward(),
197
269
  go: n => window.history.go(n),
198
- createHref: path => createHref(path)
270
+ createHref: path => createHref(path),
271
+ flush
199
272
  });
200
273
  }
201
274
  function createHashHistory() {
@@ -252,6 +325,8 @@
252
325
  return (Math.random() + 1).toString(36).substring(7);
253
326
  }
254
327
 
328
+ // export type Expand<T> = T
329
+
255
330
  // type Compute<T> = { [K in keyof T]: T[K] } | never
256
331
 
257
332
  // type AllKeys<T> = T extends any ? keyof T : never
@@ -1344,7 +1419,7 @@
1344
1419
  };
1345
1420
  this.setRouteMatch(match.id, s => ({
1346
1421
  ...s,
1347
- context
1422
+ context: replaceEqualDeep(s.context, context)
1348
1423
  }));
1349
1424
  } catch (err) {
1350
1425
  handleError(err, 'BEFORE_LOAD');