@tanstack/react-router 0.0.1-beta.23 → 0.0.1-beta.230

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +123 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +232 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +158 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/awaited.js +43 -0
  11. package/build/cjs/awaited.js.map +1 -0
  12. package/build/cjs/defer.js +37 -0
  13. package/build/cjs/defer.js.map +1 -0
  14. package/build/cjs/fileRoute.js +27 -0
  15. package/build/cjs/fileRoute.js.map +1 -0
  16. package/build/cjs/index.js +122 -0
  17. package/build/cjs/index.js.map +1 -0
  18. package/build/cjs/lazyRouteComponent.js +54 -0
  19. package/build/cjs/lazyRouteComponent.js.map +1 -0
  20. package/build/cjs/link.js +148 -0
  21. package/build/cjs/link.js.map +1 -0
  22. package/build/cjs/path.js +209 -0
  23. package/build/cjs/path.js.map +1 -0
  24. package/build/cjs/qss.js +63 -0
  25. package/build/cjs/qss.js.map +1 -0
  26. package/build/cjs/redirects.js +25 -0
  27. package/build/cjs/redirects.js.map +1 -0
  28. package/build/cjs/route.js +134 -0
  29. package/build/cjs/route.js.map +1 -0
  30. package/build/cjs/router.js +1099 -0
  31. package/build/cjs/router.js.map +1 -0
  32. package/build/cjs/scroll-restoration.js +179 -0
  33. package/build/cjs/scroll-restoration.js.map +1 -0
  34. package/build/cjs/searchParams.js +81 -0
  35. package/build/cjs/searchParams.js.map +1 -0
  36. package/build/cjs/useBlocker.js +61 -0
  37. package/build/cjs/useBlocker.js.map +1 -0
  38. package/build/cjs/useNavigate.js +75 -0
  39. package/build/cjs/useNavigate.js.map +1 -0
  40. package/build/cjs/useParams.js +26 -0
  41. package/build/cjs/useParams.js.map +1 -0
  42. package/build/cjs/useSearch.js +25 -0
  43. package/build/cjs/useSearch.js.map +1 -0
  44. package/build/cjs/utils.js +239 -0
  45. package/build/cjs/utils.js.map +1 -0
  46. package/build/esm/index.js +2149 -2560
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +3498 -2694
  49. package/build/stats-react.json +927 -42
  50. package/build/types/CatchBoundary.d.ts +33 -0
  51. package/build/types/Matches.d.ts +57 -0
  52. package/build/types/RouterProvider.d.ts +41 -0
  53. package/build/types/awaited.d.ts +9 -0
  54. package/build/types/defer.d.ts +19 -0
  55. package/build/types/fileRoute.d.ts +35 -0
  56. package/build/types/history.d.ts +7 -0
  57. package/build/types/index.d.ts +27 -108
  58. package/build/types/injectHtml.d.ts +0 -0
  59. package/build/types/lazyRouteComponent.d.ts +2 -0
  60. package/build/types/link.d.ts +105 -0
  61. package/build/types/location.d.ts +14 -0
  62. package/build/types/path.d.ts +16 -0
  63. package/build/types/qss.d.ts +2 -0
  64. package/build/types/redirects.d.ts +10 -0
  65. package/build/types/route.d.ts +278 -0
  66. package/build/types/routeInfo.d.ts +22 -0
  67. package/build/types/router.d.ts +167 -0
  68. package/build/types/scroll-restoration.d.ts +6 -0
  69. package/build/types/searchParams.d.ts +7 -0
  70. package/build/types/useBlocker.d.ts +8 -0
  71. package/build/types/useNavigate.d.ts +20 -0
  72. package/build/types/useParams.d.ts +7 -0
  73. package/build/types/useSearch.d.ts +7 -0
  74. package/build/types/utils.d.ts +66 -0
  75. package/build/umd/index.development.js +2443 -2515
  76. package/build/umd/index.development.js.map +1 -1
  77. package/build/umd/index.production.js +4 -4
  78. package/build/umd/index.production.js.map +1 -1
  79. package/package.json +9 -10
  80. package/src/CatchBoundary.tsx +98 -0
  81. package/src/Matches.tsx +387 -0
  82. package/src/RouterProvider.tsx +224 -0
  83. package/src/awaited.tsx +40 -0
  84. package/src/defer.ts +55 -0
  85. package/src/fileRoute.ts +154 -0
  86. package/src/history.ts +8 -0
  87. package/src/index.tsx +28 -709
  88. package/src/injectHtml.ts +28 -0
  89. package/src/lazyRouteComponent.tsx +33 -0
  90. package/src/link.tsx +508 -0
  91. package/src/location.ts +15 -0
  92. package/src/path.ts +256 -0
  93. package/src/qss.ts +53 -0
  94. package/src/redirects.ts +31 -0
  95. package/src/route.ts +861 -0
  96. package/src/routeInfo.ts +68 -0
  97. package/src/router.ts +1660 -0
  98. package/src/scroll-restoration.tsx +192 -0
  99. package/src/searchParams.ts +79 -0
  100. package/src/useBlocker.tsx +34 -0
  101. package/src/useNavigate.tsx +109 -0
  102. package/src/useParams.tsx +25 -0
  103. package/src/useSearch.tsx +25 -0
  104. package/src/utils.ts +350 -0
  105. package/build/cjs/react-router/src/index.js +0 -473
  106. package/build/cjs/react-router/src/index.js.map +0 -1
  107. package/build/cjs/router-core/build/esm/index.js +0 -2527
  108. package/build/cjs/router-core/build/esm/index.js.map +0 -1
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.23",
4
+ "version": "0.0.1-beta.230",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
- "homepage": "https://tanstack.com/router/",
7
+ "homepage": "https://tanstack.com/router",
8
8
  "description": "",
9
9
  "publishConfig": {
10
10
  "registry": "https://registry.npmjs.org/"
@@ -12,7 +12,6 @@
12
12
  "keywords": [
13
13
  "react",
14
14
  "location",
15
- "@tanstack/react-router",
16
15
  "router",
17
16
  "routing",
18
17
  "async",
@@ -24,7 +23,7 @@
24
23
  "url": "https://github.com/sponsors/tannerlinsley"
25
24
  },
26
25
  "module": "build/esm/index.js",
27
- "main": "build/cjs/react-router/src/index.js",
26
+ "main": "build/cjs/index.js",
28
27
  "browser": "build/umd/index.production.js",
29
28
  "types": "build/types/index.d.ts",
30
29
  "engines": {
@@ -41,11 +40,11 @@
41
40
  },
42
41
  "dependencies": {
43
42
  "@babel/runtime": "^7.16.7",
44
- "@tanstack/router-core": "0.0.1-beta.23",
45
- "use-sync-external-store": "^1.2.0"
43
+ "tiny-invariant": "^1.3.1",
44
+ "tiny-warning": "^1.0.3",
45
+ "@tanstack/history": "0.0.1-beta.230"
46
46
  },
47
- "devDependencies": {
48
- "@types/use-sync-external-store": "^0.0.3",
49
- "babel-plugin-transform-async-to-promises": "^0.8.18"
47
+ "scripts": {
48
+ "build": "rollup --config rollup.config.js"
50
49
  }
51
- }
50
+ }
@@ -0,0 +1,98 @@
1
+ import * as React from 'react'
2
+
3
+ export function CatchBoundary(props: {
4
+ resetKey: string
5
+ children: any
6
+ errorComponent?: any
7
+ onCatch: (error: any) => void
8
+ }) {
9
+ const errorComponent = props.errorComponent ?? ErrorComponent
10
+
11
+ return (
12
+ <CatchBoundaryImpl
13
+ resetKey={props.resetKey}
14
+ onCatch={props.onCatch}
15
+ children={({ error }) => {
16
+ if (error) {
17
+ return React.createElement(errorComponent, {
18
+ error,
19
+ })
20
+ }
21
+
22
+ return props.children
23
+ }}
24
+ />
25
+ )
26
+ }
27
+
28
+ export class CatchBoundaryImpl extends React.Component<{
29
+ resetKey: string
30
+ children: (props: { error: any; reset: () => void }) => any
31
+ onCatch?: (error: any) => void
32
+ }> {
33
+ state = { error: null } as any
34
+ static getDerivedStateFromError(error: any) {
35
+ return { error }
36
+ }
37
+ componentDidUpdate(
38
+ prevProps: Readonly<{
39
+ resetKey: string
40
+ children: (props: { error: any; reset: () => void }) => any
41
+ onCatch?: ((error: any, info: any) => void) | undefined
42
+ }>,
43
+ prevState: any,
44
+ ): void {
45
+ if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
46
+ this.setState({ error: null })
47
+ }
48
+ }
49
+ componentDidCatch(error: any) {
50
+ console.error(error)
51
+ this.props.onCatch?.(error)
52
+ }
53
+ render() {
54
+ return this.props.children(this.state)
55
+ }
56
+ }
57
+
58
+ export function ErrorComponent({ error }: { error: any }) {
59
+ const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production')
60
+
61
+ return (
62
+ <div style={{ padding: '.5rem', maxWidth: '100%' }}>
63
+ <div style={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>
64
+ <strong style={{ fontSize: '1rem' }}>Something went wrong!</strong>
65
+ <button
66
+ style={{
67
+ appearance: 'none',
68
+ fontSize: '.6em',
69
+ border: '1px solid currentColor',
70
+ padding: '.1rem .2rem',
71
+ fontWeight: 'bold',
72
+ borderRadius: '.25rem',
73
+ }}
74
+ onClick={() => setShow((d) => !d)}
75
+ >
76
+ {show ? 'Hide Error' : 'Show Error'}
77
+ </button>
78
+ </div>
79
+ <div style={{ height: '.25rem' }} />
80
+ {show ? (
81
+ <div>
82
+ <pre
83
+ style={{
84
+ fontSize: '.7em',
85
+ border: '1px solid red',
86
+ borderRadius: '.25rem',
87
+ padding: '.3rem',
88
+ color: 'red',
89
+ overflow: 'auto',
90
+ }}
91
+ >
92
+ {error.message ? <code>{error.message}</code> : null}
93
+ </pre>
94
+ </div>
95
+ ) : null}
96
+ </div>
97
+ )
98
+ }
@@ -0,0 +1,387 @@
1
+ import * as React from 'react'
2
+ import invariant from 'tiny-invariant'
3
+ import warning from 'tiny-warning'
4
+ import { CatchBoundary, ErrorComponent } from './CatchBoundary'
5
+ import { useRouter, useRouterState } from './RouterProvider'
6
+ import { ResolveRelativePath, ToOptions } from './link'
7
+ import { AnyRoute, ReactNode, rootRouteId } from './route'
8
+ import {
9
+ FullSearchSchema,
10
+ ParseRoute,
11
+ RouteById,
12
+ RouteByPath,
13
+ RouteIds,
14
+ RoutePaths,
15
+ } from './routeInfo'
16
+ import { RegisteredRouter } from './router'
17
+ import { NoInfer, StrictOrFrom, pick } from './utils'
18
+
19
+ export interface RouteMatch<
20
+ TRouteTree extends AnyRoute = AnyRoute,
21
+ TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
22
+ > {
23
+ id: string
24
+ routeId: TRouteId
25
+ pathname: string
26
+ params: RouteById<TRouteTree, TRouteId>['types']['allParams']
27
+ status: 'pending' | 'success' | 'error'
28
+ isFetching: boolean
29
+ showPending: boolean
30
+ invalid: boolean
31
+ error: unknown
32
+ paramsError: unknown
33
+ searchError: unknown
34
+ updatedAt: number
35
+ loadPromise?: Promise<void>
36
+ loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
37
+ __resolveLoadPromise?: () => void
38
+ context: RouteById<TRouteTree, TRouteId>['types']['allContext']
39
+ search: FullSearchSchema<TRouteTree> &
40
+ RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
41
+ fetchedAt: number
42
+ shouldReloadDeps: any
43
+ abortController: AbortController
44
+ cause: 'enter' | 'stay'
45
+ }
46
+
47
+ export type AnyRouteMatch = RouteMatch<any>
48
+
49
+ export function Matches() {
50
+ const { routesById, state } = useRouter()
51
+ const { matches } = state
52
+
53
+ const locationKey = useRouterState().location.state.key
54
+
55
+ const route = routesById[rootRouteId]!
56
+
57
+ const errorComponent = React.useCallback(
58
+ (props: any) => {
59
+ return React.createElement(ErrorComponent, {
60
+ ...props,
61
+ useMatch: route.useMatch,
62
+ useRouteContext: route.useRouteContext,
63
+ useSearch: route.useSearch,
64
+ useParams: route.useParams,
65
+ })
66
+ },
67
+ [route],
68
+ )
69
+
70
+ return (
71
+ <matchesContext.Provider value={matches}>
72
+ <CatchBoundary
73
+ resetKey={locationKey}
74
+ errorComponent={errorComponent}
75
+ onCatch={() => {
76
+ warning(
77
+ false,
78
+ `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`,
79
+ )
80
+ }}
81
+ >
82
+ {matches.length ? <Match matches={matches} /> : null}
83
+ </CatchBoundary>
84
+ </matchesContext.Provider>
85
+ )
86
+ }
87
+
88
+ function SafeFragment(props: any) {
89
+ return <>{props.children}</>
90
+ }
91
+
92
+ export function Match({ matches }: { matches: RouteMatch[] }) {
93
+ const { options, routesById } = useRouter()
94
+ const match = matches[0]!
95
+ const routeId = match?.routeId
96
+ const route = routesById[routeId]!
97
+ const locationKey = useRouterState().location.state?.key
98
+
99
+ const PendingComponent = (route.options.pendingComponent ??
100
+ options.defaultPendingComponent) as any
101
+
102
+ const pendingElement = PendingComponent
103
+ ? React.createElement(PendingComponent, {
104
+ useMatch: route.useMatch,
105
+ useRouteContext: route.useRouteContext,
106
+ useSearch: route.useSearch,
107
+ useParams: route.useParams,
108
+ })
109
+ : undefined
110
+
111
+ const routeErrorComponent =
112
+ route.options.errorComponent ??
113
+ options.defaultErrorComponent ??
114
+ ErrorComponent
115
+
116
+ const ResolvedSuspenseBoundary =
117
+ route.options.wrapInSuspense ?? pendingElement
118
+ ? React.Suspense
119
+ : SafeFragment
120
+
121
+ const errorComponent = routeErrorComponent
122
+ ? React.useCallback(
123
+ (props: any) => {
124
+ return React.createElement(routeErrorComponent, {
125
+ ...props,
126
+ useMatch: route.useMatch,
127
+ useRouteContext: route.useRouteContext,
128
+ useSearch: route.useSearch,
129
+ useParams: route.useParams,
130
+ })
131
+ },
132
+ [route],
133
+ )
134
+ : undefined
135
+
136
+ const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment
137
+
138
+ return (
139
+ <matchesContext.Provider value={matches}>
140
+ <ResolvedSuspenseBoundary fallback={pendingElement}>
141
+ <ResolvedCatchBoundary
142
+ resetKey={locationKey}
143
+ errorComponent={errorComponent}
144
+ onCatch={() => {
145
+ warning(false, `Error in route match: ${match.id}`)
146
+ }}
147
+ >
148
+ <MatchInner match={match} pendingElement={pendingElement} />
149
+ </ResolvedCatchBoundary>
150
+ </ResolvedSuspenseBoundary>
151
+ </matchesContext.Provider>
152
+ )
153
+ }
154
+ function MatchInner({
155
+ match,
156
+ pendingElement,
157
+ }: {
158
+ match: RouteMatch
159
+ pendingElement: any
160
+ }): any {
161
+ const { options, routesById } = useRouter()
162
+ const route = routesById[match.routeId]!
163
+
164
+ if (match.status === 'error') {
165
+ throw match.error
166
+ }
167
+
168
+ if (match.status === 'pending') {
169
+ if (match.showPending) {
170
+ return pendingElement || null
171
+ }
172
+ throw match.loadPromise
173
+ }
174
+
175
+ if (match.status === 'success') {
176
+ let comp = route.options.component ?? options.defaultComponent
177
+
178
+ if (comp) {
179
+ return React.createElement(comp, {
180
+ useMatch: route.useMatch,
181
+ useRouteContext: route.useRouteContext as any,
182
+ useSearch: route.useSearch,
183
+ useParams: route.useParams as any,
184
+ useLoaderData: route.useLoaderData,
185
+ })
186
+ }
187
+
188
+ return <Outlet />
189
+ }
190
+
191
+ invariant(
192
+ false,
193
+ 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',
194
+ )
195
+ }
196
+
197
+ export function Outlet() {
198
+ const matches = React.useContext(matchesContext).slice(1)
199
+
200
+ if (!matches[0]) {
201
+ return null
202
+ }
203
+
204
+ return <Match matches={matches} />
205
+ }
206
+
207
+ export interface MatchRouteOptions {
208
+ pending?: boolean
209
+ caseSensitive?: boolean
210
+ includeSearch?: boolean
211
+ fuzzy?: boolean
212
+ }
213
+
214
+ export type MakeUseMatchRouteOptions<
215
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
216
+ TFrom extends RoutePaths<TRouteTree> = '/',
217
+ TTo extends string = '',
218
+ TMaskFrom extends RoutePaths<TRouteTree> = '/',
219
+ TMaskTo extends string = '',
220
+ > = ToOptions<AnyRoute, TFrom, TTo, TMaskFrom, TMaskTo> & MatchRouteOptions
221
+
222
+ export function useMatchRoute<
223
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
224
+ >() {
225
+ const { matchRoute } = useRouter()
226
+
227
+ return React.useCallback(
228
+ <
229
+ TFrom extends RoutePaths<TRouteTree> = '/',
230
+ TTo extends string = '',
231
+ TMaskFrom extends RoutePaths<TRouteTree> = '/',
232
+ TMaskTo extends string = '',
233
+ TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,
234
+ >(
235
+ opts: MakeUseMatchRouteOptions<
236
+ TRouteTree,
237
+ TFrom,
238
+ TTo,
239
+ TMaskFrom,
240
+ TMaskTo
241
+ >,
242
+ ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {
243
+ const { pending, caseSensitive, ...rest } = opts
244
+
245
+ return matchRoute(rest as any, {
246
+ pending,
247
+ caseSensitive,
248
+ })
249
+ },
250
+ [],
251
+ )
252
+ }
253
+
254
+ export type MakeMatchRouteOptions<
255
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
256
+ TFrom extends RoutePaths<TRouteTree> = '/',
257
+ TTo extends string = '',
258
+ TMaskFrom extends RoutePaths<TRouteTree> = '/',
259
+ TMaskTo extends string = '',
260
+ > = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &
261
+ MatchRouteOptions & {
262
+ // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
263
+ children?:
264
+ | ((
265
+ params?: RouteByPath<
266
+ TRouteTree,
267
+ ResolveRelativePath<TFrom, NoInfer<TTo>>
268
+ >['types']['allParams'],
269
+ ) => ReactNode)
270
+ | React.ReactNode
271
+ }
272
+
273
+ export function MatchRoute<
274
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
275
+ TFrom extends RoutePaths<TRouteTree> = '/',
276
+ TTo extends string = '',
277
+ TMaskFrom extends RoutePaths<TRouteTree> = '/',
278
+ TMaskTo extends string = '',
279
+ >(
280
+ props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,
281
+ ): any {
282
+ const matchRoute = useMatchRoute()
283
+ const params = matchRoute(props as any)
284
+
285
+ if (typeof props.children === 'function') {
286
+ return (props.children as any)(params)
287
+ }
288
+
289
+ return !!params ? props.children : null
290
+ }
291
+
292
+ export function useMatch<
293
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
294
+ TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
295
+ TStrict extends boolean = true,
296
+ TRouteMatchState = RouteMatch<TRouteTree, TFrom>,
297
+ TSelected = TRouteMatchState,
298
+ >(
299
+ opts: StrictOrFrom<TFrom> & {
300
+ select?: (match: TRouteMatchState) => TSelected
301
+ },
302
+ ): TStrict extends true ? TSelected : TSelected | undefined {
303
+ const nearestMatch = React.useContext(matchesContext)[0]!
304
+ const nearestMatchRouteId = nearestMatch?.routeId
305
+
306
+ const matchRouteId = useRouterState({
307
+ select: (state) => {
308
+ const match = opts?.from
309
+ ? state.matches.find((d) => d.routeId === opts?.from)
310
+ : state.matches.find((d) => d.id === nearestMatch.id)
311
+
312
+ return match!.routeId
313
+ },
314
+ })
315
+
316
+ if (opts?.strict ?? true) {
317
+ invariant(
318
+ nearestMatchRouteId == matchRouteId,
319
+ `useMatch("${
320
+ matchRouteId as string
321
+ }") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${
322
+ matchRouteId as string
323
+ }", { strict: false })' or 'useRoute("${
324
+ matchRouteId as string
325
+ }")' instead?`,
326
+ )
327
+ }
328
+
329
+ const matchSelection = useRouterState({
330
+ select: (state) => {
331
+ const match = opts?.from
332
+ ? state.matches.find((d) => d.routeId === opts?.from)
333
+ : state.matches.find((d) => d.id === nearestMatch.id)
334
+
335
+ invariant(
336
+ match,
337
+ `Could not find ${
338
+ opts?.from
339
+ ? `an active match from "${opts.from}"`
340
+ : 'a nearest match!'
341
+ }`,
342
+ )
343
+
344
+ return opts?.select ? opts.select(match as any) : match
345
+ },
346
+ })
347
+
348
+ return matchSelection as any
349
+ }
350
+
351
+ export const matchesContext = React.createContext<RouteMatch[]>(null!)
352
+
353
+ export function useMatches<T = RouteMatch[]>(opts?: {
354
+ select?: (matches: RouteMatch[]) => T
355
+ }): T {
356
+ const contextMatches = React.useContext(matchesContext)
357
+
358
+ return useRouterState({
359
+ select: (state) => {
360
+ const matches = state.matches.slice(
361
+ state.matches.findIndex((d) => d.id === contextMatches[0]?.id),
362
+ )
363
+ return opts?.select ? opts.select(matches) : (matches as T)
364
+ },
365
+ })
366
+ }
367
+
368
+ export function useLoaderData<
369
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
370
+ TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
371
+ TStrict extends boolean = true,
372
+ TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<
373
+ TRouteTree,
374
+ TFrom
375
+ >,
376
+ TSelected = TRouteMatch['loaderData'],
377
+ >(
378
+ opts: StrictOrFrom<TFrom> & {
379
+ select?: (match: TRouteMatch) => TSelected
380
+ },
381
+ ): TStrict extends true ? TSelected : TSelected | undefined {
382
+ const match = useMatch({ ...opts, select: undefined })!
383
+
384
+ return typeof opts.select === 'function'
385
+ ? opts.select(match?.loaderData)
386
+ : match?.loaderData
387
+ }