@tanstack/react-router 1.112.11 → 1.112.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/cjs/Match.cjs +2 -2
  2. package/dist/cjs/Match.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs.map +1 -1
  4. package/dist/cjs/Matches.d.cts +1 -8
  5. package/dist/cjs/RouterProvider.cjs.map +1 -1
  6. package/dist/cjs/RouterProvider.d.cts +2 -2
  7. package/dist/cjs/Transitioner.cjs +1 -1
  8. package/dist/cjs/Transitioner.cjs.map +1 -1
  9. package/dist/cjs/fileRoute.cjs.map +1 -1
  10. package/dist/cjs/fileRoute.d.cts +4 -7
  11. package/dist/cjs/index.d.cts +4 -6
  12. package/dist/cjs/link.cjs.map +1 -1
  13. package/dist/cjs/link.d.cts +1 -2
  14. package/dist/cjs/not-found.cjs.map +1 -1
  15. package/dist/cjs/not-found.d.cts +1 -2
  16. package/dist/cjs/redirects.cjs.map +1 -1
  17. package/dist/cjs/redirects.d.cts +1 -2
  18. package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
  19. package/dist/cjs/renderRouteNotFound.d.cts +1 -2
  20. package/dist/cjs/route.cjs +15 -23
  21. package/dist/cjs/route.cjs.map +1 -1
  22. package/dist/cjs/route.d.cts +18 -43
  23. package/dist/cjs/router.cjs +18 -20
  24. package/dist/cjs/router.cjs.map +1 -1
  25. package/dist/cjs/router.d.cts +82 -458
  26. package/dist/cjs/routerContext.cjs.map +1 -1
  27. package/dist/cjs/routerContext.d.cts +2 -2
  28. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  29. package/dist/cjs/scroll-restoration.d.cts +1 -2
  30. package/dist/cjs/structuralSharing.d.cts +1 -2
  31. package/dist/cjs/typePrimitives.d.cts +1 -2
  32. package/dist/cjs/useBlocker.cjs.map +1 -1
  33. package/dist/cjs/useBlocker.d.cts +1 -3
  34. package/dist/cjs/useLoaderData.cjs.map +1 -1
  35. package/dist/cjs/useLoaderData.d.cts +1 -2
  36. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  37. package/dist/cjs/useLoaderDeps.d.cts +1 -2
  38. package/dist/cjs/useLocation.cjs.map +1 -1
  39. package/dist/cjs/useLocation.d.cts +1 -1
  40. package/dist/cjs/useMatch.cjs.map +1 -1
  41. package/dist/cjs/useMatch.d.cts +1 -2
  42. package/dist/cjs/useNavigate.cjs.map +1 -1
  43. package/dist/cjs/useNavigate.d.cts +1 -2
  44. package/dist/cjs/useParams.cjs.map +1 -1
  45. package/dist/cjs/useParams.d.cts +1 -2
  46. package/dist/cjs/useRouteContext.cjs.map +1 -1
  47. package/dist/cjs/useRouteContext.d.cts +1 -2
  48. package/dist/cjs/useRouter.cjs.map +1 -1
  49. package/dist/cjs/useRouter.d.cts +1 -1
  50. package/dist/cjs/useRouterState.cjs.map +1 -1
  51. package/dist/cjs/useRouterState.d.cts +1 -1
  52. package/dist/cjs/useSearch.cjs.map +1 -1
  53. package/dist/cjs/useSearch.d.cts +1 -2
  54. package/dist/cjs/utils.d.cts +1 -1
  55. package/dist/esm/Match.js +2 -2
  56. package/dist/esm/Match.js.map +1 -1
  57. package/dist/esm/Matches.d.ts +1 -8
  58. package/dist/esm/Matches.js.map +1 -1
  59. package/dist/esm/RouterProvider.d.ts +2 -2
  60. package/dist/esm/RouterProvider.js.map +1 -1
  61. package/dist/esm/Transitioner.js +1 -1
  62. package/dist/esm/Transitioner.js.map +1 -1
  63. package/dist/esm/fileRoute.d.ts +4 -7
  64. package/dist/esm/fileRoute.js.map +1 -1
  65. package/dist/esm/index.d.ts +4 -6
  66. package/dist/esm/link.d.ts +1 -2
  67. package/dist/esm/link.js.map +1 -1
  68. package/dist/esm/not-found.d.ts +1 -2
  69. package/dist/esm/not-found.js.map +1 -1
  70. package/dist/esm/redirects.d.ts +1 -2
  71. package/dist/esm/redirects.js.map +1 -1
  72. package/dist/esm/renderRouteNotFound.d.ts +1 -2
  73. package/dist/esm/renderRouteNotFound.js.map +1 -1
  74. package/dist/esm/route.d.ts +18 -43
  75. package/dist/esm/route.js +15 -23
  76. package/dist/esm/route.js.map +1 -1
  77. package/dist/esm/router.d.ts +82 -458
  78. package/dist/esm/router.js +18 -20
  79. package/dist/esm/router.js.map +1 -1
  80. package/dist/esm/routerContext.d.ts +2 -2
  81. package/dist/esm/routerContext.js.map +1 -1
  82. package/dist/esm/scroll-restoration.d.ts +1 -2
  83. package/dist/esm/scroll-restoration.js.map +1 -1
  84. package/dist/esm/structuralSharing.d.ts +1 -2
  85. package/dist/esm/typePrimitives.d.ts +1 -2
  86. package/dist/esm/useBlocker.d.ts +1 -3
  87. package/dist/esm/useBlocker.js.map +1 -1
  88. package/dist/esm/useLoaderData.d.ts +1 -2
  89. package/dist/esm/useLoaderData.js.map +1 -1
  90. package/dist/esm/useLoaderDeps.d.ts +1 -2
  91. package/dist/esm/useLoaderDeps.js.map +1 -1
  92. package/dist/esm/useLocation.d.ts +1 -1
  93. package/dist/esm/useLocation.js.map +1 -1
  94. package/dist/esm/useMatch.d.ts +1 -2
  95. package/dist/esm/useMatch.js.map +1 -1
  96. package/dist/esm/useNavigate.d.ts +1 -2
  97. package/dist/esm/useNavigate.js.map +1 -1
  98. package/dist/esm/useParams.d.ts +1 -2
  99. package/dist/esm/useParams.js.map +1 -1
  100. package/dist/esm/useRouteContext.d.ts +1 -2
  101. package/dist/esm/useRouteContext.js.map +1 -1
  102. package/dist/esm/useRouter.d.ts +1 -1
  103. package/dist/esm/useRouter.js.map +1 -1
  104. package/dist/esm/useRouterState.d.ts +1 -1
  105. package/dist/esm/useRouterState.js.map +1 -1
  106. package/dist/esm/useSearch.d.ts +1 -2
  107. package/dist/esm/useSearch.js.map +1 -1
  108. package/dist/esm/utils.d.ts +1 -1
  109. package/package.json +2 -2
  110. package/src/Match.tsx +7 -4
  111. package/src/Matches.tsx +4 -8
  112. package/src/RouterProvider.tsx +2 -8
  113. package/src/Transitioner.tsx +1 -1
  114. package/src/fileRoute.ts +9 -25
  115. package/src/index.tsx +20 -26
  116. package/src/link.tsx +2 -2
  117. package/src/not-found.tsx +1 -2
  118. package/src/redirects.ts +1 -1
  119. package/src/renderRouteNotFound.tsx +1 -2
  120. package/src/route.ts +91 -211
  121. package/src/router.ts +151 -610
  122. package/src/routerContext.tsx +1 -1
  123. package/src/scroll-restoration.tsx +5 -2
  124. package/src/structuralSharing.ts +1 -1
  125. package/src/typePrimitives.ts +2 -2
  126. package/src/useBlocker.tsx +6 -3
  127. package/src/useLoaderData.tsx +2 -1
  128. package/src/useLoaderDeps.tsx +2 -1
  129. package/src/useLocation.tsx +5 -1
  130. package/src/useMatch.tsx +2 -1
  131. package/src/useNavigate.tsx +2 -1
  132. package/src/useParams.tsx +2 -1
  133. package/src/useRouteContext.ts +2 -1
  134. package/src/useRouter.tsx +1 -1
  135. package/src/useRouterState.tsx +5 -1
  136. package/src/useSearch.tsx +2 -1
@@ -1,440 +1,77 @@
1
- import { Store, NoInfer } from '@tanstack/react-store';
2
- import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
3
- import { AnyContext, AnyRedirect, AnyRouteMatch, AnySchema, BuildLocationFn, CommitLocationOptions, ControlledPromise, FullSearchSchema, MakeRemountDepsOptionsUnion, MakeRouteMatch, MakeRouteMatchUnion, Manifest, NavigateFn, NavigateOptions, NonNullableUpdater, ParsedLocation, PickAsRequired, Register, ResolveRelativePath, ResolvedRedirect, RouteById, RoutePaths, RoutesById, RoutesByPath, SearchParser, SearchSerializer, StartSerializer, ToOptions, TrailingSlashOption, Updater, ViewTransitionOptions } from '@tanstack/router-core';
4
- import { AnyRoute, ErrorRouteComponent, NotFoundRouteComponent, RootRoute, RouteComponent, RouteMask } from './route.js';
5
- import { MatchRouteOptions } from './Matches.js';
1
+ import { Store } from '@tanstack/react-store';
2
+ import { RouterHistory } from '@tanstack/history';
3
+ import { AnyRedirect, AnyRoute, AnyRouteMatch, AnyRouter, BuildLocationFn, BuildNextOptions, ClearCacheFn, CommitLocationFn, CommitLocationOptions, ControlledPromise, Router as CoreRouter, EmitFn, FullSearchSchema, GetMatchFn, GetMatchRoutesFn, InjectedHtmlEntry, InvalidateFn, LoadFn, MakeRouteMatch, Manifest, MatchRouteFn, MatchRoutesFn, NavigateFn, ParseLocationFn, ParsedLocation, PickAsRequired, PreloadRouteFn, ResolvedRedirect, RouterConstructorOptions, RouterEvent, RouterListener, RouterOptions, RouterState, RoutesById, RoutesByPath, StartSerializer, StartTransitionFn, SubscribeFn, TrailingSlashOption, UpdateFn, UpdateMatchFn, ViewTransitionOptions } from '@tanstack/router-core';
4
+ import { ErrorRouteComponent, NotFoundRouteComponent, RouteComponent } from './route.js';
6
5
  import { NotFoundError } from './not-found.js';
7
6
  import type * as React from 'react';
8
- declare global {
9
- interface Window {
10
- __TSR_ROUTER__?: AnyRouter;
11
- }
12
- }
13
- export type AnyRouter = Router<any, any, any, any, any, any>;
14
- export type RegisteredRouter = Register extends {
15
- router: infer TRouter extends AnyRouter;
16
- } ? TRouter : AnyRouter;
17
- export type InferRouterContext<TRouteTree extends AnyRoute> = TRouteTree extends RootRoute<any, infer TRouterContext extends AnyContext, any, any, any, any, any, any> ? TRouterContext : AnyContext;
18
- export type ControllablePromise<T = any> = Promise<T> & {
19
- resolve: (value: T) => void;
20
- reject: (value?: any) => void;
21
- };
22
- export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends InferRouterContext<TRouteTree> ? {
23
- context?: InferRouterContext<TRouteTree>;
24
- } : {
25
- context: InferRouterContext<TRouteTree>;
26
- };
27
- export type InjectedHtmlEntry = Promise<string>;
28
- export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>> {
29
- /**
30
- * The history object that will be used to manage the browser history.
31
- *
32
- * If not provided, a new createBrowserHistory instance will be created and used.
33
- *
34
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#history-property)
35
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/history-types)
36
- */
37
- history?: TRouterHistory;
38
- /**
39
- * A function that will be used to stringify search params when generating links.
40
- *
41
- * @default defaultStringifySearch
42
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#stringifysearch-method)
43
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
44
- */
45
- stringifySearch?: SearchSerializer;
46
- /**
47
- * A function that will be used to parse search params when parsing the current location.
48
- *
49
- * @default defaultParseSearch
50
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#parsesearch-method)
51
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
52
- */
53
- parseSearch?: SearchParser;
54
- /**
55
- * If `false`, routes will not be preloaded by default in any way.
56
- *
57
- * If `'intent'`, routes will be preloaded by default when the user hovers over a link or a `touchstart` event is detected on a `<Link>`.
58
- *
59
- * If `'viewport'`, routes will be preloaded by default when they are within the viewport.
60
- *
61
- * @default false
62
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
63
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
64
- */
65
- defaultPreload?: false | 'intent' | 'viewport' | 'render';
66
- /**
67
- * The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
68
- *
69
- * @default 50
70
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloaddelay-property)
71
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#preload-delay)
72
- */
73
- defaultPreloadDelay?: number;
74
- /**
75
- * The default `component` a route should use if no component is provided.
76
- *
77
- * @default Outlet
78
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultcomponent-property)
79
- */
80
- defaultComponent?: RouteComponent;
81
- /**
82
- * The default `errorComponent` a route should use if no error component is provided.
83
- *
84
- * @default ErrorComponent
85
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulterrorcomponent-property)
86
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
87
- */
88
- defaultErrorComponent?: ErrorRouteComponent;
89
- /**
90
- * The default `pendingComponent` a route should use if no pending component is provided.
91
- *
92
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingcomponent-property)
93
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
94
- */
95
- defaultPendingComponent?: RouteComponent;
96
- /**
97
- * The default `pendingMs` a route should use if no pendingMs is provided.
98
- *
99
- * @default 1000
100
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingms-property)
101
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
102
- */
103
- defaultPendingMs?: number;
104
- /**
105
- * The default `pendingMinMs` a route should use if no pendingMinMs is provided.
106
- *
107
- * @default 500
108
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingminms-property)
109
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
110
- */
111
- defaultPendingMinMs?: number;
112
- /**
113
- * 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.
114
- *
115
- * @default 0
116
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultstaletime-property)
117
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
118
- */
119
- defaultStaleTime?: number;
120
- /**
121
- * The default `preloadStaleTime` a route should use if no preloadStaleTime is provided.
122
- *
123
- * @default 30_000 `(30 seconds)`
124
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadstaletime-property)
125
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
126
- */
127
- defaultPreloadStaleTime?: number;
128
- /**
129
- * The default `defaultPreloadGcTime` a route should use if no preloadGcTime is provided.
130
- *
131
- * @default 1_800_000 `(30 minutes)`
132
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadgctime-property)
133
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
134
- */
135
- defaultPreloadGcTime?: number;
136
- /**
137
- * The default `onCatch` handler for errors caught by the Router ErrorBoundary
138
- *
139
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
140
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
141
- */
142
- defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void;
143
- /**
144
- * If `true`, route navigations will called using `document.startViewTransition()`.
145
- *
146
- * If the browser does not support this api, this option will be ignored.
147
- *
148
- * See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
149
- *
150
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property)
151
- */
152
- defaultViewTransition?: boolean | ViewTransitionOptions;
153
- /**
154
- * The default `hashScrollIntoView` a route should use if no hashScrollIntoView is provided while navigating
155
- *
156
- * See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on `ScrollIntoViewOptions`.
157
- *
158
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulthashscrollintoview-property)
159
- */
160
- defaultHashScrollIntoView?: boolean | ScrollIntoViewOptions;
161
- /**
162
- * @default 'fuzzy'
163
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundmode-property)
164
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#the-notfoundmode-option)
165
- */
166
- notFoundMode?: 'root' | 'fuzzy';
167
- /**
168
- * The default `gcTime` a route should use if no gcTime is provided.
169
- *
170
- * @default 1_800_000 `(30 minutes)`
171
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultgctime-property)
172
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
173
- */
174
- defaultGcTime?: number;
175
- /**
176
- * If `true`, all routes will be matched as case-sensitive.
177
- *
178
- * @default false
179
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#casesensitive-property)
180
- */
181
- caseSensitive?: boolean;
182
- /**
183
- *
184
- * The route tree that will be used to configure the router instance.
185
- *
186
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routetree-property)
187
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/routing/route-trees)
188
- */
189
- routeTree?: TRouteTree;
190
- /**
191
- * The basepath for then entire router. This is useful for mounting a router instance at a subpath.
192
- *
193
- * @default '/'
194
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
195
- */
196
- basepath?: string;
197
- /**
198
- * The root context that will be provided to all routes in the route tree.
199
- *
200
- * This can be used to provide a context to all routes in the tree without having to provide it to each route individually.
201
- *
202
- * Optional or required if the root route was created with [`createRootRouteWithContext()`](https://tanstack.com/router/latest/docs/framework/react/api/router/createRootRouteWithContextFunction).
203
- *
204
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#context-property)
205
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/router-context)
206
- */
207
- context?: InferRouterContext<TRouteTree>;
208
- /**
209
- * A function that will be called when the router is dehydrated.
210
- *
211
- * The return value of this function will be serialized and stored in the router's dehydrated state.
212
- *
213
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#dehydrate-method)
214
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
215
- */
216
- dehydrate?: () => TDehydrated;
217
- /**
218
- * A function that will be called when the router is hydrated.
219
- *
220
- * The return value of this function will be serialized and stored in the router's dehydrated state.
221
- *
222
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#hydrate-method)
223
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
224
- */
225
- hydrate?: (dehydrated: TDehydrated) => void;
226
- /**
227
- * An array of route masks that will be used to mask routes in the route tree.
228
- *
229
- * 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.
230
- *
231
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routemasks-property)
232
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking)
233
- */
234
- routeMasks?: Array<RouteMask<TRouteTree>>;
235
- /**
236
- * If `true`, route masks will, by default, be removed when the page is reloaded.
237
- *
238
- * 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.
239
- *
240
- * @default false
241
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#unmaskonreload-property)
242
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking#unmasking-on-page-reload)
243
- */
244
- unmaskOnReload?: boolean;
245
- /**
246
- * A component that will be used to wrap the entire router.
247
- *
248
- * This is useful for providing a context to the entire router.
249
- *
250
- * Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
251
- *
252
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#wrap-property)
253
- */
254
- Wrap?: (props: {
255
- children: any;
256
- }) => React.JSX.Element;
257
- /**
258
- * A component that will be used to wrap the inner contents of the router.
259
- *
260
- * This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.
261
- *
262
- * Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
263
- *
264
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#innerwrap-property)
265
- */
266
- InnerWrap?: (props: {
267
- children: any;
268
- }) => React.JSX.Element;
269
- /**
270
- * Use `notFoundComponent` instead.
271
- *
272
- * @deprecated
273
- * See https://tanstack.com/router/v1/docs/guide/not-found-errors#migrating-from-notfoundroute for more info.
274
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundroute-property)
275
- */
276
- notFoundRoute?: AnyRoute;
277
- /**
278
- * The default `notFoundComponent` a route should use if no notFound component is provided.
279
- *
280
- * @default NotFound
281
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
282
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
283
- */
284
- defaultNotFoundComponent?: NotFoundRouteComponent;
285
- /**
286
- * Configures how trailing slashes are treated.
287
- *
288
- * - `'always'` will add a trailing slash if not present
289
- * - `'never'` will remove the trailing slash if present
290
- * - `'preserve'` will not modify the trailing slash.
291
- *
292
- * @default 'never'
293
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#trailingslash-property)
294
- */
295
- trailingSlash?: TTrailingSlashOption;
296
- /**
297
- * 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.
298
- *
299
- * @default typeof document !== 'undefined'
300
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#isserver-property)
301
- */
302
- isServer?: boolean;
303
- defaultSsr?: boolean;
304
- search?: {
7
+ declare module '@tanstack/router-core' {
8
+ interface RouterOptionsExtensions {
305
9
  /**
306
- * Configures how unknown search params (= not returned by any `validateSearch`) are treated.
10
+ * The default `component` a route should use if no component is provided.
307
11
  *
308
- * @default false
309
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#search.strict-property)
12
+ * @default Outlet
13
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultcomponent-property)
310
14
  */
311
- strict?: boolean;
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
- * Configures which URI characters are allowed in path params that would ordinarily be escaped by encodeURIComponent.
321
- *
322
- * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#pathparamsallowedcharacters-property)
323
- * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/path-params#allowed-characters)
324
- */
325
- pathParamsAllowedCharacters?: Array<';' | ':' | '@' | '&' | '=' | '+' | '$' | ','>;
326
- defaultRemountDeps?: (opts: MakeRemountDepsOptionsUnion<TRouteTree>) => any;
327
- /**
328
- * If `true`, scroll restoration will be enabled
329
- *
330
- * @default false
331
- */
332
- scrollRestoration?: boolean;
333
- /**
334
- * A function that will be called to get the key for the scroll restoration cache.
335
- *
336
- * @default (location) => location.href
337
- */
338
- getScrollRestorationKey?: (location: ParsedLocation) => string;
339
- /**
340
- * The default behavior for scroll restoration.
341
- *
342
- * @default 'auto'
343
- */
344
- scrollRestorationBehavior?: ScrollBehavior;
345
- /**
346
- * An array of selectors that will be used to scroll to the top of the page in addition to `window`
347
- *
348
- * @default ['window']
349
- */
350
- scrollToTopSelectors?: Array<string>;
351
- }
352
- export interface RouterErrorSerializer<TSerializedError> {
353
- serialize: (err: unknown) => TSerializedError;
354
- deserialize: (err: TSerializedError) => unknown;
355
- }
356
- export interface RouterState<TRouteTree extends AnyRoute = AnyRoute, TRouteMatch = MakeRouteMatchUnion> {
357
- status: 'pending' | 'idle';
358
- loadedAt: number;
359
- isLoading: boolean;
360
- isTransitioning: boolean;
361
- matches: Array<TRouteMatch>;
362
- pendingMatches?: Array<TRouteMatch>;
363
- cachedMatches: Array<TRouteMatch>;
364
- location: ParsedLocation<FullSearchSchema<TRouteTree>>;
365
- resolvedLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>;
366
- statusCode: number;
367
- redirect?: ResolvedRedirect;
368
- }
369
- export type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void;
370
- export interface BuildNextOptions {
371
- to?: string | number | null;
372
- params?: true | Updater<unknown>;
373
- search?: true | Updater<unknown>;
374
- hash?: true | Updater<string>;
375
- state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>;
376
- mask?: {
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
- unmaskOnReload?: boolean;
383
- };
384
- from?: string;
385
- _fromLocation?: ParsedLocation;
386
- href?: string;
387
- }
388
- export interface MatchedRoutesResult {
389
- matchedRoutes: Array<AnyRoute>;
390
- routeParams: Record<string, string>;
15
+ defaultComponent?: RouteComponent;
16
+ /**
17
+ * The default `errorComponent` a route should use if no error component is provided.
18
+ *
19
+ * @default ErrorComponent
20
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulterrorcomponent-property)
21
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
22
+ */
23
+ defaultErrorComponent?: ErrorRouteComponent;
24
+ /**
25
+ * The default `pendingComponent` a route should use if no pending component is provided.
26
+ *
27
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingcomponent-property)
28
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
29
+ */
30
+ defaultPendingComponent?: RouteComponent;
31
+ /**
32
+ * The default `notFoundComponent` a route should use if no notFound component is provided.
33
+ *
34
+ * @default NotFound
35
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
36
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
37
+ */
38
+ defaultNotFoundComponent?: NotFoundRouteComponent;
39
+ /**
40
+ * A component that will be used to wrap the entire router.
41
+ *
42
+ * This is useful for providing a context to the entire router.
43
+ *
44
+ * Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
45
+ *
46
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#wrap-property)
47
+ */
48
+ Wrap?: (props: {
49
+ children: any;
50
+ }) => React.JSX.Element;
51
+ /**
52
+ * A component that will be used to wrap the inner contents of the router.
53
+ *
54
+ * This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.
55
+ *
56
+ * Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
57
+ *
58
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#innerwrap-property)
59
+ */
60
+ InnerWrap?: (props: {
61
+ children: any;
62
+ }) => React.JSX.Element;
63
+ /**
64
+ * The default `onCatch` handler for errors caught by the Router ErrorBoundary
65
+ *
66
+ * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
67
+ * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
68
+ */
69
+ defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void;
70
+ }
391
71
  }
392
- export type RouterConstructorOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'context'> & RouterContextOptions<TRouteTree>;
393
72
  export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent", "notFoundComponent"];
394
- type NavigationEventInfo = {
395
- fromLocation?: ParsedLocation;
396
- toLocation: ParsedLocation;
397
- pathChanged: boolean;
398
- hrefChanged: boolean;
399
- hashChanged: boolean;
400
- };
401
- export type RouterEvents = {
402
- onBeforeNavigate: {
403
- type: 'onBeforeNavigate';
404
- } & NavigationEventInfo;
405
- onBeforeLoad: {
406
- type: 'onBeforeLoad';
407
- } & NavigationEventInfo;
408
- onLoad: {
409
- type: 'onLoad';
410
- } & NavigationEventInfo;
411
- onResolved: {
412
- type: 'onResolved';
413
- } & NavigationEventInfo;
414
- onBeforeRouteMount: {
415
- type: 'onBeforeRouteMount';
416
- } & NavigationEventInfo;
417
- onInjectedHtml: {
418
- type: 'onInjectedHtml';
419
- promise: Promise<string>;
420
- };
421
- onRendered: {
422
- type: 'onRendered';
423
- } & NavigationEventInfo;
424
- };
425
- export type RouterEvent = RouterEvents[keyof RouterEvents];
426
- export type RouterListener<TRouterEvent extends RouterEvent> = {
427
- eventType: TRouterEvent['type'];
428
- fn: ListenerFn<TRouterEvent>;
429
- };
430
- export declare function createRouter<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>, TSerializedError extends Record<string, any> = Record<string, any>>(options: undefined extends number ? 'strictNullChecks must be enabled in tsconfig.json' : RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>): Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated, TSerializedError>;
431
- type MatchRoutesOpts = {
432
- preload?: boolean;
433
- throwOnError?: boolean;
434
- _buildLocation?: boolean;
435
- dest?: BuildNextOptions;
436
- };
437
- export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailingSlashOption extends TrailingSlashOption, in out TDefaultStructuralSharingOption extends boolean, in out TRouterHistory extends RouterHistory = RouterHistory, in out TDehydrated extends Record<string, any> = Record<string, any>, in out TSerializedError extends Record<string, any> = Record<string, any>> {
73
+ export declare function createRouter<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>>(options: undefined extends number ? 'strictNullChecks must be enabled in tsconfig.json' : RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>): CoreRouter<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
74
+ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailingSlashOption extends TrailingSlashOption, in out TDefaultStructuralSharingOption extends boolean, in out TRouterHistory extends RouterHistory = RouterHistory, in out TDehydrated extends Record<string, any> = Record<string, any>> implements CoreRouter<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated> {
438
75
  tempLocationKey: string | undefined;
439
76
  resetNextScroll: boolean;
440
77
  shouldViewTransition?: boolean | ViewTransitionOptions;
@@ -458,13 +95,13 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
458
95
  * @deprecated Use the `createRouter` function instead
459
96
  */
460
97
  constructor(options: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>);
461
- startReactTransition: (fn: () => void) => void;
462
- update: (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
98
+ startTransition: StartTransitionFn;
99
+ update: UpdateFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
463
100
  get state(): RouterState<TRouteTree, import('@tanstack/router-core').RouteMatch<any, any, any, any, any, any, any>>;
464
101
  buildRouteTree: () => void;
465
- subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
466
- emit: (routerEvent: RouterEvent) => void;
467
- parseLocation: (previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>, locationToParse?: HistoryLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
102
+ subscribe: SubscribeFn;
103
+ emit: EmitFn;
104
+ parseLocation: ParseLocationFn<TRouteTree>;
468
105
  resolvePathWithBase: (from: string, path: string) => string;
469
106
  get looseRoutesById(): Record<string, AnyRoute>;
470
107
  /**
@@ -476,28 +113,21 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
476
113
  ): Array<AnyRouteMatch>;
477
114
  ```
478
115
  */
479
- matchRoutes(pathname: string, locationSearch: AnySchema, opts?: MatchRoutesOpts): Array<AnyRouteMatch>;
480
- matchRoutes(next: ParsedLocation, opts?: MatchRoutesOpts): Array<AnyRouteMatch>;
116
+ matchRoutes: MatchRoutesFn;
481
117
  private matchRoutesInternal;
482
- getMatchedRoutes: (next: ParsedLocation, dest?: BuildNextOptions) => {
483
- matchedRoutes: AnyRoute[];
484
- routeParams: Record<string, string>;
485
- foundRoute: AnyRoute | undefined;
486
- };
118
+ getMatchedRoutes: GetMatchRoutesFn;
487
119
  cancelMatch: (id: string) => void;
488
120
  cancelMatches: () => void;
489
121
  buildLocation: BuildLocationFn;
490
122
  commitLocationPromise: undefined | ControlledPromise<void>;
491
- commitLocation: ({ viewTransition, ignoreBlocker, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
123
+ commitLocation: CommitLocationFn;
492
124
  buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
493
125
  navigate: NavigateFn;
494
126
  latestLoadPromise: undefined | Promise<void>;
495
- load: (opts?: {
496
- sync?: boolean;
497
- }) => Promise<void>;
127
+ load: LoadFn;
498
128
  startViewTransition: (fn: () => Promise<void>) => void;
499
- updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
500
- getMatch: (matchId: string) => import('@tanstack/router-core').RouteMatch<any, any, any, any, any, any, any> | undefined;
129
+ updateMatch: UpdateMatchFn;
130
+ getMatch: GetMatchFn;
501
131
  loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
502
132
  location: ParsedLocation;
503
133
  matches: Array<AnyRouteMatch>;
@@ -507,18 +137,13 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
507
137
  getMatch?: (matchId: string) => AnyRouteMatch | undefined;
508
138
  sync?: boolean;
509
139
  }) => Promise<Array<MakeRouteMatch>>;
510
- invalidate: <TRouter extends AnyRouter = this>(opts?: {
511
- filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
512
- sync?: boolean;
513
- }) => Promise<void>;
140
+ invalidate: InvalidateFn<Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
514
141
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
515
- clearCache: <TRouter extends AnyRouter = this>(opts?: {
516
- filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
517
- }) => void;
142
+ clearCache: ClearCacheFn<this>;
518
143
  clearExpiredCache: () => void;
519
144
  loadRouteChunk: (route: AnyRoute) => Promise<void[]>;
520
- preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
521
- matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
145
+ preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
146
+ matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
522
147
  ssr?: {
523
148
  manifest: Manifest | undefined;
524
149
  serializer: StartSerializer;
@@ -550,4 +175,3 @@ export declare class SearchParamError extends Error {
550
175
  export declare class PathParamError extends Error {
551
176
  }
552
177
  export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
553
- export {};