@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.
- package/dist/cjs/Match.cjs +2 -2
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +1 -8
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +2 -2
- package/dist/cjs/Transitioner.cjs +1 -1
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +4 -7
- package/dist/cjs/index.d.cts +4 -6
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -2
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +1 -2
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +1 -2
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
- package/dist/cjs/renderRouteNotFound.d.cts +1 -2
- package/dist/cjs/route.cjs +15 -23
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +18 -43
- package/dist/cjs/router.cjs +18 -20
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +82 -458
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +2 -2
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -2
- package/dist/cjs/structuralSharing.d.cts +1 -2
- package/dist/cjs/typePrimitives.d.cts +1 -2
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +1 -3
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +1 -2
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +1 -2
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useLocation.d.cts +1 -1
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +1 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +1 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +1 -2
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +1 -2
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouter.d.cts +1 -1
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useRouterState.d.cts +1 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +1 -2
- package/dist/cjs/utils.d.cts +1 -1
- package/dist/esm/Match.js +2 -2
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +1 -8
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +2 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Transitioner.js +1 -1
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +4 -7
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +4 -6
- package/dist/esm/link.d.ts +1 -2
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/not-found.d.ts +1 -2
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/redirects.d.ts +1 -2
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/renderRouteNotFound.d.ts +1 -2
- package/dist/esm/renderRouteNotFound.js.map +1 -1
- package/dist/esm/route.d.ts +18 -43
- package/dist/esm/route.js +15 -23
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +82 -458
- package/dist/esm/router.js +18 -20
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +2 -2
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -2
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/structuralSharing.d.ts +1 -2
- package/dist/esm/typePrimitives.d.ts +1 -2
- package/dist/esm/useBlocker.d.ts +1 -3
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +1 -2
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +1 -2
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useLocation.d.ts +1 -1
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.d.ts +1 -2
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +1 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +1 -2
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +1 -2
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.d.ts +1 -1
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +1 -1
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +1 -2
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/Match.tsx +7 -4
- package/src/Matches.tsx +4 -8
- package/src/RouterProvider.tsx +2 -8
- package/src/Transitioner.tsx +1 -1
- package/src/fileRoute.ts +9 -25
- package/src/index.tsx +20 -26
- package/src/link.tsx +2 -2
- package/src/not-found.tsx +1 -2
- package/src/redirects.ts +1 -1
- package/src/renderRouteNotFound.tsx +1 -2
- package/src/route.ts +91 -211
- package/src/router.ts +151 -610
- package/src/routerContext.tsx +1 -1
- package/src/scroll-restoration.tsx +5 -2
- package/src/structuralSharing.ts +1 -1
- package/src/typePrimitives.ts +2 -2
- package/src/useBlocker.tsx +6 -3
- package/src/useLoaderData.tsx +2 -1
- package/src/useLoaderDeps.tsx +2 -1
- package/src/useLocation.tsx +5 -1
- package/src/useMatch.tsx +2 -1
- package/src/useNavigate.tsx +2 -1
- package/src/useParams.tsx +2 -1
- package/src/useRouteContext.ts +2 -1
- package/src/useRouter.tsx +1 -1
- package/src/useRouterState.tsx +5 -1
- package/src/useSearch.tsx +2 -1
package/src/router.ts
CHANGED
|
@@ -31,510 +31,132 @@ import { isNotFound } from './not-found'
|
|
|
31
31
|
|
|
32
32
|
import { setupScrollRestoration } from './scroll-restoration'
|
|
33
33
|
import type * as React from 'react'
|
|
34
|
-
import type {
|
|
35
|
-
HistoryLocation,
|
|
36
|
-
HistoryState,
|
|
37
|
-
ParsedHistoryState,
|
|
38
|
-
RouterHistory,
|
|
39
|
-
} from '@tanstack/history'
|
|
40
|
-
import type { NoInfer } from '@tanstack/react-store'
|
|
34
|
+
import type { HistoryLocation, RouterHistory } from '@tanstack/history'
|
|
41
35
|
|
|
42
36
|
import type {
|
|
43
|
-
AnyContext,
|
|
44
37
|
AnyRedirect,
|
|
38
|
+
AnyRoute,
|
|
45
39
|
AnyRouteMatch,
|
|
40
|
+
AnyRouter,
|
|
46
41
|
AnySchema,
|
|
47
42
|
AnyValidator,
|
|
48
43
|
BeforeLoadContextOptions,
|
|
49
44
|
BuildLocationFn,
|
|
45
|
+
BuildNextOptions,
|
|
46
|
+
ClearCacheFn,
|
|
47
|
+
CommitLocationFn,
|
|
50
48
|
CommitLocationOptions,
|
|
51
49
|
ControlledPromise,
|
|
50
|
+
Router as CoreRouter,
|
|
51
|
+
EmitFn,
|
|
52
52
|
FullSearchSchema,
|
|
53
|
+
GetMatchFn,
|
|
54
|
+
GetMatchRoutesFn,
|
|
55
|
+
InjectedHtmlEntry,
|
|
56
|
+
InvalidateFn,
|
|
57
|
+
LoadFn,
|
|
53
58
|
LoaderFnContext,
|
|
54
|
-
MakeRemountDepsOptionsUnion,
|
|
55
59
|
MakeRouteMatch,
|
|
56
60
|
MakeRouteMatchUnion,
|
|
57
61
|
Manifest,
|
|
62
|
+
MatchRouteFn,
|
|
63
|
+
MatchRoutesFn,
|
|
64
|
+
MatchRoutesOpts,
|
|
65
|
+
MatchedRoutesResult,
|
|
58
66
|
NavigateFn,
|
|
59
|
-
|
|
60
|
-
NonNullableUpdater,
|
|
67
|
+
ParseLocationFn,
|
|
61
68
|
ParsedLocation,
|
|
62
69
|
PickAsRequired,
|
|
63
|
-
|
|
64
|
-
ResolveRelativePath,
|
|
70
|
+
PreloadRouteFn,
|
|
65
71
|
ResolvedRedirect,
|
|
66
|
-
RouteById,
|
|
67
72
|
RouteContextOptions,
|
|
68
|
-
|
|
73
|
+
RouterConstructorOptions,
|
|
74
|
+
RouterEvent,
|
|
75
|
+
RouterListener,
|
|
76
|
+
RouterOptions,
|
|
77
|
+
RouterState,
|
|
69
78
|
RoutesById,
|
|
70
79
|
RoutesByPath,
|
|
71
80
|
SearchMiddleware,
|
|
72
|
-
SearchParser,
|
|
73
|
-
SearchSerializer,
|
|
74
81
|
StartSerializer,
|
|
75
|
-
|
|
82
|
+
StartTransitionFn,
|
|
83
|
+
SubscribeFn,
|
|
76
84
|
TrailingSlashOption,
|
|
77
|
-
|
|
85
|
+
UpdateFn,
|
|
86
|
+
UpdateMatchFn,
|
|
78
87
|
ViewTransitionOptions,
|
|
79
88
|
} from '@tanstack/router-core'
|
|
80
89
|
import type {
|
|
81
|
-
AnyRoute,
|
|
82
90
|
ErrorRouteComponent,
|
|
83
91
|
NotFoundRouteComponent,
|
|
84
|
-
RootRoute,
|
|
85
92
|
RouteComponent,
|
|
86
|
-
RouteMask,
|
|
87
93
|
} from './route'
|
|
88
94
|
|
|
89
|
-
import type { MatchRouteOptions } from './Matches'
|
|
90
|
-
|
|
91
95
|
import type { NotFoundError } from './not-found'
|
|
92
96
|
|
|
93
|
-
declare
|
|
94
|
-
interface
|
|
95
|
-
__TSR_ROUTER__?: AnyRouter
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type AnyRouter = Router<any, any, any, any, any, any>
|
|
100
|
-
|
|
101
|
-
export type RegisteredRouter = Register extends {
|
|
102
|
-
router: infer TRouter extends AnyRouter
|
|
103
|
-
}
|
|
104
|
-
? TRouter
|
|
105
|
-
: AnyRouter
|
|
106
|
-
|
|
107
|
-
export type InferRouterContext<TRouteTree extends AnyRoute> =
|
|
108
|
-
TRouteTree extends RootRoute<
|
|
109
|
-
any,
|
|
110
|
-
infer TRouterContext extends AnyContext,
|
|
111
|
-
any,
|
|
112
|
-
any,
|
|
113
|
-
any,
|
|
114
|
-
any,
|
|
115
|
-
any,
|
|
116
|
-
any
|
|
117
|
-
>
|
|
118
|
-
? TRouterContext
|
|
119
|
-
: AnyContext
|
|
120
|
-
|
|
121
|
-
export type ControllablePromise<T = any> = Promise<T> & {
|
|
122
|
-
resolve: (value: T) => void
|
|
123
|
-
reject: (value?: any) => void
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export type RouterContextOptions<TRouteTree extends AnyRoute> =
|
|
127
|
-
AnyContext extends InferRouterContext<TRouteTree>
|
|
128
|
-
? {
|
|
129
|
-
context?: InferRouterContext<TRouteTree>
|
|
130
|
-
}
|
|
131
|
-
: {
|
|
132
|
-
context: InferRouterContext<TRouteTree>
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export type InjectedHtmlEntry = Promise<string>
|
|
136
|
-
|
|
137
|
-
export interface RouterOptions<
|
|
138
|
-
TRouteTree extends AnyRoute,
|
|
139
|
-
TTrailingSlashOption extends TrailingSlashOption,
|
|
140
|
-
TDefaultStructuralSharingOption extends boolean = false,
|
|
141
|
-
TRouterHistory extends RouterHistory = RouterHistory,
|
|
142
|
-
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
143
|
-
> {
|
|
144
|
-
/**
|
|
145
|
-
* The history object that will be used to manage the browser history.
|
|
146
|
-
*
|
|
147
|
-
* If not provided, a new createBrowserHistory instance will be created and used.
|
|
148
|
-
*
|
|
149
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#history-property)
|
|
150
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/history-types)
|
|
151
|
-
*/
|
|
152
|
-
history?: TRouterHistory
|
|
153
|
-
/**
|
|
154
|
-
* A function that will be used to stringify search params when generating links.
|
|
155
|
-
*
|
|
156
|
-
* @default defaultStringifySearch
|
|
157
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#stringifysearch-method)
|
|
158
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
|
|
159
|
-
*/
|
|
160
|
-
stringifySearch?: SearchSerializer
|
|
161
|
-
/**
|
|
162
|
-
* A function that will be used to parse search params when parsing the current location.
|
|
163
|
-
*
|
|
164
|
-
* @default defaultParseSearch
|
|
165
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#parsesearch-method)
|
|
166
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization)
|
|
167
|
-
*/
|
|
168
|
-
parseSearch?: SearchParser
|
|
169
|
-
/**
|
|
170
|
-
* If `false`, routes will not be preloaded by default in any way.
|
|
171
|
-
*
|
|
172
|
-
* If `'intent'`, routes will be preloaded by default when the user hovers over a link or a `touchstart` event is detected on a `<Link>`.
|
|
173
|
-
*
|
|
174
|
-
* If `'viewport'`, routes will be preloaded by default when they are within the viewport.
|
|
175
|
-
*
|
|
176
|
-
* @default false
|
|
177
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreload-property)
|
|
178
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
|
|
179
|
-
*/
|
|
180
|
-
defaultPreload?: false | 'intent' | 'viewport' | 'render'
|
|
181
|
-
/**
|
|
182
|
-
* The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
|
|
183
|
-
*
|
|
184
|
-
* @default 50
|
|
185
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloaddelay-property)
|
|
186
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading#preload-delay)
|
|
187
|
-
*/
|
|
188
|
-
defaultPreloadDelay?: number
|
|
189
|
-
/**
|
|
190
|
-
* The default `component` a route should use if no component is provided.
|
|
191
|
-
*
|
|
192
|
-
* @default Outlet
|
|
193
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultcomponent-property)
|
|
194
|
-
*/
|
|
195
|
-
defaultComponent?: RouteComponent
|
|
196
|
-
/**
|
|
197
|
-
* The default `errorComponent` a route should use if no error component is provided.
|
|
198
|
-
*
|
|
199
|
-
* @default ErrorComponent
|
|
200
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
201
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
202
|
-
*/
|
|
203
|
-
defaultErrorComponent?: ErrorRouteComponent
|
|
204
|
-
/**
|
|
205
|
-
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
206
|
-
*
|
|
207
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
208
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
|
|
209
|
-
*/
|
|
210
|
-
defaultPendingComponent?: RouteComponent
|
|
211
|
-
/**
|
|
212
|
-
* The default `pendingMs` a route should use if no pendingMs is provided.
|
|
213
|
-
*
|
|
214
|
-
* @default 1000
|
|
215
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingms-property)
|
|
216
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
|
|
217
|
-
*/
|
|
218
|
-
defaultPendingMs?: number
|
|
219
|
-
/**
|
|
220
|
-
* The default `pendingMinMs` a route should use if no pendingMinMs is provided.
|
|
221
|
-
*
|
|
222
|
-
* @default 500
|
|
223
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingminms-property)
|
|
224
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#avoiding-pending-component-flash)
|
|
225
|
-
*/
|
|
226
|
-
defaultPendingMinMs?: number
|
|
227
|
-
/**
|
|
228
|
-
* 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.
|
|
229
|
-
*
|
|
230
|
-
* @default 0
|
|
231
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultstaletime-property)
|
|
232
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
|
|
233
|
-
*/
|
|
234
|
-
defaultStaleTime?: number
|
|
235
|
-
/**
|
|
236
|
-
* The default `preloadStaleTime` a route should use if no preloadStaleTime is provided.
|
|
237
|
-
*
|
|
238
|
-
* @default 30_000 `(30 seconds)`
|
|
239
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadstaletime-property)
|
|
240
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
|
|
241
|
-
*/
|
|
242
|
-
defaultPreloadStaleTime?: number
|
|
243
|
-
/**
|
|
244
|
-
* The default `defaultPreloadGcTime` a route should use if no preloadGcTime is provided.
|
|
245
|
-
*
|
|
246
|
-
* @default 1_800_000 `(30 minutes)`
|
|
247
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpreloadgctime-property)
|
|
248
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/preloading)
|
|
249
|
-
*/
|
|
250
|
-
defaultPreloadGcTime?: number
|
|
251
|
-
/**
|
|
252
|
-
* The default `onCatch` handler for errors caught by the Router ErrorBoundary
|
|
253
|
-
*
|
|
254
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
|
|
255
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
|
|
256
|
-
*/
|
|
257
|
-
defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void
|
|
258
|
-
/**
|
|
259
|
-
* If `true`, route navigations will called using `document.startViewTransition()`.
|
|
260
|
-
*
|
|
261
|
-
* If the browser does not support this api, this option will be ignored.
|
|
262
|
-
*
|
|
263
|
-
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
|
|
264
|
-
*
|
|
265
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property)
|
|
266
|
-
*/
|
|
267
|
-
defaultViewTransition?: boolean | ViewTransitionOptions
|
|
268
|
-
/**
|
|
269
|
-
* The default `hashScrollIntoView` a route should use if no hashScrollIntoView is provided while navigating
|
|
270
|
-
*
|
|
271
|
-
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on `ScrollIntoViewOptions`.
|
|
272
|
-
*
|
|
273
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulthashscrollintoview-property)
|
|
274
|
-
*/
|
|
275
|
-
defaultHashScrollIntoView?: boolean | ScrollIntoViewOptions
|
|
276
|
-
/**
|
|
277
|
-
* @default 'fuzzy'
|
|
278
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundmode-property)
|
|
279
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#the-notfoundmode-option)
|
|
280
|
-
*/
|
|
281
|
-
notFoundMode?: 'root' | 'fuzzy'
|
|
282
|
-
/**
|
|
283
|
-
* The default `gcTime` a route should use if no gcTime is provided.
|
|
284
|
-
*
|
|
285
|
-
* @default 1_800_000 `(30 minutes)`
|
|
286
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultgctime-property)
|
|
287
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
|
|
288
|
-
*/
|
|
289
|
-
defaultGcTime?: number
|
|
290
|
-
/**
|
|
291
|
-
* If `true`, all routes will be matched as case-sensitive.
|
|
292
|
-
*
|
|
293
|
-
* @default false
|
|
294
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#casesensitive-property)
|
|
295
|
-
*/
|
|
296
|
-
caseSensitive?: boolean
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
299
|
-
* The route tree that will be used to configure the router instance.
|
|
300
|
-
*
|
|
301
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routetree-property)
|
|
302
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/routing/route-trees)
|
|
303
|
-
*/
|
|
304
|
-
routeTree?: TRouteTree
|
|
305
|
-
/**
|
|
306
|
-
* The basepath for then entire router. This is useful for mounting a router instance at a subpath.
|
|
307
|
-
*
|
|
308
|
-
* @default '/'
|
|
309
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
|
|
310
|
-
*/
|
|
311
|
-
basepath?: string
|
|
312
|
-
/**
|
|
313
|
-
* The root context that will be provided to all routes in the route tree.
|
|
314
|
-
*
|
|
315
|
-
* This can be used to provide a context to all routes in the tree without having to provide it to each route individually.
|
|
316
|
-
*
|
|
317
|
-
* Optional or required if the root route was created with [`createRootRouteWithContext()`](https://tanstack.com/router/latest/docs/framework/react/api/router/createRootRouteWithContextFunction).
|
|
318
|
-
*
|
|
319
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#context-property)
|
|
320
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/router-context)
|
|
321
|
-
*/
|
|
322
|
-
context?: InferRouterContext<TRouteTree>
|
|
323
|
-
/**
|
|
324
|
-
* A function that will be called when the router is dehydrated.
|
|
325
|
-
*
|
|
326
|
-
* The return value of this function will be serialized and stored in the router's dehydrated state.
|
|
327
|
-
*
|
|
328
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#dehydrate-method)
|
|
329
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
|
|
330
|
-
*/
|
|
331
|
-
dehydrate?: () => TDehydrated
|
|
332
|
-
/**
|
|
333
|
-
* A function that will be called when the router is hydrated.
|
|
334
|
-
*
|
|
335
|
-
* The return value of this function will be serialized and stored in the router's dehydrated state.
|
|
336
|
-
*
|
|
337
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#hydrate-method)
|
|
338
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
|
|
339
|
-
*/
|
|
340
|
-
hydrate?: (dehydrated: TDehydrated) => void
|
|
341
|
-
/**
|
|
342
|
-
* An array of route masks that will be used to mask routes in the route tree.
|
|
343
|
-
*
|
|
344
|
-
* 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.
|
|
345
|
-
*
|
|
346
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#routemasks-property)
|
|
347
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking)
|
|
348
|
-
*/
|
|
349
|
-
routeMasks?: Array<RouteMask<TRouteTree>>
|
|
350
|
-
/**
|
|
351
|
-
* If `true`, route masks will, by default, be removed when the page is reloaded.
|
|
352
|
-
*
|
|
353
|
-
* 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.
|
|
354
|
-
*
|
|
355
|
-
* @default false
|
|
356
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#unmaskonreload-property)
|
|
357
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/route-masking#unmasking-on-page-reload)
|
|
358
|
-
*/
|
|
359
|
-
unmaskOnReload?: boolean
|
|
360
|
-
/**
|
|
361
|
-
* A component that will be used to wrap the entire router.
|
|
362
|
-
*
|
|
363
|
-
* This is useful for providing a context to the entire router.
|
|
364
|
-
*
|
|
365
|
-
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
|
366
|
-
*
|
|
367
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#wrap-property)
|
|
368
|
-
*/
|
|
369
|
-
Wrap?: (props: { children: any }) => React.JSX.Element
|
|
370
|
-
/**
|
|
371
|
-
* A component that will be used to wrap the inner contents of the router.
|
|
372
|
-
*
|
|
373
|
-
* 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.
|
|
374
|
-
*
|
|
375
|
-
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
|
376
|
-
*
|
|
377
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#innerwrap-property)
|
|
378
|
-
*/
|
|
379
|
-
InnerWrap?: (props: { children: any }) => React.JSX.Element
|
|
380
|
-
/**
|
|
381
|
-
* Use `notFoundComponent` instead.
|
|
382
|
-
*
|
|
383
|
-
* @deprecated
|
|
384
|
-
* See https://tanstack.com/router/v1/docs/guide/not-found-errors#migrating-from-notfoundroute for more info.
|
|
385
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundroute-property)
|
|
386
|
-
*/
|
|
387
|
-
notFoundRoute?: AnyRoute
|
|
388
|
-
/**
|
|
389
|
-
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
390
|
-
*
|
|
391
|
-
* @default NotFound
|
|
392
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
393
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
394
|
-
*/
|
|
395
|
-
defaultNotFoundComponent?: NotFoundRouteComponent
|
|
396
|
-
/**
|
|
397
|
-
* Configures how trailing slashes are treated.
|
|
398
|
-
*
|
|
399
|
-
* - `'always'` will add a trailing slash if not present
|
|
400
|
-
* - `'never'` will remove the trailing slash if present
|
|
401
|
-
* - `'preserve'` will not modify the trailing slash.
|
|
402
|
-
*
|
|
403
|
-
* @default 'never'
|
|
404
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#trailingslash-property)
|
|
405
|
-
*/
|
|
406
|
-
trailingSlash?: TTrailingSlashOption
|
|
407
|
-
/**
|
|
408
|
-
* 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.
|
|
409
|
-
*
|
|
410
|
-
* @default typeof document !== 'undefined'
|
|
411
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#isserver-property)
|
|
412
|
-
*/
|
|
413
|
-
isServer?: boolean
|
|
414
|
-
|
|
415
|
-
defaultSsr?: boolean
|
|
416
|
-
|
|
417
|
-
search?: {
|
|
97
|
+
declare module '@tanstack/router-core' {
|
|
98
|
+
export interface RouterOptionsExtensions {
|
|
418
99
|
/**
|
|
419
|
-
*
|
|
100
|
+
* The default `component` a route should use if no component is provided.
|
|
420
101
|
*
|
|
421
|
-
* @default
|
|
422
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#
|
|
102
|
+
* @default Outlet
|
|
103
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultcomponent-property)
|
|
423
104
|
*/
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
*/
|
|
469
|
-
scrollToTopSelectors?: Array<string>
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export interface RouterErrorSerializer<TSerializedError> {
|
|
473
|
-
serialize: (err: unknown) => TSerializedError
|
|
474
|
-
deserialize: (err: TSerializedError) => unknown
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
export interface RouterState<
|
|
478
|
-
TRouteTree extends AnyRoute = AnyRoute,
|
|
479
|
-
TRouteMatch = MakeRouteMatchUnion,
|
|
480
|
-
> {
|
|
481
|
-
status: 'pending' | 'idle'
|
|
482
|
-
loadedAt: number
|
|
483
|
-
isLoading: boolean
|
|
484
|
-
isTransitioning: boolean
|
|
485
|
-
matches: Array<TRouteMatch>
|
|
486
|
-
pendingMatches?: Array<TRouteMatch>
|
|
487
|
-
cachedMatches: Array<TRouteMatch>
|
|
488
|
-
location: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
489
|
-
resolvedLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
490
|
-
statusCode: number
|
|
491
|
-
redirect?: ResolvedRedirect
|
|
492
|
-
}
|
|
105
|
+
defaultComponent?: RouteComponent
|
|
106
|
+
/**
|
|
107
|
+
* The default `errorComponent` a route should use if no error component is provided.
|
|
108
|
+
*
|
|
109
|
+
* @default ErrorComponent
|
|
110
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
111
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
112
|
+
*/
|
|
113
|
+
defaultErrorComponent?: ErrorRouteComponent
|
|
114
|
+
/**
|
|
115
|
+
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
116
|
+
*
|
|
117
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
118
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#showing-a-pending-component)
|
|
119
|
+
*/
|
|
120
|
+
defaultPendingComponent?: RouteComponent
|
|
121
|
+
/**
|
|
122
|
+
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
123
|
+
*
|
|
124
|
+
* @default NotFound
|
|
125
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
126
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
127
|
+
*/
|
|
128
|
+
defaultNotFoundComponent?: NotFoundRouteComponent
|
|
129
|
+
/**
|
|
130
|
+
* A component that will be used to wrap the entire router.
|
|
131
|
+
*
|
|
132
|
+
* This is useful for providing a context to the entire router.
|
|
133
|
+
*
|
|
134
|
+
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
|
135
|
+
*
|
|
136
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#wrap-property)
|
|
137
|
+
*/
|
|
138
|
+
Wrap?: (props: { children: any }) => React.JSX.Element
|
|
139
|
+
/**
|
|
140
|
+
* A component that will be used to wrap the inner contents of the router.
|
|
141
|
+
*
|
|
142
|
+
* 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.
|
|
143
|
+
*
|
|
144
|
+
* Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
|
|
145
|
+
*
|
|
146
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#innerwrap-property)
|
|
147
|
+
*/
|
|
148
|
+
InnerWrap?: (props: { children: any }) => React.JSX.Element
|
|
493
149
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
|
|
502
|
-
mask?: {
|
|
503
|
-
to?: string | number | null
|
|
504
|
-
params?: true | Updater<unknown>
|
|
505
|
-
search?: true | Updater<unknown>
|
|
506
|
-
hash?: true | Updater<string>
|
|
507
|
-
state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>
|
|
508
|
-
unmaskOnReload?: boolean
|
|
150
|
+
/**
|
|
151
|
+
* The default `onCatch` handler for errors caught by the Router ErrorBoundary
|
|
152
|
+
*
|
|
153
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)
|
|
154
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)
|
|
155
|
+
*/
|
|
156
|
+
defaultOnCatch?: (error: Error, errorInfo: React.ErrorInfo) => void
|
|
509
157
|
}
|
|
510
|
-
from?: string
|
|
511
|
-
_fromLocation?: ParsedLocation
|
|
512
|
-
href?: string
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export interface MatchedRoutesResult {
|
|
516
|
-
matchedRoutes: Array<AnyRoute>
|
|
517
|
-
routeParams: Record<string, string>
|
|
518
158
|
}
|
|
519
159
|
|
|
520
|
-
export type RouterConstructorOptions<
|
|
521
|
-
TRouteTree extends AnyRoute,
|
|
522
|
-
TTrailingSlashOption extends TrailingSlashOption,
|
|
523
|
-
TDefaultStructuralSharingOption extends boolean,
|
|
524
|
-
TRouterHistory extends RouterHistory,
|
|
525
|
-
TDehydrated extends Record<string, any>,
|
|
526
|
-
> = Omit<
|
|
527
|
-
RouterOptions<
|
|
528
|
-
TRouteTree,
|
|
529
|
-
TTrailingSlashOption,
|
|
530
|
-
TDefaultStructuralSharingOption,
|
|
531
|
-
TRouterHistory,
|
|
532
|
-
TDehydrated
|
|
533
|
-
>,
|
|
534
|
-
'context'
|
|
535
|
-
> &
|
|
536
|
-
RouterContextOptions<TRouteTree>
|
|
537
|
-
|
|
538
160
|
export const componentTypes = [
|
|
539
161
|
'component',
|
|
540
162
|
'errorComponent',
|
|
@@ -579,53 +201,12 @@ function validateSearch(validateSearch: AnyValidator, input: unknown): unknown {
|
|
|
579
201
|
return {}
|
|
580
202
|
}
|
|
581
203
|
|
|
582
|
-
type NavigationEventInfo = {
|
|
583
|
-
fromLocation?: ParsedLocation
|
|
584
|
-
toLocation: ParsedLocation
|
|
585
|
-
pathChanged: boolean
|
|
586
|
-
hrefChanged: boolean
|
|
587
|
-
hashChanged: boolean
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
export type RouterEvents = {
|
|
591
|
-
onBeforeNavigate: {
|
|
592
|
-
type: 'onBeforeNavigate'
|
|
593
|
-
} & NavigationEventInfo
|
|
594
|
-
onBeforeLoad: {
|
|
595
|
-
type: 'onBeforeLoad'
|
|
596
|
-
} & NavigationEventInfo
|
|
597
|
-
onLoad: {
|
|
598
|
-
type: 'onLoad'
|
|
599
|
-
} & NavigationEventInfo
|
|
600
|
-
onResolved: {
|
|
601
|
-
type: 'onResolved'
|
|
602
|
-
} & NavigationEventInfo
|
|
603
|
-
onBeforeRouteMount: {
|
|
604
|
-
type: 'onBeforeRouteMount'
|
|
605
|
-
} & NavigationEventInfo
|
|
606
|
-
onInjectedHtml: {
|
|
607
|
-
type: 'onInjectedHtml'
|
|
608
|
-
promise: Promise<string>
|
|
609
|
-
}
|
|
610
|
-
onRendered: {
|
|
611
|
-
type: 'onRendered'
|
|
612
|
-
} & NavigationEventInfo
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
export type RouterEvent = RouterEvents[keyof RouterEvents]
|
|
616
|
-
|
|
617
|
-
export type RouterListener<TRouterEvent extends RouterEvent> = {
|
|
618
|
-
eventType: TRouterEvent['type']
|
|
619
|
-
fn: ListenerFn<TRouterEvent>
|
|
620
|
-
}
|
|
621
|
-
|
|
622
204
|
export function createRouter<
|
|
623
205
|
TRouteTree extends AnyRoute,
|
|
624
206
|
TTrailingSlashOption extends TrailingSlashOption,
|
|
625
207
|
TDefaultStructuralSharingOption extends boolean,
|
|
626
208
|
TRouterHistory extends RouterHistory = RouterHistory,
|
|
627
209
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
628
|
-
TSerializedError extends Record<string, any> = Record<string, any>,
|
|
629
210
|
>(
|
|
630
211
|
options: undefined extends number
|
|
631
212
|
? 'strictNullChecks must be enabled in tsconfig.json'
|
|
@@ -636,32 +217,37 @@ export function createRouter<
|
|
|
636
217
|
TRouterHistory,
|
|
637
218
|
TDehydrated
|
|
638
219
|
>,
|
|
639
|
-
)
|
|
220
|
+
): CoreRouter<
|
|
221
|
+
TRouteTree,
|
|
222
|
+
TTrailingSlashOption,
|
|
223
|
+
TDefaultStructuralSharingOption,
|
|
224
|
+
TRouterHistory,
|
|
225
|
+
TDehydrated
|
|
226
|
+
> {
|
|
640
227
|
return new Router<
|
|
641
228
|
TRouteTree,
|
|
642
229
|
TTrailingSlashOption,
|
|
643
230
|
TDefaultStructuralSharingOption,
|
|
644
231
|
TRouterHistory,
|
|
645
|
-
TDehydrated
|
|
646
|
-
TSerializedError
|
|
232
|
+
TDehydrated
|
|
647
233
|
>(options)
|
|
648
234
|
}
|
|
649
235
|
|
|
650
|
-
type MatchRoutesOpts = {
|
|
651
|
-
preload?: boolean
|
|
652
|
-
throwOnError?: boolean
|
|
653
|
-
_buildLocation?: boolean
|
|
654
|
-
dest?: BuildNextOptions
|
|
655
|
-
}
|
|
656
|
-
|
|
657
236
|
export class Router<
|
|
658
237
|
in out TRouteTree extends AnyRoute,
|
|
659
238
|
in out TTrailingSlashOption extends TrailingSlashOption,
|
|
660
239
|
in out TDefaultStructuralSharingOption extends boolean,
|
|
661
240
|
in out TRouterHistory extends RouterHistory = RouterHistory,
|
|
662
241
|
in out TDehydrated extends Record<string, any> = Record<string, any>,
|
|
663
|
-
|
|
664
|
-
|
|
242
|
+
> implements
|
|
243
|
+
CoreRouter<
|
|
244
|
+
TRouteTree,
|
|
245
|
+
TTrailingSlashOption,
|
|
246
|
+
TDefaultStructuralSharingOption,
|
|
247
|
+
TRouterHistory,
|
|
248
|
+
TDehydrated
|
|
249
|
+
>
|
|
250
|
+
{
|
|
665
251
|
// Option-independent properties
|
|
666
252
|
tempLocationKey: string | undefined = `${Math.round(
|
|
667
253
|
Math.random() * 10000000,
|
|
@@ -728,17 +314,15 @@ export class Router<
|
|
|
728
314
|
// These are default implementations that can optionally be overridden
|
|
729
315
|
// by the router provider once rendered. We provide these so that the
|
|
730
316
|
// router can be used in a non-react environment if necessary
|
|
731
|
-
|
|
317
|
+
startTransition: StartTransitionFn = (fn) => fn()
|
|
732
318
|
|
|
733
|
-
update
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
>,
|
|
741
|
-
) => {
|
|
319
|
+
update: UpdateFn<
|
|
320
|
+
TRouteTree,
|
|
321
|
+
TTrailingSlashOption,
|
|
322
|
+
TDefaultStructuralSharingOption,
|
|
323
|
+
TRouterHistory,
|
|
324
|
+
TDehydrated
|
|
325
|
+
> = (newOptions) => {
|
|
742
326
|
if (newOptions.notFoundRoute) {
|
|
743
327
|
console.warn(
|
|
744
328
|
'The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info.',
|
|
@@ -950,10 +534,7 @@ export class Router<
|
|
|
950
534
|
})
|
|
951
535
|
}
|
|
952
536
|
|
|
953
|
-
subscribe =
|
|
954
|
-
eventType: TType,
|
|
955
|
-
fn: ListenerFn<RouterEvents[TType]>,
|
|
956
|
-
) => {
|
|
537
|
+
subscribe: SubscribeFn = (eventType, fn) => {
|
|
957
538
|
const listener: RouterListener<any> = {
|
|
958
539
|
eventType,
|
|
959
540
|
fn,
|
|
@@ -966,7 +547,7 @@ export class Router<
|
|
|
966
547
|
}
|
|
967
548
|
}
|
|
968
549
|
|
|
969
|
-
emit = (routerEvent
|
|
550
|
+
emit: EmitFn = (routerEvent) => {
|
|
970
551
|
this.subscribers.forEach((listener) => {
|
|
971
552
|
if (listener.eventType === routerEvent.type) {
|
|
972
553
|
listener.fn(routerEvent)
|
|
@@ -974,10 +555,10 @@ export class Router<
|
|
|
974
555
|
})
|
|
975
556
|
}
|
|
976
557
|
|
|
977
|
-
parseLocation = (
|
|
978
|
-
previousLocation
|
|
979
|
-
locationToParse
|
|
980
|
-
)
|
|
558
|
+
parseLocation: ParseLocationFn<TRouteTree> = (
|
|
559
|
+
previousLocation,
|
|
560
|
+
locationToParse,
|
|
561
|
+
) => {
|
|
981
562
|
const parse = ({
|
|
982
563
|
pathname,
|
|
983
564
|
search,
|
|
@@ -1041,21 +622,11 @@ export class Router<
|
|
|
1041
622
|
): Array<AnyRouteMatch>;
|
|
1042
623
|
```
|
|
1043
624
|
*/
|
|
1044
|
-
|
|
1045
|
-
pathname: string,
|
|
1046
|
-
locationSearch: AnySchema,
|
|
1047
|
-
opts?: MatchRoutesOpts,
|
|
1048
|
-
): Array<AnyRouteMatch>
|
|
1049
|
-
public matchRoutes(
|
|
1050
|
-
next: ParsedLocation,
|
|
1051
|
-
opts?: MatchRoutesOpts,
|
|
1052
|
-
): Array<AnyRouteMatch>
|
|
1053
|
-
|
|
1054
|
-
public matchRoutes(
|
|
625
|
+
matchRoutes: MatchRoutesFn = (
|
|
1055
626
|
pathnameOrNext: string | ParsedLocation,
|
|
1056
627
|
locationSearchOrOpts?: AnySchema | MatchRoutesOpts,
|
|
1057
628
|
opts?: MatchRoutesOpts,
|
|
1058
|
-
) {
|
|
629
|
+
) => {
|
|
1059
630
|
if (typeof pathnameOrNext === 'string') {
|
|
1060
631
|
return this.matchRoutesInternal(
|
|
1061
632
|
{
|
|
@@ -1381,7 +952,7 @@ export class Router<
|
|
|
1381
952
|
return matches
|
|
1382
953
|
}
|
|
1383
954
|
|
|
1384
|
-
getMatchedRoutes = (next
|
|
955
|
+
getMatchedRoutes: GetMatchRoutesFn = (next, dest) => {
|
|
1385
956
|
let routeParams: Record<string, string> = {}
|
|
1386
957
|
const trimmedPath = trimPathRight(next.pathname)
|
|
1387
958
|
const getMatchedParams = (route: AnyRoute) => {
|
|
@@ -1745,11 +1316,11 @@ export class Router<
|
|
|
1745
1316
|
|
|
1746
1317
|
commitLocationPromise: undefined | ControlledPromise<void>
|
|
1747
1318
|
|
|
1748
|
-
commitLocation = ({
|
|
1319
|
+
commitLocation: CommitLocationFn = ({
|
|
1749
1320
|
viewTransition,
|
|
1750
1321
|
ignoreBlocker,
|
|
1751
1322
|
...next
|
|
1752
|
-
}
|
|
1323
|
+
}) => {
|
|
1753
1324
|
const isSameState = () => {
|
|
1754
1325
|
// the following props are ignored but may still be provided when navigating,
|
|
1755
1326
|
// temporarily add the previous values to the next state so they don't affect
|
|
@@ -1889,7 +1460,7 @@ export class Router<
|
|
|
1889
1460
|
|
|
1890
1461
|
latestLoadPromise: undefined | Promise<void>
|
|
1891
1462
|
|
|
1892
|
-
load = async (opts?: { sync?: boolean }): Promise<void> => {
|
|
1463
|
+
load: LoadFn = async (opts?: { sync?: boolean }): Promise<void> => {
|
|
1893
1464
|
this.latestLocation = this.parseLocation(this.latestLocation)
|
|
1894
1465
|
|
|
1895
1466
|
let redirect: ResolvedRedirect | undefined
|
|
@@ -1899,7 +1470,7 @@ export class Router<
|
|
|
1899
1470
|
|
|
1900
1471
|
// eslint-disable-next-line prefer-const
|
|
1901
1472
|
loadPromise = new Promise<void>((resolve) => {
|
|
1902
|
-
this.
|
|
1473
|
+
this.startTransition(async () => {
|
|
1903
1474
|
try {
|
|
1904
1475
|
const next = this.latestLocation
|
|
1905
1476
|
const prevLocation = this.state.resolvedLocation
|
|
@@ -2103,10 +1674,7 @@ export class Router<
|
|
|
2103
1674
|
}
|
|
2104
1675
|
}
|
|
2105
1676
|
|
|
2106
|
-
updateMatch = (
|
|
2107
|
-
id: string,
|
|
2108
|
-
updater: (match: AnyRouteMatch) => AnyRouteMatch,
|
|
2109
|
-
) => {
|
|
1677
|
+
updateMatch: UpdateMatchFn = (id, updater) => {
|
|
2110
1678
|
let updated!: AnyRouteMatch
|
|
2111
1679
|
const isPending = this.state.pendingMatches?.find((d) => d.id === id)
|
|
2112
1680
|
const isMatched = this.state.matches.find((d) => d.id === id)
|
|
@@ -2132,7 +1700,7 @@ export class Router<
|
|
|
2132
1700
|
return updated
|
|
2133
1701
|
}
|
|
2134
1702
|
|
|
2135
|
-
getMatch = (matchId: string) => {
|
|
1703
|
+
getMatch: GetMatchFn = (matchId: string) => {
|
|
2136
1704
|
return [
|
|
2137
1705
|
...this.state.cachedMatches,
|
|
2138
1706
|
...(this.state.pendingMatches ?? []),
|
|
@@ -2318,11 +1886,9 @@ export class Router<
|
|
|
2318
1886
|
const prevLoadPromise = prev.loadPromise
|
|
2319
1887
|
return {
|
|
2320
1888
|
...prev,
|
|
2321
|
-
loadPromise: createControlledPromise<void>(
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
},
|
|
2325
|
-
),
|
|
1889
|
+
loadPromise: createControlledPromise<void>(() => {
|
|
1890
|
+
prevLoadPromise?.resolve()
|
|
1891
|
+
}),
|
|
2326
1892
|
beforeLoadPromise: createControlledPromise<void>(),
|
|
2327
1893
|
}
|
|
2328
1894
|
})
|
|
@@ -2699,12 +2265,17 @@ export class Router<
|
|
|
2699
2265
|
return matches
|
|
2700
2266
|
}
|
|
2701
2267
|
|
|
2702
|
-
invalidate
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2268
|
+
invalidate: InvalidateFn<
|
|
2269
|
+
Router<
|
|
2270
|
+
TRouteTree,
|
|
2271
|
+
TTrailingSlashOption,
|
|
2272
|
+
TDefaultStructuralSharingOption,
|
|
2273
|
+
TRouterHistory,
|
|
2274
|
+
TDehydrated
|
|
2275
|
+
>
|
|
2276
|
+
> = (opts) => {
|
|
2706
2277
|
const invalidate = (d: MakeRouteMatch<TRouteTree>) => {
|
|
2707
|
-
if (opts?.filter?.(d as MakeRouteMatchUnion<
|
|
2278
|
+
if (opts?.filter?.(d as MakeRouteMatchUnion<this>) ?? true) {
|
|
2708
2279
|
return {
|
|
2709
2280
|
...d,
|
|
2710
2281
|
invalid: true,
|
|
@@ -2736,16 +2307,14 @@ export class Router<
|
|
|
2736
2307
|
return redirect
|
|
2737
2308
|
}
|
|
2738
2309
|
|
|
2739
|
-
clearCache
|
|
2740
|
-
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean
|
|
2741
|
-
}) => {
|
|
2310
|
+
clearCache: ClearCacheFn<this> = (opts) => {
|
|
2742
2311
|
const filter = opts?.filter
|
|
2743
2312
|
if (filter !== undefined) {
|
|
2744
2313
|
this.__store.setState((s) => {
|
|
2745
2314
|
return {
|
|
2746
2315
|
...s,
|
|
2747
2316
|
cachedMatches: s.cachedMatches.filter(
|
|
2748
|
-
(m) => !filter(m as MakeRouteMatchUnion<
|
|
2317
|
+
(m) => !filter(m as MakeRouteMatchUnion<this>),
|
|
2749
2318
|
),
|
|
2750
2319
|
}
|
|
2751
2320
|
})
|
|
@@ -2812,27 +2381,12 @@ export class Router<
|
|
|
2812
2381
|
return route._componentsPromise
|
|
2813
2382
|
}
|
|
2814
2383
|
|
|
2815
|
-
preloadRoute
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
>(
|
|
2821
|
-
opts: NavigateOptions<
|
|
2822
|
-
Router<
|
|
2823
|
-
TRouteTree,
|
|
2824
|
-
TTrailingSlashOption,
|
|
2825
|
-
TDefaultStructuralSharingOption,
|
|
2826
|
-
TRouterHistory,
|
|
2827
|
-
TDehydrated,
|
|
2828
|
-
TSerializedError
|
|
2829
|
-
>,
|
|
2830
|
-
TFrom,
|
|
2831
|
-
TTo,
|
|
2832
|
-
TMaskFrom,
|
|
2833
|
-
TMaskTo
|
|
2834
|
-
>,
|
|
2835
|
-
): Promise<Array<AnyRouteMatch> | undefined> => {
|
|
2384
|
+
preloadRoute: PreloadRouteFn<
|
|
2385
|
+
TRouteTree,
|
|
2386
|
+
TTrailingSlashOption,
|
|
2387
|
+
TDefaultStructuralSharingOption,
|
|
2388
|
+
TRouterHistory
|
|
2389
|
+
> = async (opts) => {
|
|
2836
2390
|
const next = this.buildLocation(opts as any)
|
|
2837
2391
|
|
|
2838
2392
|
let matches = this.matchRoutes(next, {
|
|
@@ -2898,25 +2452,12 @@ export class Router<
|
|
|
2898
2452
|
}
|
|
2899
2453
|
}
|
|
2900
2454
|
|
|
2901
|
-
matchRoute
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
Router<
|
|
2908
|
-
TRouteTree,
|
|
2909
|
-
TTrailingSlashOption,
|
|
2910
|
-
TDefaultStructuralSharingOption,
|
|
2911
|
-
TRouterHistory,
|
|
2912
|
-
TDehydrated,
|
|
2913
|
-
TSerializedError
|
|
2914
|
-
>,
|
|
2915
|
-
TFrom,
|
|
2916
|
-
TTo
|
|
2917
|
-
>,
|
|
2918
|
-
opts?: MatchRouteOptions,
|
|
2919
|
-
): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {
|
|
2455
|
+
matchRoute: MatchRouteFn<
|
|
2456
|
+
TRouteTree,
|
|
2457
|
+
TTrailingSlashOption,
|
|
2458
|
+
TDefaultStructuralSharingOption,
|
|
2459
|
+
TRouterHistory
|
|
2460
|
+
> = (location, opts) => {
|
|
2920
2461
|
const matchLocation = {
|
|
2921
2462
|
...location,
|
|
2922
2463
|
to: location.to
|