@tanstack/router-core 1.112.8 → 1.112.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/router.ts CHANGED
@@ -1,7 +1,61 @@
1
1
  import type { ParsedLocation } from './location'
2
2
  import type { DeferredPromiseState } from './defer'
3
- import type { ControlledPromise } from './utils'
4
- import type { AnyRoute, AnyRouteWithContext } from './route'
3
+ import type {
4
+ ControlledPromise,
5
+ NoInfer,
6
+ NonNullableUpdater,
7
+ Updater,
8
+ } from './utils'
9
+ import type {
10
+ AnyContext,
11
+ AnyRoute,
12
+ AnyRouteWithContext,
13
+ MakeRemountDepsOptionsUnion,
14
+ RouteMask,
15
+ } from './route'
16
+ import type { Store } from '@tanstack/store'
17
+ import type {
18
+ FullSearchSchema,
19
+ RouteById,
20
+ RoutePaths,
21
+ RoutesById,
22
+ RoutesByPath,
23
+ } from './routeInfo'
24
+ import type {
25
+ AnyRouteMatch,
26
+ MakeRouteMatchUnion,
27
+ MatchRouteOptions,
28
+ } from './Matches'
29
+ import type { AnyRedirect, ResolvedRedirect } from './redirect'
30
+ import type {
31
+ BuildLocationFn,
32
+ CommitLocationOptions,
33
+ NavigateFn,
34
+ } from './RouterProvider'
35
+ import type {
36
+ HistoryLocation,
37
+ HistoryState,
38
+ ParsedHistoryState,
39
+ RouterHistory,
40
+ } from '@tanstack/history'
41
+ import type { Manifest } from './manifest'
42
+ import type { StartSerializer } from './serializer'
43
+ import type { AnySchema } from './validators'
44
+ import type { NavigateOptions, ResolveRelativePath, ToOptions } from './link'
45
+ import type { SearchParser, SearchSerializer } from './searchParams'
46
+
47
+ declare global {
48
+ interface Window {
49
+ __TSR_ROUTER__?: AnyRouter
50
+ }
51
+ }
52
+
53
+ export type ControllablePromise<T = any> = Promise<T> & {
54
+ resolve: (value: T) => void
55
+ reject: (value?: any) => void
56
+ }
57
+
58
+ export type InjectedHtmlEntry = Promise<string>
5
59
 
6
60
  export interface Register {
7
61
  // router: Router
@@ -13,26 +67,660 @@ export type RegisteredRouter = Register extends {
13
67
  ? TRouter
14
68
  : AnyRouter
15
69
 
70
+ export type DefaultRemountDepsFn<TRouteTree extends AnyRoute> = (
71
+ opts: MakeRemountDepsOptionsUnion<TRouteTree>,
72
+ ) => any
73
+
74
+ export interface DefaultRouterOptionsExtensions {}
75
+
76
+ export interface RouterOptionsExtensions
77
+ extends DefaultRouterOptionsExtensions {}
78
+
16
79
  export interface RouterOptions<
17
- in out TTrailingSlashOption extends TrailingSlashOption,
18
- > {
80
+ TRouteTree extends AnyRoute,
81
+ TTrailingSlashOption extends TrailingSlashOption,
82
+ TDefaultStructuralSharingOption extends boolean = false,
83
+ TRouterHistory extends RouterHistory = RouterHistory,
84
+ TDehydrated extends Record<string, any> = Record<string, any>,
85
+ > extends RouterOptionsExtensions {
86
+ /**
87
+ * The history object that will be used to manage the browser history.
88
+ *
89
+ * If not provided, a new createBrowserHistory instance will be created and used.
90
+ *
91
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#history-property)
92
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/history-types)
93
+ */
94
+ history?: TRouterHistory
95
+ /**
96
+ * A function that will be used to stringify search params when generating links.
97
+ *
98
+ * @default defaultStringifySearch
99
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#stringifysearch-method)
100
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
101
+ */
102
+ stringifySearch?: SearchSerializer
103
+ /**
104
+ * A function that will be used to parse search params when parsing the current location.
105
+ *
106
+ * @default defaultParseSearch
107
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#parsesearch-method)
108
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
109
+ */
110
+ parseSearch?: SearchParser
111
+ /**
112
+ * If `false`, routes will not be preloaded by default in any way.
113
+ *
114
+ * If `'intent'`, routes will be preloaded by default when the user hovers over a link or a `touchstart` event is detected on a `<Link>`.
115
+ *
116
+ * If `'viewport'`, routes will be preloaded by default when they are within the viewport.
117
+ *
118
+ * @default false
119
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
120
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
121
+ */
122
+ defaultPreload?: false | 'intent' | 'viewport' | 'render'
123
+ /**
124
+ * The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
125
+ *
126
+ * @default 50
127
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloaddelay-property)
128
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#preload-delay)
129
+ */
130
+ defaultPreloadDelay?: number
131
+ /**
132
+ * The default `pendingMs` a route should use if no pendingMs is provided.
133
+ *
134
+ * @default 1000
135
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingms-property)
136
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
137
+ */
138
+ defaultPendingMs?: number
139
+ /**
140
+ * The default `pendingMinMs` a route should use if no pendingMinMs is provided.
141
+ *
142
+ * @default 500
143
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingminms-property)
144
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
145
+ */
146
+ defaultPendingMinMs?: number
147
+ /**
148
+ * The default `staleTime` a route should use if no staleTime is provided. This is the time in milliseconds that a route will be considered fresh.
149
+ *
150
+ * @default 0
151
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultstaletime-property)
152
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
153
+ */
154
+ defaultStaleTime?: number
155
+ /**
156
+ * The default `preloadStaleTime` a route should use if no preloadStaleTime is provided.
157
+ *
158
+ * @default 30_000 `(30 seconds)`
159
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadstaletime-property)
160
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
161
+ */
162
+ defaultPreloadStaleTime?: number
163
+ /**
164
+ * The default `defaultPreloadGcTime` a route should use if no preloadGcTime is provided.
165
+ *
166
+ * @default 1_800_000 `(30 minutes)`
167
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadgctime-property)
168
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
169
+ */
170
+ defaultPreloadGcTime?: number
171
+ /**
172
+ * If `true`, route navigations will called using `document.startViewTransition()`.
173
+ *
174
+ * If the browser does not support this api, this option will be ignored.
175
+ *
176
+ * See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
177
+ *
178
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property)
179
+ */
180
+ defaultViewTransition?: boolean | ViewTransitionOptions
181
+ /**
182
+ * The default `hashScrollIntoView` a route should use if no hashScrollIntoView is provided while navigating
183
+ *
184
+ * See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on `ScrollIntoViewOptions`.
185
+ *
186
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulthashscrollintoview-property)
187
+ */
188
+ defaultHashScrollIntoView?: boolean | ScrollIntoViewOptions
189
+ /**
190
+ * @default 'fuzzy'
191
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundmode-property)
192
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#the-notfoundmode-option)
193
+ */
194
+ notFoundMode?: 'root' | 'fuzzy'
195
+ /**
196
+ * The default `gcTime` a route should use if no gcTime is provided.
197
+ *
198
+ * @default 1_800_000 `(30 minutes)`
199
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultgctime-property)
200
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
201
+ */
202
+ defaultGcTime?: number
203
+ /**
204
+ * If `true`, all routes will be matched as case-sensitive.
205
+ *
206
+ * @default false
207
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#casesensitive-property)
208
+ */
209
+ caseSensitive?: boolean
210
+ /**
211
+ *
212
+ * The route tree that will be used to configure the router instance.
213
+ *
214
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routetree-property)
215
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/routing/route-trees)
216
+ */
217
+ routeTree?: TRouteTree
218
+ /**
219
+ * The basepath for then entire router. This is useful for mounting a router instance at a subpath.
220
+ *
221
+ * @default '/'
222
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
223
+ */
224
+ basepath?: string
225
+ /**
226
+ * The root context that will be provided to all routes in the route tree.
227
+ *
228
+ * This can be used to provide a context to all routes in the tree without having to provide it to each route individually.
229
+ *
230
+ * Optional or required if the root route was created with [`createRootRouteWithContext()`](https://tanstack.com/router/latest/docs/framework/react/api/router/createRootRouteWithContextFunction).
231
+ *
232
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#context-property)
233
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/router-context)
234
+ */
235
+ context?: InferRouterContext<TRouteTree>
236
+ /**
237
+ * A function that will be called when the router is dehydrated.
238
+ *
239
+ * The return value of this function will be serialized and stored in the router's dehydrated state.
240
+ *
241
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#dehydrate-method)
242
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
243
+ */
244
+ dehydrate?: () => TDehydrated
245
+ /**
246
+ * A function that will be called when the router is hydrated.
247
+ *
248
+ * The return value of this function will be serialized and stored in the router's dehydrated state.
249
+ *
250
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#hydrate-method)
251
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
252
+ */
253
+ hydrate?: (dehydrated: TDehydrated) => void
254
+ /**
255
+ * An array of route masks that will be used to mask routes in the route tree.
256
+ *
257
+ * Route masking is when you display a route at a different path than the one it is configured to match, like a modal popup that when shared will unmask to the modal's content instead of the modal's context.
258
+ *
259
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routemasks-property)
260
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking)
261
+ */
262
+ routeMasks?: Array<RouteMask<TRouteTree>>
263
+ /**
264
+ * If `true`, route masks will, by default, be removed when the page is reloaded.
265
+ *
266
+ * This can be overridden on a per-mask basis by setting the `unmaskOnReload` option on the mask, or on a per-navigation basis by setting the `unmaskOnReload` option in the `Navigate` options.
267
+ *
268
+ * @default false
269
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#unmaskonreload-property)
270
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking#unmasking-on-page-reload)
271
+ */
272
+ unmaskOnReload?: boolean
273
+
274
+ /**
275
+ * Use `notFoundComponent` instead.
276
+ *
277
+ * @deprecated
278
+ * See https://tanstack.com/router/v1/docs/guide/not-found-errors#migrating-from-notfoundroute for more info.
279
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundroute-property)
280
+ */
281
+ notFoundRoute?: AnyRoute
282
+ /**
283
+ * Configures how trailing slashes are treated.
284
+ *
285
+ * - `'always'` will add a trailing slash if not present
286
+ * - `'never'` will remove the trailing slash if present
287
+ * - `'preserve'` will not modify the trailing slash.
288
+ *
289
+ * @default 'never'
290
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#trailingslash-property)
291
+ */
19
292
  trailingSlash?: TTrailingSlashOption
293
+ /**
294
+ * While usually automatic, sometimes it can be useful to force the router into a server-side state, e.g. when using the router in a non-browser environment that has access to a global.document object.
295
+ *
296
+ * @default typeof document !== 'undefined'
297
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#isserver-property)
298
+ */
299
+ isServer?: boolean
300
+
301
+ defaultSsr?: boolean
302
+
303
+ search?: {
304
+ /**
305
+ * Configures how unknown search params (= not returned by any `validateSearch`) are treated.
306
+ *
307
+ * @default false
308
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#search.strict-property)
309
+ */
310
+ strict?: boolean
311
+ }
312
+
313
+ /**
314
+ * Configures whether structural sharing is enabled by default for fine-grained selectors.
315
+ *
316
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultstructuralsharing-property)
317
+ */
318
+ defaultStructuralSharing?: TDefaultStructuralSharingOption
319
+
320
+ /**
321
+ * Configures which URI characters are allowed in path params that would ordinarily be escaped by encodeURIComponent.
322
+ *
323
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#pathparamsallowedcharacters-property)
324
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/path-params#allowed-characters)
325
+ */
326
+ pathParamsAllowedCharacters?: Array<
327
+ ';' | ':' | '@' | '&' | '=' | '+' | '$' | ','
328
+ >
329
+
330
+ defaultRemountDeps?: DefaultRemountDepsFn<TRouteTree>
331
+
332
+ /**
333
+ * If `true`, scroll restoration will be enabled
334
+ *
335
+ * @default false
336
+ */
337
+ scrollRestoration?: boolean
338
+
339
+ /**
340
+ * A function that will be called to get the key for the scroll restoration cache.
341
+ *
342
+ * @default (location) => location.href
343
+ */
344
+ getScrollRestorationKey?: (location: ParsedLocation) => string
345
+ /**
346
+ * The default behavior for scroll restoration.
347
+ *
348
+ * @default 'auto'
349
+ */
350
+ scrollRestorationBehavior?: ScrollBehavior
351
+ /**
352
+ * An array of selectors that will be used to scroll to the top of the page in addition to `window`
353
+ *
354
+ * @default ['window']
355
+ */
356
+ scrollToTopSelectors?: Array<string>
357
+ }
358
+
359
+ export interface RouterState<
360
+ in out TRouteTree extends AnyRoute = AnyRoute,
361
+ in out TRouteMatch = MakeRouteMatchUnion,
362
+ > {
363
+ status: 'pending' | 'idle'
364
+ loadedAt: number
365
+ isLoading: boolean
366
+ isTransitioning: boolean
367
+ matches: Array<TRouteMatch>
368
+ pendingMatches?: Array<TRouteMatch>
369
+ cachedMatches: Array<TRouteMatch>
370
+ location: ParsedLocation<FullSearchSchema<TRouteTree>>
371
+ resolvedLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>
372
+ statusCode: number
373
+ redirect?: ResolvedRedirect
374
+ }
375
+
376
+ export interface BuildNextOptions {
377
+ to?: string | number | null
378
+ params?: true | Updater<unknown>
379
+ search?: true | Updater<unknown>
380
+ hash?: true | Updater<string>
381
+ state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
382
+ mask?: {
383
+ to?: string | number | null
384
+ params?: true | Updater<unknown>
385
+ search?: true | Updater<unknown>
386
+ hash?: true | Updater<string>
387
+ state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
388
+ unmaskOnReload?: boolean
389
+ }
390
+ from?: string
391
+ _fromLocation?: ParsedLocation
392
+ href?: string
393
+ }
394
+
395
+ type NavigationEventInfo = {
396
+ fromLocation?: ParsedLocation
397
+ toLocation: ParsedLocation
398
+ pathChanged: boolean
399
+ hrefChanged: boolean
400
+ hashChanged: boolean
401
+ }
402
+
403
+ export type RouterEvents = {
404
+ onBeforeNavigate: {
405
+ type: 'onBeforeNavigate'
406
+ } & NavigationEventInfo
407
+ onBeforeLoad: {
408
+ type: 'onBeforeLoad'
409
+ } & NavigationEventInfo
410
+ onLoad: {
411
+ type: 'onLoad'
412
+ } & NavigationEventInfo
413
+ onResolved: {
414
+ type: 'onResolved'
415
+ } & NavigationEventInfo
416
+ onBeforeRouteMount: {
417
+ type: 'onBeforeRouteMount'
418
+ } & NavigationEventInfo
419
+ onInjectedHtml: {
420
+ type: 'onInjectedHtml'
421
+ promise: Promise<string>
422
+ }
423
+ onRendered: {
424
+ type: 'onRendered'
425
+ } & NavigationEventInfo
426
+ }
427
+
428
+ export type RouterEvent = RouterEvents[keyof RouterEvents]
429
+
430
+ export type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void
431
+
432
+ export type RouterListener<TRouterEvent extends RouterEvent> = {
433
+ eventType: TRouterEvent['type']
434
+ fn: ListenerFn<TRouterEvent>
435
+ }
436
+
437
+ export interface MatchRoutesOpts {
438
+ preload?: boolean
439
+ throwOnError?: boolean
440
+ _buildLocation?: boolean
441
+ dest?: BuildNextOptions
442
+ }
443
+
444
+ export type InferRouterContext<TRouteTree extends AnyRoute> =
445
+ TRouteTree['types']['routerContext']
446
+
447
+ export type RouterContextOptions<TRouteTree extends AnyRoute> =
448
+ AnyContext extends InferRouterContext<TRouteTree>
449
+ ? {
450
+ context?: InferRouterContext<TRouteTree>
451
+ }
452
+ : {
453
+ context: InferRouterContext<TRouteTree>
454
+ }
455
+
456
+ export type RouterConstructorOptions<
457
+ TRouteTree extends AnyRoute,
458
+ TTrailingSlashOption extends TrailingSlashOption,
459
+ TDefaultStructuralSharingOption extends boolean,
460
+ TRouterHistory extends RouterHistory,
461
+ TDehydrated extends Record<string, any>,
462
+ > = Omit<
463
+ RouterOptions<
464
+ TRouteTree,
465
+ TTrailingSlashOption,
466
+ TDefaultStructuralSharingOption,
467
+ TRouterHistory,
468
+ TDehydrated
469
+ >,
470
+ 'context'
471
+ > &
472
+ RouterContextOptions<TRouteTree>
473
+
474
+ export interface RouterErrorSerializer<TSerializedError> {
475
+ serialize: (err: unknown) => TSerializedError
476
+ deserialize: (err: TSerializedError) => unknown
477
+ }
478
+
479
+ export interface MatchedRoutesResult {
480
+ matchedRoutes: Array<AnyRoute>
481
+ routeParams: Record<string, string>
482
+ }
483
+
484
+ export type PreloadRouteFn<
485
+ TRouteTree extends AnyRoute,
486
+ TTrailingSlashOption extends TrailingSlashOption,
487
+ TDefaultStructuralSharingOption extends boolean,
488
+ TRouterHistory extends RouterHistory,
489
+ > = <
490
+ TFrom extends RoutePaths<TRouteTree> | string = string,
491
+ TTo extends string | undefined = undefined,
492
+ TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
493
+ TMaskTo extends string = '',
494
+ >(
495
+ opts: NavigateOptions<
496
+ Router<
497
+ TRouteTree,
498
+ TTrailingSlashOption,
499
+ TDefaultStructuralSharingOption,
500
+ TRouterHistory
501
+ >,
502
+ TFrom,
503
+ TTo,
504
+ TMaskFrom,
505
+ TMaskTo
506
+ >,
507
+ ) => Promise<Array<AnyRouteMatch> | undefined>
508
+
509
+ export type MatchRouteFn<
510
+ TRouteTree extends AnyRoute,
511
+ TTrailingSlashOption extends TrailingSlashOption,
512
+ TDefaultStructuralSharingOption extends boolean,
513
+ TRouterHistory extends RouterHistory,
514
+ > = <
515
+ TFrom extends RoutePaths<TRouteTree> = '/',
516
+ TTo extends string | undefined = undefined,
517
+ TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,
518
+ >(
519
+ location: ToOptions<
520
+ Router<
521
+ TRouteTree,
522
+ TTrailingSlashOption,
523
+ TDefaultStructuralSharingOption,
524
+ TRouterHistory
525
+ >,
526
+ TFrom,
527
+ TTo
528
+ >,
529
+ opts?: MatchRouteOptions,
530
+ ) => false | RouteById<TRouteTree, TResolved>['types']['allParams']
531
+
532
+ export type UpdateFn<
533
+ TRouteTree extends AnyRoute,
534
+ TTrailingSlashOption extends TrailingSlashOption,
535
+ TDefaultStructuralSharingOption extends boolean,
536
+ TRouterHistory extends RouterHistory,
537
+ TDehydrated extends Record<string, any>,
538
+ > = (
539
+ newOptions: RouterConstructorOptions<
540
+ TRouteTree,
541
+ TTrailingSlashOption,
542
+ TDefaultStructuralSharingOption,
543
+ TRouterHistory,
544
+ TDehydrated
545
+ >,
546
+ ) => void
547
+
548
+ export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
549
+ filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
550
+ sync?: boolean
551
+ }) => Promise<void>
552
+
553
+ export type ParseLocationFn<TRouteTree extends AnyRoute> = (
554
+ previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>,
555
+ locationToParse?: HistoryLocation,
556
+ ) => ParsedLocation<FullSearchSchema<TRouteTree>>
557
+
558
+ export type GetMatchRoutesFn = (
559
+ next: ParsedLocation,
560
+ dest?: BuildNextOptions,
561
+ ) => {
562
+ matchedRoutes: Array<AnyRoute>
563
+ routeParams: Record<string, string>
564
+ foundRoute: AnyRoute | undefined
565
+ }
566
+
567
+ export type EmitFn = (routerEvent: RouterEvent) => void
568
+
569
+ export type LoadFn = (opts?: { sync?: boolean }) => Promise<void>
570
+
571
+ export type CommitLocationFn = ({
572
+ viewTransition,
573
+ ignoreBlocker,
574
+ ...next
575
+ }: ParsedLocation & CommitLocationOptions) => Promise<void>
576
+
577
+ export type StartTransitionFn = (fn: () => void) => void
578
+
579
+ export type SubscribeFn = <TType extends keyof RouterEvents>(
580
+ eventType: TType,
581
+ fn: ListenerFn<RouterEvents[TType]>,
582
+ ) => () => void
583
+
584
+ export interface MatchRoutesFn {
585
+ (
586
+ pathname: string,
587
+ locationSearch: AnySchema,
588
+ opts?: MatchRoutesOpts,
589
+ ): Array<AnyRouteMatch>
590
+ (next: ParsedLocation, opts?: MatchRoutesOpts): Array<AnyRouteMatch>
591
+ (
592
+ pathnameOrNext: string | ParsedLocation,
593
+ locationSearchOrOpts?: AnySchema | MatchRoutesOpts,
594
+ opts?: MatchRoutesOpts,
595
+ ): Array<AnyRouteMatch>
596
+ }
597
+
598
+ export type GetMatchFn = (matchId: string) => AnyRouteMatch | undefined
599
+
600
+ export type UpdateMatchFn = (
601
+ id: string,
602
+ updater: (match: AnyRouteMatch) => AnyRouteMatch,
603
+ ) => AnyRouteMatch
604
+
605
+ export type LoadRouteChunkFn = (route: AnyRoute) => Promise<Array<void>>
606
+
607
+ export type ResolveRedirect = (err: AnyRedirect) => ResolvedRedirect
608
+
609
+ export type ClearCacheFn<TRouter extends AnyRouter> = (opts?: {
610
+ filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
611
+ }) => void
612
+
613
+ export interface ServerSrr {
614
+ injectedHtml: Array<InjectedHtmlEntry>
615
+ injectHtml: (getHtml: () => string | Promise<string>) => Promise<void>
616
+ injectScript: (
617
+ getScript: () => string | Promise<string>,
618
+ opts?: { logScript?: boolean },
619
+ ) => Promise<void>
620
+ streamValue: (key: string, value: any) => void
621
+ streamedKeys: Set<string>
622
+ onMatchSettled: (opts: { router: AnyRouter; match: AnyRouteMatch }) => any
20
623
  }
21
624
 
22
625
  export interface Router<
23
626
  in out TRouteTree extends AnyRoute,
24
627
  in out TTrailingSlashOption extends TrailingSlashOption,
628
+ in out TDefaultStructuralSharingOption extends boolean,
629
+ in out TRouterHistory extends RouterHistory = RouterHistory,
630
+ in out TDehydrated extends Record<string, any> = Record<string, any>,
25
631
  > {
26
632
  routeTree: TRouteTree
27
- options: RouterOptions<TTrailingSlashOption>
633
+ options: RouterOptions<
634
+ TRouteTree,
635
+ TTrailingSlashOption,
636
+ TDefaultStructuralSharingOption,
637
+ TRouterHistory,
638
+ TDehydrated
639
+ >
640
+ __store: Store<RouterState<TRouteTree>>
641
+ navigate: NavigateFn
642
+ history: TRouterHistory
643
+ state: RouterState<TRouteTree>
644
+ isServer: boolean
645
+ clientSsr?: {
646
+ getStreamedValue: <T>(key: string) => T | undefined
647
+ }
648
+ looseRoutesById: Record<string, AnyRoute>
649
+ latestLocation: ParsedLocation<FullSearchSchema<TRouteTree>>
650
+ isScrollRestoring: boolean
651
+ resetNextScroll: boolean
652
+ isScrollRestorationSetup: boolean
653
+ ssr?: {
654
+ manifest: Manifest | undefined
655
+ serializer: StartSerializer
656
+ }
657
+ serverSsr?: ServerSrr
658
+ basepath: string
659
+ routesById: RoutesById<TRouteTree>
660
+ routesByPath: RoutesByPath<TRouteTree>
661
+ flatRoutes: Array<AnyRoute>
662
+ parseLocation: ParseLocationFn<TRouteTree>
663
+ getMatchedRoutes: GetMatchRoutesFn
664
+ emit: EmitFn
665
+ load: LoadFn
666
+ commitLocation: CommitLocationFn
667
+ buildLocation: BuildLocationFn
668
+ startTransition: StartTransitionFn
669
+ subscribe: SubscribeFn
670
+ matchRoutes: MatchRoutesFn
671
+ preloadRoute: PreloadRouteFn<
672
+ TRouteTree,
673
+ TTrailingSlashOption,
674
+ TDefaultStructuralSharingOption,
675
+ TRouterHistory
676
+ >
677
+ getMatch: GetMatchFn
678
+ updateMatch: UpdateMatchFn
679
+ matchRoute: MatchRouteFn<
680
+ TRouteTree,
681
+ TTrailingSlashOption,
682
+ TDefaultStructuralSharingOption,
683
+ TRouterHistory
684
+ >
685
+ update: UpdateFn<
686
+ TRouteTree,
687
+ TTrailingSlashOption,
688
+ TDefaultStructuralSharingOption,
689
+ TRouterHistory,
690
+ TDehydrated
691
+ >
692
+ invalidate: InvalidateFn<
693
+ Router<
694
+ TRouteTree,
695
+ TTrailingSlashOption,
696
+ TDefaultStructuralSharingOption,
697
+ TRouterHistory,
698
+ TDehydrated
699
+ >
700
+ >
701
+ loadRouteChunk: LoadRouteChunkFn
702
+ resolveRedirect: ResolveRedirect
703
+ buildRouteTree: () => void
704
+ clearCache: ClearCacheFn<
705
+ Router<
706
+ TRouteTree,
707
+ TTrailingSlashOption,
708
+ TDefaultStructuralSharingOption,
709
+ TRouterHistory,
710
+ TDehydrated
711
+ >
712
+ >
28
713
  }
29
714
 
30
715
  export type AnyRouterWithContext<TContext> = Router<
31
716
  AnyRouteWithContext<TContext>,
717
+ any,
718
+ any,
719
+ any,
32
720
  any
33
721
  >
34
722
 
35
- export type AnyRouter = Router<any, any>
723
+ export type AnyRouter = Router<any, any, any, any, any>
36
724
 
37
725
  export interface ViewTransitionOptions {
38
726
  types: Array<string>