@tanstack/react-router 1.120.15 → 1.120.16

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.
@@ -0,0 +1,4244 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const content = `# ActiveLinkOptions type
4
+
5
+ The \`ActiveLinkOptions\` type extends the [\`LinkOptions\`](../LinkOptionsType.md) type and contains additional options that can be used to describe how a link should be styled when it is active.
6
+
7
+ \`\`\`tsx
8
+ type ActiveLinkOptions = LinkOptions & {
9
+ activeProps?:
10
+ | React.AnchorHTMLAttributes<HTMLAnchorElement>
11
+ | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)
12
+ inactiveProps?:
13
+ | React.AnchorHTMLAttributes<HTMLAnchorElement>
14
+ | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>)
15
+ }
16
+ \`\`\`
17
+
18
+ ## ActiveLinkOptions properties
19
+
20
+ The \`ActiveLinkOptions\` object accepts/contains the following properties:
21
+
22
+ ### \`activeProps\`
23
+
24
+ - \`React.AnchorHTMLAttributes<HTMLAnchorElement>\`
25
+ - Optional
26
+ - The props that will be applied to the anchor element when the link is active
27
+
28
+ ### \`inactiveProps\`
29
+
30
+ - Type: \`React.AnchorHTMLAttributes<HTMLAnchorElement>\`
31
+ - Optional
32
+ - The props that will be applied to the anchor element when the link is inactive
33
+
34
+ # AsyncRouteComponent type
35
+
36
+ The \`AsyncRouteComponent\` type is used to describe a code-split route component that can be preloaded using a \`component.preload()\` method.
37
+
38
+ \`\`\`tsx
39
+ type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
40
+ preload?: () => Promise<void>
41
+ }
42
+ \`\`\`
43
+
44
+ # FileRoute class
45
+
46
+ > [!CAUTION]
47
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
48
+ > Please use the [\`createFileRoute\`](../createFileRouteFunction.md) function instead.
49
+
50
+ The \`FileRoute\` class is a factory that can be used to create a file-based route instance. This route instance can then be used to automatically generate a route tree with the \`tsr generate\` and \`tsr watch\` commands.
51
+
52
+ ## \`FileRoute\` constructor
53
+
54
+ The \`FileRoute\` constructor accepts a single argument: the \`path\` of the file that the route will be generated for.
55
+
56
+ ### Constructor options
57
+
58
+ - Type: \`string\` literal
59
+ - Required, but **automatically inserted and updated by the \`tsr generate\` and \`tsr watch\` commands**.
60
+ - The full path of the file that the route will be generated from.
61
+
62
+ ### Constructor returns
63
+
64
+ - An instance of the \`FileRoute\` class that can be used to create a route.
65
+
66
+ ## \`FileRoute\` methods
67
+
68
+ The \`FileRoute\` class implements the following method(s):
69
+
70
+ ### \`.createRoute\` method
71
+
72
+ The \`createRoute\` method is a method that can be used to configure the file route instance. It accepts a single argument: the \`options\` that will be used to configure the file route instance.
73
+
74
+ #### .createRoute options
75
+
76
+ - Type: \`Omit<RouteOptions, 'getParentRoute' | 'path' | 'id'>\`
77
+ - [\`RouteOptions\`](../RouteOptionsType.md)
78
+ - Optional
79
+ - The same options that are available to the \`Route\` class, but with the \`getParentRoute\`, \`path\`, and \`id\` options omitted since they are unnecessary for file-based routing.
80
+
81
+ #### .createRoute returns
82
+
83
+ A [\`Route\`](../RouteType.md) instance that can be used to configure the route to be inserted into the route-tree.
84
+
85
+ > ⚠️ Note: For \`tsr generate\` and \`tsr watch\` to work properly, the file route instance must be exported from the file using the \`Route\` identifier.
86
+
87
+ ### Examples
88
+
89
+ \`\`\`tsx
90
+ import { FileRoute } from '@tanstack/react-router'
91
+
92
+ export const Route = new FileRoute('/').createRoute({
93
+ loader: () => {
94
+ return 'Hello World'
95
+ },
96
+ component: IndexComponent,
97
+ })
98
+
99
+ function IndexComponent() {
100
+ const data = Route.useLoaderData()
101
+ return <div>{data}</div>
102
+ }
103
+ \`\`\`
104
+
105
+ # LinkOptions type
106
+
107
+ The \`LinkOptions\` type extends the [\`NavigateOptions\`](../NavigateOptionsType.md) type and contains additional options that can be used by TanStack Router when handling actual anchor element attributes.
108
+
109
+ \`\`\`tsx
110
+ type LinkOptions = NavigateOptions & {
111
+ target?: HTMLAnchorElement['target']
112
+ activeOptions?: ActiveOptions
113
+ preload?: false | 'intent'
114
+ preloadDelay?: number
115
+ disabled?: boolean
116
+ }
117
+ \`\`\`
118
+
119
+ ## LinkOptions properties
120
+
121
+ The \`LinkOptions\` object accepts/contains the following properties:
122
+
123
+ ### \`target\`
124
+
125
+ - Type: \`HTMLAnchorElement['target']\`
126
+ - Optional
127
+ - The standard anchor tag target attribute
128
+
129
+ ### \`activeOptions\`
130
+
131
+ - Type: \`ActiveOptions\`
132
+ - Optional
133
+ - The options that will be used to determine if the link is active
134
+
135
+ ### \`preload\`
136
+
137
+ - Type: \`false | 'intent' | 'viewport' | 'render'\`
138
+ - Optional
139
+ - If set, the link's preloading strategy will be set to this value.
140
+ - See the [Preloading guide](../../../guide/preloading.md) for more information.
141
+
142
+ ### \`preloadDelay\`
143
+
144
+ - Type: \`number\`
145
+ - Optional
146
+ - Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.
147
+
148
+ ### \`disabled\`
149
+
150
+ - Type: \`boolean\`
151
+ - Optional
152
+ - If true, will render the link without the href attribute
153
+
154
+ # LinkProps type
155
+
156
+ The \`LinkProps\` type extends the [\`ActiveLinkOptions\`](../ActiveLinkOptionsType.md) and \`React.AnchorHTMLAttributes<HTMLAnchorElement>\` types and contains additional props specific to the \`Link\` component.
157
+
158
+ \`\`\`tsx
159
+ type LinkProps = ActiveLinkOptions &
160
+ Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
161
+ children?:
162
+ | React.ReactNode
163
+ | ((state: { isActive: boolean }) => React.ReactNode)
164
+ }
165
+ \`\`\`
166
+
167
+ ## LinkProps properties
168
+
169
+ - All of the props from [\`ActiveLinkOptions\`](../ActiveLinkOptionsType.md)
170
+ - All of the props from \`React.AnchorHTMLAttributes<HTMLAnchorElement>\`
171
+
172
+ #### \`children\`
173
+
174
+ - Type: \`React.ReactNode | ((state: { isActive: boolean }) => React.ReactNode)\`
175
+ - Optional
176
+ - The children that will be rendered inside of the anchor element. If a function is provided, it will be called with an object that contains the \`isActive\` boolean value that can be used to determine if the link is active.
177
+
178
+ # MatchRouteOptions type
179
+
180
+ The \`MatchRouteOptions\` type is used to describe the options that can be used when matching a route.
181
+
182
+ \`\`\`tsx
183
+ interface MatchRouteOptions {
184
+ pending?: boolean
185
+ caseSensitive?: boolean
186
+ includeSearch?: boolean
187
+ fuzzy?: boolean
188
+ }
189
+ \`\`\`
190
+
191
+ ## MatchRouteOptions properties
192
+
193
+ The \`MatchRouteOptions\` type has the following properties:
194
+
195
+ ### \`pending\` property
196
+
197
+ - Type: \`boolean\`
198
+ - Optional
199
+ - If \`true\`, will match against pending location instead of the current location
200
+
201
+ ### \`caseSensitive\` property
202
+
203
+ - Type: \`boolean\`
204
+ - Optional
205
+ - If \`true\`, will match against the current location with case sensitivity
206
+
207
+ ### \`includeSearch\` property
208
+
209
+ - Type: \`boolean\`
210
+ - Optional
211
+ - If \`true\`, will match against the current location's search params using a deep inclusive check. e.g. \`{ a: 1 }\` will match for a current location of \`{ a: 1, b: 2 }\`
212
+
213
+ ### \`fuzzy\` property
214
+
215
+ - Type: \`boolean\`
216
+ - Optional
217
+ - If \`true\`, will match against the current location using a fuzzy match. e.g. \`/posts\` will match for a current location of \`/posts/123\`
218
+
219
+ # NavigateOptions type
220
+
221
+ The \`NavigateOptions\` type is used to describe the options that can be used when describing a navigation action in TanStack Router.
222
+
223
+ \`\`\`tsx
224
+ type NavigateOptions = ToOptions & {
225
+ replace?: boolean
226
+ resetScroll?: boolean
227
+ hashScrollIntoView?: boolean | ScrollIntoViewOptions
228
+ viewTransition?: boolean | ViewTransitionOptions
229
+ ignoreBlocker?: boolean
230
+ reloadDocument?: boolean
231
+ href?: string
232
+ }
233
+ \`\`\`
234
+
235
+ ## NavigateOptions properties
236
+
237
+ The \`NavigateOptions\` object accepts the following properties:
238
+
239
+ ### \`replace\`
240
+
241
+ - Type: \`boolean\`
242
+ - Optional
243
+ - Defaults to \`false\`.
244
+ - If \`true\`, the location will be committed to the browser history using \`history.replace\` instead of \`history.push\`.
245
+
246
+ ### \`resetScroll\`
247
+
248
+ - Type: \`boolean\`
249
+ - Optional
250
+ - Defaults to \`true\` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
251
+ - If \`false\`, the scroll position will not be reset to 0,0 after the location is committed to history.
252
+
253
+ ### \`hashScrollIntoView\`
254
+
255
+ - Type: \`boolean | ScrollIntoViewOptions\`
256
+ - Optional
257
+ - Defaults to \`true\` so the element with an id matching the hash will be scrolled into view after the location is committed to history.
258
+ - If \`false\`, the element with an id matching the hash will not be scrolled into view after the location is committed to history.
259
+ - If an object is provided, it will be passed to the \`scrollIntoView\` method as options.
260
+ - See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on \`ScrollIntoViewOptions\`.
261
+
262
+ ### \`viewTransition\`
263
+
264
+ - Type: \`boolean | ViewTransitionOptions\`
265
+ - Optional
266
+ - Defaults to \`false\`.
267
+ - If \`true\`, navigation will be called using \`document.startViewTransition()\`.
268
+ - If [\`ViewTransitionOptions\`](../ViewTransitionOptionsType.md), route navigations will be called using \`document.startViewTransition({update, types})\` where \`types\` will be the strings array passed with \`ViewTransitionOptions["types"]\`. If the browser does not support viewTransition types, the navigation will fall back to normal \`document.startTransition()\`, same as if \`true\` was passed.
269
+ - If the browser does not support this api, this option will be ignored.
270
+ - See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
271
+ - See [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types) for more information on viewTransition types
272
+
273
+ ### \`ignoreBlocker\`
274
+
275
+ - Type: \`boolean\`
276
+ - Optional
277
+ - Defaults to \`false\`.
278
+ - If \`true\`, navigation will ignore any blockers that might prevent it.
279
+
280
+ ### \`reloadDocument\`
281
+
282
+ - Type: \`boolean\`
283
+ - Optional
284
+ - Defaults to \`false\`.
285
+ - If \`true\`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.
286
+
287
+ ### \`href\`
288
+
289
+ - Type: \`string\`
290
+ - Optional
291
+ - This can be used instead of \`to\` to navigate to a fully built href, e.g. pointing to an external target.
292
+
293
+ - [\`ToOptions\`](../ToOptionsType.md)
294
+
295
+ # NotFoundError
296
+
297
+ The \`NotFoundError\` type is used to represent a not-found error in TanStack Router.
298
+
299
+ \`\`\`tsx
300
+ export type NotFoundError = {
301
+ global?: boolean
302
+ data?: any
303
+ throw?: boolean
304
+ routeId?: string
305
+ }
306
+ \`\`\`
307
+
308
+ ## NotFoundError properties
309
+
310
+ The \`NotFoundError\` object accepts/contains the following properties:
311
+
312
+ ### \`data\` property
313
+
314
+ - Type: \`any\`
315
+ - Optional
316
+ - Custom data that is passed into to \`notFoundComponent\` when the not-found error is handled
317
+
318
+ ### \`global\` property
319
+
320
+ - Type: \`boolean\`
321
+ - Optional - \`default: false\`
322
+ - If true, the not-found error will be handled by the \`notFoundComponent\` of the root route instead of bubbling up from the route that threw it. This has the same behavior as importing the root route and calling \`RootRoute.notFound()\`.
323
+
324
+ ### \`route\` property
325
+
326
+ - Type: \`string\`
327
+ - Optional
328
+ - The ID of the route that will attempt to handle the not-found error. If the route does not have a \`notFoundComponent\`, the error will bubble up to the parent route (and be handled by the root route if necessary). By default, TanStack Router will attempt to handle the not-found error with the route that threw it.
329
+
330
+ ### \`throw\` property
331
+
332
+ - Type: \`boolean\`
333
+ - Optional - \`default: false\`
334
+ - If provided, will throw the not-found object instead of returning it. This can be useful in places where \`throwing\` in a function might cause it to have a return type of \`never\`. In that case, you can use \`notFound({ throw: true })\` to throw the not-found object instead of returning it.
335
+
336
+ # NotFoundRoute class
337
+
338
+ > [!CAUTION]
339
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
340
+ > Please use the \`notFoundComponent\` route option that is present during route configuration.
341
+ > See the [Not Found Errors guide](../../../guide/not-found-errors.md) for more information.
342
+
343
+ The \`NotFoundRoute\` class extends the \`Route\` class and can be used to create a not found route instance. A not found route instance can be passed to the \`routerOptions.notFoundRoute\` option to configure a default not-found/404 route for every branch of the route tree.
344
+
345
+ ## Constructor options
346
+
347
+ The \`NotFoundRoute\` constructor accepts an object as its only argument.
348
+
349
+ - Type:
350
+
351
+ \`\`\`tsx
352
+ Omit<
353
+ RouteOptions,
354
+ | 'path'
355
+ | 'id'
356
+ | 'getParentRoute'
357
+ | 'caseSensitive'
358
+ | 'parseParams'
359
+ | 'stringifyParams'
360
+ >
361
+ \`\`\`
362
+
363
+ - [RouteOptions](../RouteOptionsType.md)
364
+ - Required
365
+ - The options that will be used to configure the not found route instance.
366
+
367
+ ## Examples
368
+
369
+ \`\`\`tsx
370
+ import { NotFoundRoute, createRouter } from '@tanstack/react-router'
371
+ import { Route as rootRoute } from './routes/__root'
372
+ import { routeTree } from './routeTree.gen'
373
+
374
+ const notFoundRoute = new NotFoundRoute({
375
+ getParentRoute: () => rootRoute,
376
+ component: () => <div>Not found!!!</div>,
377
+ })
378
+
379
+ const router = createRouter({
380
+ routeTree,
381
+ notFoundRoute,
382
+ })
383
+
384
+ // ... other code
385
+ \`\`\`
386
+
387
+ # ParsedHistoryState type
388
+
389
+ The \`ParsedHistoryState\` type represents a parsed state object. Additionally to \`HistoryState\`, it contains the index and the unique key of the route.
390
+
391
+ \`\`\`tsx
392
+ export type ParsedHistoryState = HistoryState & {
393
+ key?: string
394
+ __TSR_index: number
395
+ }
396
+ \`\`\`
397
+
398
+ # ParsedLocation type
399
+
400
+ The \`ParsedLocation\` type represents a parsed location in TanStack Router. It contains a lot of useful information about the current location, including the pathname, search params, hash, location state, and route masking information.
401
+
402
+ \`\`\`tsx
403
+ interface ParsedLocation {
404
+ href: string
405
+ pathname: string
406
+ search: TFullSearchSchema
407
+ searchStr: string
408
+ state: ParsedHistoryState
409
+ hash: string
410
+ maskedLocation?: ParsedLocation
411
+ unmaskOnReload?: boolean
412
+ }
413
+ \`\`\`
414
+
415
+ # Redirect type
416
+
417
+ The \`Redirect\` type is used to represent a redirect action in TanStack Router.
418
+
419
+ \`\`\`tsx
420
+ export type Redirect = {
421
+ statusCode?: number
422
+ throw?: any
423
+ headers?: HeadersInit
424
+ } & NavigateOptions
425
+ \`\`\`
426
+
427
+ - [\`NavigateOptions\`](../NavigateOptionsType.md)
428
+
429
+ ## Redirect properties
430
+
431
+ The \`Redirect\` object accepts/contains the following properties:
432
+
433
+ ### \`statusCode\` property
434
+
435
+ - Type: \`number\`
436
+ - Optional
437
+ - The HTTP status code to use when redirecting
438
+
439
+ ### \`throw\` property
440
+
441
+ - Type: \`any\`
442
+ - Optional
443
+ - If provided, will throw the redirect object instead of returning it. This can be useful in places where \`throwing\` in a function might cause it to have a return type of \`never\`. In that case, you can use \`redirect({ throw: true })\` to throw the redirect object instead of returning it.
444
+
445
+ ### \`headers\` property
446
+
447
+ - Type: \`HeadersInit\`
448
+ - Optional
449
+ - The HTTP headers to use when redirecting.
450
+
451
+ # Register type
452
+
453
+ This type is used to register a route tree with a router instance. Doing so unlocks the full type safety of TanStack Router, including top-level exports from the \`@tanstack/react-router\` package.
454
+
455
+ \`\`\`tsx
456
+ export type Register = {
457
+ // router: [Your router type here]
458
+ }
459
+ \`\`\`
460
+
461
+ To register a route tree with a router instance, use declaration merging to add the type of your router instance to the Register interface under the \`router\` property:
462
+
463
+ ## Examples
464
+
465
+ \`\`\`tsx
466
+ const router = createRouter({
467
+ // ...
468
+ })
469
+
470
+ declare module '@tanstack/react-router' {
471
+ interface Register {
472
+ router: typeof router
473
+ }
474
+ }
475
+ \`\`\`
476
+
477
+ # RootRoute class
478
+
479
+ > [!CAUTION]
480
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
481
+ > Please use the [\`createRootRoute\`](../createRootRouteFunction.md) function instead.
482
+
483
+ The \`RootRoute\` class extends the \`Route\` class and can be used to create a root route instance. A root route instance can then be used to create a route tree.
484
+
485
+ ## \`RootRoute\` constructor
486
+
487
+ The \`RootRoute\` constructor accepts an object as its only argument.
488
+
489
+ ### Constructor options
490
+
491
+ The options that will be used to configure the root route instance.
492
+
493
+ - Type:
494
+
495
+ \`\`\`tsx
496
+ Omit<
497
+ RouteOptions,
498
+ | 'path'
499
+ | 'id'
500
+ | 'getParentRoute'
501
+ | 'caseSensitive'
502
+ | 'parseParams'
503
+ | 'stringifyParams'
504
+ >
505
+ \`\`\`
506
+
507
+ - [\`RouteOptions\`](../RouteOptionsType.md)
508
+ - Optional
509
+
510
+ ## Constructor returns
511
+
512
+ A new [\`Route\`](../RouteType.md) instance.
513
+
514
+ ## Examples
515
+
516
+ \`\`\`tsx
517
+ import { RootRoute, createRouter, Outlet } from '@tanstack/react-router'
518
+
519
+ const rootRoute = new RootRoute({
520
+ component: () => <Outlet />,
521
+ // ... root route options
522
+ })
523
+
524
+ const routeTree = rootRoute.addChildren([
525
+ // ... other routes
526
+ ])
527
+
528
+ const router = createRouter({
529
+ routeTree,
530
+ })
531
+ \`\`\`
532
+
533
+ # RouteApi class
534
+
535
+ > [!CAUTION]
536
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
537
+ > Please use the [\`getRouteApi\`](../getRouteApiFunction.md) function instead.
538
+
539
+ The \`RouteApi\` class provides type-safe version of common hooks like \`useParams\`, \`useSearch\`, \`useRouteContext\`, \`useNavigate\`, \`useLoaderData\`, and \`useLoaderDeps\` that are pre-bound to a specific route ID and corresponding registered route types.
540
+
541
+ ## Constructor options
542
+
543
+ The \`RouteApi\` constructor accepts a single argument: the \`options\` that will be used to configure the \`RouteApi\` instance.
544
+
545
+ ### \`opts.routeId\` option
546
+
547
+ - Type: \`string\`
548
+ - Required
549
+ - The route ID to which the \`RouteApi\` instance will be bound
550
+
551
+ ## Constructor returns
552
+
553
+ - An instance of the [\`RouteApi\`](../RouteApiType.md) that is pre-bound to the route ID that it was called with.
554
+
555
+ ## Examples
556
+
557
+ \`\`\`tsx
558
+ import { RouteApi } from '@tanstack/react-router'
559
+
560
+ const routeApi = new RouteApi({ id: '/posts' })
561
+
562
+ export function PostsPage() {
563
+ const posts = routeApi.useLoaderData()
564
+ // ...
565
+ }
566
+ \`\`\`
567
+
568
+ # RouteApi Type
569
+
570
+ The \`RouteApi\` describes an instance that provides type-safe versions of common hooks like \`useParams\`, \`useSearch\`, \`useRouteContext\`, \`useNavigate\`, \`useLoaderData\`, and \`useLoaderDeps\` that are pre-bound to a specific route ID and corresponding registered route types.
571
+
572
+ ## \`RouteApi\` properties and methods
573
+
574
+ The \`RouteApi\` has the following properties and methods:
575
+
576
+ ### \`useMatch\` method
577
+
578
+ \`\`\`tsx
579
+ useMatch<TSelected = TAllContext>(opts?: {
580
+ select?: (match: TAllContext) => TSelected
581
+ }): TSelected
582
+ \`\`\`
583
+
584
+ - A type-safe version of the [\`useMatch\`](../useMatchHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
585
+ - Options
586
+ - \`opts.select\`
587
+ - Optional
588
+ - \`(match: RouteMatch) => TSelected\`
589
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useMatch\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
590
+ - \`opts.structuralSharing\`
591
+ - Optional
592
+ - \`boolean\`
593
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
594
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
595
+ - Returns
596
+ - If a \`select\` function is provided, the return value of the \`select\` function.
597
+ - If no \`select\` function is provided, the \`RouteMatch\` object or a loosened version of the \`RouteMatch\` object if \`opts.strict\` is \`false\`.
598
+
599
+ ### \`useRouteContext\` method
600
+
601
+ \`\`\`tsx
602
+ useRouteContext<TSelected = TAllContext>(opts?: {
603
+ select?: (search: TAllContext) => TSelected
604
+ }): TSelected
605
+ \`\`\`
606
+
607
+ - A type-safe version of the [\`useRouteContext\`](../useRouteContextHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
608
+ - Options
609
+ - \`opts.select\`
610
+ - Optional
611
+ - \`(match: RouteContext) => TSelected\`
612
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useRouteContext\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
613
+ - Returns
614
+ - If a \`select\` function is provided, the return value of the \`select\` function.
615
+ - If no \`select\` function is provided, the \`RouteContext\` object or a loosened version of the \`RouteContext\` object if \`opts.strict\` is \`false\`.
616
+
617
+ ### \`useSearch\` method
618
+
619
+ \`\`\`tsx
620
+ useSearch<TSelected = TFullSearchSchema>(opts?: {
621
+ select?: (search: TFullSearchSchema) => TSelected
622
+ }): TSelected
623
+ \`\`\`
624
+
625
+ - A type-safe version of the [\`useSearch\`](../useSearchHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
626
+ - Options
627
+ - \`opts.select\`
628
+ - Optional
629
+ - \`(match: TFullSearchSchema) => TSelected\`
630
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useSearch\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
631
+ - \`opts.structuralSharing\`
632
+ - Optional
633
+ - \`boolean\`
634
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
635
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
636
+ - Returns
637
+ - If a \`select\` function is provided, the return value of the \`select\` function.
638
+ - If no \`select\` function is provided, the \`TFullSearchSchema\` object or a loosened version of the \`TFullSearchSchema\` object if \`opts.strict\` is \`false\`.
639
+
640
+ ### \`useParams\` method
641
+
642
+ \`\`\`tsx
643
+ useParams<TSelected = TAllParams>(opts?: {
644
+ select?: (params: TAllParams) => TSelected
645
+ }): TSelected
646
+ \`\`\`
647
+
648
+ - A type-safe version of the [\`useParams\`](../useParamsHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
649
+ - Options
650
+ - \`opts.select\`
651
+ - Optional
652
+ - \`(match: TAllParams) => TSelected\`
653
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useParams\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
654
+ - \`opts.structuralSharing\`
655
+ - Optional
656
+ - \`boolean\`
657
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
658
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
659
+ - Returns
660
+ - If a \`select\` function is provided, the return value of the \`select\` function.
661
+ - If no \`select\` function is provided, the \`TAllParams\` object or a loosened version of the \`TAllParams\` object if \`opts.strict\` is \`false\`.
662
+
663
+ ### \`useLoaderData\` method
664
+
665
+ \`\`\`tsx
666
+ useLoaderData<TSelected = TLoaderData>(opts?: {
667
+ select?: (search: TLoaderData) => TSelected
668
+ }): TSelected
669
+ \`\`\`
670
+
671
+ - A type-safe version of the [\`useLoaderData\`](../useLoaderDataHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
672
+ - Options
673
+ - \`opts.select\`
674
+ - Optional
675
+ - \`(match: TLoaderData) => TSelected\`
676
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useLoaderData\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
677
+ - \`opts.structuralSharing\`
678
+ - Optional
679
+ - \`boolean\`
680
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
681
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
682
+ - Returns
683
+ - If a \`select\` function is provided, the return value of the \`select\` function.
684
+ - If no \`select\` function is provided, the \`TLoaderData\` object or a loosened version of the \`TLoaderData\` object if \`opts.strict\` is \`false\`.
685
+
686
+ ### \`useLoaderDeps\` method
687
+
688
+ \`\`\`tsx
689
+ useLoaderDeps<TSelected = TLoaderDeps>(opts?: {
690
+ select?: (search: TLoaderDeps) => TSelected
691
+ }): TSelected
692
+ \`\`\`
693
+
694
+ - A type-safe version of the [\`useLoaderDeps\`](../useLoaderDepsHook.md) hook that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
695
+ - Options
696
+ - \`opts.select\`
697
+ - Optional
698
+ - \`(match: TLoaderDeps) => TSelected\`
699
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useLoaderDeps\`.
700
+ - \`opts.structuralSharing\`
701
+ - Optional
702
+ - \`boolean\`
703
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
704
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
705
+ - Returns
706
+ - If a \`select\` function is provided, the return value of the \`select\` function.
707
+ - If no \`select\` function is provided, the \`TLoaderDeps\` object.
708
+
709
+ ### \`useNavigate\` method
710
+
711
+ \`\`\`tsx
712
+ useNavigate(): // navigate function
713
+ \`\`\`
714
+
715
+ - A type-safe version of [\`useNavigate\`](../useNavigateHook.md) that is pre-bound to the route ID that the \`RouteApi\` instance was created with.
716
+
717
+ # Route class
718
+
719
+ > [!CAUTION]
720
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
721
+ > Please use the [\`createRoute\`](../createRouteFunction.md) function instead.
722
+
723
+ The \`Route\` class implements the \`RouteApi\` class and can be used to create route instances. A route instance can then be used to create a route tree.
724
+
725
+ ## \`Route\` constructor
726
+
727
+ The \`Route\` constructor accepts an object as its only argument.
728
+
729
+ ### Constructor options
730
+
731
+ - Type: [\`RouteOptions\`](../RouteOptionsType.md)
732
+ - Required
733
+ - The options that will be used to configure the route instance
734
+
735
+ ### Constructor returns
736
+
737
+ A new [\`Route\`](../RouteType.md) instance.
738
+
739
+ ## Examples
740
+
741
+ \`\`\`tsx
742
+ import { Route } from '@tanstack/react-router'
743
+ import { rootRoute } from './__root'
744
+
745
+ const indexRoute = new Route({
746
+ getParentRoute: () => rootRoute,
747
+ path: '/',
748
+ loader: () => {
749
+ return 'Hello World'
750
+ },
751
+ component: IndexComponent,
752
+ })
753
+
754
+ function IndexComponent() {
755
+ const data = indexRoute.useLoaderData()
756
+ return <div>{data}</div>
757
+ }
758
+ \`\`\`
759
+
760
+ # RouteMask type
761
+
762
+ The \`RouteMask\` type extends the [\`ToOptions\`](../ToOptionsType.md) type and has other the necessary properties to create a route mask.
763
+
764
+ ## RouteMask properties
765
+
766
+ The \`RouteMask\` type accepts an object with the following properties:
767
+
768
+ ### \`...ToOptions\`
769
+
770
+ - Type: [\`ToOptions\`](../ToOptionsType.md)
771
+ - Required
772
+ - The options that will be used to configure the route mask
773
+
774
+ ### \`options.routeTree\`
775
+
776
+ - Type: \`TRouteTree\`
777
+ - Required
778
+ - The route tree that this route mask will support
779
+
780
+ ### \`options.unmaskOnReload\`
781
+
782
+ - Type: \`boolean\`
783
+ - Optional
784
+ - If \`true\`, the route mask will be removed when the page is reloaded
785
+
786
+ # RouteMatch type
787
+
788
+ The \`RouteMatch\` type represents a route match in TanStack Router.
789
+
790
+ \`\`\`tsx
791
+ interface RouteMatch {
792
+ id: string
793
+ routeId: string
794
+ pathname: string
795
+ params: Route['allParams']
796
+ status: 'pending' | 'success' | 'error'
797
+ isFetching: boolean
798
+ showPending: boolean
799
+ error: unknown
800
+ paramsError: unknown
801
+ searchError: unknown
802
+ updatedAt: number
803
+ loadPromise?: Promise<void>
804
+ loaderData?: Route['loaderData']
805
+ context: Route['allContext']
806
+ search: Route['fullSearchSchema']
807
+ fetchedAt: number
808
+ abortController: AbortController
809
+ cause: 'enter' | 'stay'
810
+ }
811
+ \`\`\`
812
+
813
+ # RouteOptions type
814
+
815
+ The \`RouteOptions\` type is used to describe the options that can be used when creating a route.
816
+
817
+ ## RouteOptions properties
818
+
819
+ The \`RouteOptions\` type accepts an object with the following properties:
820
+
821
+ ### \`getParentRoute\` method
822
+
823
+ - Type: \`() => TParentRoute\`
824
+ - Required
825
+ - A function that returns the parent route of the route being created. This is required to provide full type safety to child route configurations and to ensure that the route tree is built correctly.
826
+
827
+ ### \`path\` property
828
+
829
+ - Type: \`string\`
830
+ - Required, unless an \`id\` is provided to configure the route as a pathless layout route
831
+ - The path segment that will be used to match the route.
832
+
833
+ ### \`id\` property
834
+
835
+ - Type: \`string\`
836
+ - Optional, but required if a \`path\` is not provided
837
+ - The unique identifier for the route if it is to be configured as a pathless layout route. If provided, the route will not match against the location pathname and its routes will be flattened into its parent route for matching.
838
+
839
+ ### \`component\` property
840
+
841
+ - Type: \`RouteComponent\` or \`LazyRouteComponent\`
842
+ - Optional - Defaults to \`<Outlet />\`
843
+ - The content to be rendered when the route is matched.
844
+
845
+ ### \`errorComponent\` property
846
+
847
+ - Type: \`RouteComponent\` or \`LazyRouteComponent\`
848
+ - Optional - Defaults to \`routerOptions.defaultErrorComponent\`
849
+ - The content to be rendered when the route encounters an error.
850
+
851
+ ### \`pendingComponent\` property
852
+
853
+ - Type: \`RouteComponent\` or \`LazyRouteComponent\`
854
+ - Optional - Defaults to \`routerOptions.defaultPendingComponent\`
855
+ - The content to be rendered if and when the route is pending and has reached its pendingMs threshold.
856
+
857
+ ### \`notFoundComponent\` property
858
+
859
+ - Type: \`NotFoundRouteComponent\` or \`LazyRouteComponent\`
860
+ - Optional - Defaults to \`routerOptions.defaultNotFoundComponent\`
861
+ - The content to be rendered when the route is not found.
862
+
863
+ ### \`validateSearch\` method
864
+
865
+ - Type: \`(rawSearchParams: unknown) => TSearchSchema\`
866
+ - Optional
867
+ - A function that will be called when this route is matched and passed the raw search params from the current location and return valid parsed search params. If this function throws, the route will be put into an error state and the error will be thrown during render. If this function does not throw, its return value will be used as the route's search params and the return type will be inferred into the rest of the router.
868
+ - Optionally, the parameter type can be tagged with the \`SearchSchemaInput\` type like this: \`(searchParams: TSearchSchemaInput & SearchSchemaInput) => TSearchSchema\`. If this tag is present, \`TSearchSchemaInput\` will be used to type the \`search\` property of \`<Link />\` and \`navigate()\` **instead of** \`TSearchSchema\`. The difference between \`TSearchSchemaInput\` and \`TSearchSchema\` can be useful, for example, to express optional search parameters.
869
+
870
+ ### \`search.middlewares\` property
871
+
872
+ - Type: \`(({search: TSearchSchema, next: (newSearch: TSearchSchema) => TSearchSchema}) => TSearchSchema)[]\`
873
+ - Optional
874
+ - Search middlewares are functions that transform the search parameters when generating new links for a route or its descendants.
875
+ - A search middleware is passed in the current search (if it is the first middleware to run) or is invoked by the previous middleware calling \`next\`.
876
+
877
+ ### \`parseParams\` method (⚠️ deprecated, use \`params.parse\` instead)
878
+
879
+ - Type: \`(rawParams: Record<string, string>) => TParams\`
880
+ - Optional
881
+ - A function that will be called when this route is matched and passed the raw params from the current location and return valid parsed params. If this function throws, the route will be put into an error state and the error will be thrown during render. If this function does not throw, its return value will be used as the route's params and the return type will be inferred into the rest of the router.
882
+
883
+ ### \`stringifyParams\` method (⚠️ deprecated, use \`params.stringify\` instead)
884
+
885
+ - Type: \`(params: TParams) => Record<string, string>\`
886
+ - Required if \`parseParams\` is provided
887
+ - A function that will be called when this route's parsed params are being used to build a location. This function should return a valid object of \`Record<string, string>\` mapping.
888
+
889
+ ### \`params.parse\` method
890
+
891
+ - Type: \`(rawParams: Record<string, string>) => TParams\`
892
+ - Optional
893
+ - A function that will be called when this route is matched and passed the raw params from the current location and return valid parsed params. If this function throws, the route will be put into an error state and the error will be thrown during render. If this function does not throw, its return value will be used as the route's params and the return type will be inferred into the rest of the router.
894
+
895
+ ### \`params.stringify\` method
896
+
897
+ - Type: \`(params: TParams) => Record<string, string>\`
898
+ - A function that will be called when this route's parsed params are being used to build a location. This function should return a valid object of \`Record<string, string>\` mapping.
899
+
900
+ ### \`beforeLoad\` method
901
+
902
+ - Type:
903
+
904
+ \`\`\`tsx
905
+ type beforeLoad = (
906
+ opts: RouteMatch & {
907
+ search: TFullSearchSchema
908
+ abortController: AbortController
909
+ preload: boolean
910
+ params: TAllParams
911
+ context: TParentContext
912
+ location: ParsedLocation
913
+ navigate: NavigateFn<AnyRoute> // @deprecated
914
+ buildLocation: BuildLocationFn<AnyRoute>
915
+ cause: 'enter' | 'stay'
916
+ },
917
+ ) => Promise<TRouteContext> | TRouteContext | void
918
+ \`\`\`
919
+
920
+ - Optional
921
+ - [\`ParsedLocation\`](../ParsedLocationType.md)
922
+ - This async function is called before a route is loaded. If an error is thrown here, the route's loader will not be called and the route will not render. If thrown during a navigation, the navigation will be canceled and the error will be passed to the \`onError\` function. If thrown during a preload event, the error will be logged to the console and the preload will fail.
923
+ - If this function returns a promise, the route will be put into a pending state and cause rendering to suspend until the promise resolves. If this route's pendingMs threshold is reached, the \`pendingComponent\` will be shown until it resolves. If the promise rejects, the route will be put into an error state and the error will be thrown during render.
924
+ - If this function returns a \`TRouteContext\` object, that object will be merged into the route's context and be made available in the \`loader\` and other related route components/methods.
925
+ - It's common to use this function to check if a user is authenticated and redirect them to a login page if they are not. To do this, you can either return or throw a \`redirect\` object from this function.
926
+
927
+ > 🚧 \`opts.navigate\` has been deprecated and will be removed in the next major release. Use \`throw redirect({ to: '/somewhere' })\` instead. Read more about the \`redirect\` function [here](../redirectFunction.md).
928
+
929
+ ### \`loader\` method
930
+
931
+ - Type:
932
+
933
+ \`\`\`tsx
934
+ type loader = (
935
+ opts: RouteMatch & {
936
+ abortController: AbortController
937
+ cause: 'enter' | 'stay'
938
+ context: TAllContext
939
+ deps: TLoaderDeps
940
+ location: ParsedLocation
941
+ params: TAllParams
942
+ preload: boolean
943
+ parentMatchPromise: Promise<MakeRouteMatchFromRoute<TParentRoute>>
944
+ navigate: NavigateFn<AnyRoute> // @deprecated
945
+ },
946
+ ) => Promise<TLoaderData> | TLoaderData | void
947
+ \`\`\`
948
+
949
+ - Optional
950
+ - [\`ParsedLocation\`](../ParsedLocationType.md)
951
+ - This async function is called when a route is matched and passed the route's match object. If an error is thrown here, the route will be put into an error state and the error will be thrown during render. If thrown during a navigation, the navigation will be canceled and the error will be passed to the \`onError\` function. If thrown during a preload event, the error will be logged to the console and the preload will fail.
952
+ - If this function returns a promise, the route will be put into a pending state and cause rendering to suspend until the promise resolves. If this route's pendingMs threshold is reached, the \`pendingComponent\` will be shown until it resolves. If the promise rejects, the route will be put into an error state and the error will be thrown during render.
953
+ - If this function returns a \`TLoaderData\` object, that object will be stored on the route match until the route match is no longer active. It can be accessed using the \`useLoaderData\` hook in any component that is a child of the route match before another \`<Outlet />\` is rendered.
954
+ - Deps must be returned by your \`loaderDeps\` function in order to appear.
955
+
956
+ > 🚧 \`opts.navigate\` has been deprecated and will be removed in the next major release. Use \`throw redirect({ to: '/somewhere' })\` instead. Read more about the \`redirect\` function [here](../redirectFunction.md).
957
+
958
+ ### \`loaderDeps\` method
959
+
960
+ - Type:
961
+
962
+ \`\`\`tsx
963
+ type loaderDeps = (opts: { search: TFullSearchSchema }) => Record<string, any>
964
+ \`\`\`
965
+
966
+ - Optional
967
+ - A function that will be called before this route is matched to provide additional unique identification to the route match and serve as a dependency tracker for when the match should be reloaded. It should return any serializable value that can uniquely identify the route match from navigation to navigation.
968
+ - By default, path params are already used to uniquely identify a route match, so it's unnecessary to return these here.
969
+ - If your route match relies on search params for unique identification, it's required that you return them here so they can be made available in the \`loader\`'s \`deps\` argument.
970
+
971
+ ### \`staleTime\` property
972
+
973
+ - Type: \`number\`
974
+ - Optional
975
+ - Defaults to \`routerOptions.defaultStaleTime\`, which defaults to \`0\`
976
+ - The amount of time in milliseconds that a route match's loader data will be considered fresh. If a route match is matched again within this time frame, its loader data will not be reloaded.
977
+
978
+ ### \`preloadStaleTime\` property
979
+
980
+ - Type: \`number\`
981
+ - Optional
982
+ - Defaults to \`routerOptions.defaultPreloadStaleTime\`, which defaults to \`30_000\` ms (30 seconds)
983
+ - The amount of time in milliseconds that a route match's loader data will be considered fresh when preloading. If a route match is preloaded again within this time frame, its loader data will not be reloaded. If a route match is loaded (for navigation) within this time frame, the normal \`staleTime\` is used instead.
984
+
985
+ ### \`gcTime\` property
986
+
987
+ - Type: \`number\`
988
+ - Optional
989
+ - Defaults to \`routerOptions.defaultGcTime\`, which defaults to 30 minutes.
990
+ - The amount of time in milliseconds that a route match's loader data will be kept in memory after a preload or it is no longer in use.
991
+
992
+ ### \`shouldReload\` property
993
+
994
+ - Type: \`boolean | ((args: LoaderArgs) => boolean)\`
995
+ - Optional
996
+ - If \`false\` or returns \`false\`, the route match's loader data will not be reloaded on subsequent matches.
997
+ - If \`true\` or returns \`true\`, the route match's loader data will be reloaded on subsequent matches.
998
+ - If \`undefined\` or returns \`undefined\`, the route match's loader data will adhere to the default stale-while-revalidate behavior.
999
+
1000
+ ### \`caseSensitive\` property
1001
+
1002
+ - Type: \`boolean\`
1003
+ - Optional
1004
+ - If \`true\`, this route will be matched as case-sensitive.
1005
+
1006
+ ### \`wrapInSuspense\` property
1007
+
1008
+ - Type: \`boolean\`
1009
+ - Optional
1010
+ - If \`true\`, this route will be forcefully wrapped in a suspense boundary, regardless if a reason is found to do so from inspecting its provided components.
1011
+
1012
+ ### \`pendingMs\` property
1013
+
1014
+ - Type: \`number\`
1015
+ - Optional
1016
+ - Defaults to \`routerOptions.defaultPendingMs\`, which defaults to \`1000\`
1017
+ - The threshold in milliseconds that a route must be pending before its \`pendingComponent\` is shown.
1018
+
1019
+ ### \`pendingMinMs\` property
1020
+
1021
+ - Type: \`number\`
1022
+ - Optional
1023
+ - Defaults to \`routerOptions.defaultPendingMinMs\` which defaults to \`500\`
1024
+ - The minimum amount of time in milliseconds that the pending component will be shown for if it is shown. This is useful to prevent the pending component from flashing on the screen for a split second.
1025
+
1026
+ ### \`preloadMaxAge\` property
1027
+
1028
+ - Type: \`number\`
1029
+ - Optional
1030
+ - Defaults to \`30_000\` ms (30 seconds)
1031
+ - The maximum amount of time in milliseconds that a route's preloaded route data will be cached for. If a route is not matched within this time frame, its loader data will be discarded.
1032
+
1033
+ ### \`preSearchFilters\` property (⚠️ deprecated, use \`search.middlewares\` instead)
1034
+
1035
+ - Type: \`((search: TFullSearchSchema) => TFullSearchSchema)[]\`
1036
+ - Optional
1037
+ - An array of functions that will be called when generating any new links to this route or its grandchildren.
1038
+ - Each function will be called with the current search params and should return a new search params object that will be used to generate the link.
1039
+ - It has a \`pre\` prefix because it is called before the user-provided function that is passed to \`navigate\`/\`Link\` etc has a chance to modify the search params.
1040
+
1041
+ ### \`postSearchFilters\` property (⚠️ deprecated, use \`search.middlewares\` instead)
1042
+
1043
+ - Type: \`((search: TFullSearchSchema) => TFullSearchSchema)[]\`
1044
+ - Optional
1045
+ - An array of functions that will be called when generating any new links to this route or its grandchildren.
1046
+ - Each function will be called with the current search params and should return a new search params object that will be used to generate the link.
1047
+ - It has a \`post\` prefix because it is called after the user-provided function that is passed to \`navigate\`/\`Link\` etc has modified the search params.
1048
+
1049
+ ### \`onError\` property
1050
+
1051
+ - Type: \`(error: any) => void\`
1052
+ - Optional
1053
+ - A function that will be called when an error is thrown during a navigation or preload event.
1054
+ - If this function throws a [\`redirect\`](../redirectFunction.md), then the router will process and apply the redirect immediately.
1055
+
1056
+ ### \`onEnter\` property
1057
+
1058
+ - Type: \`(match: RouteMatch) => void\`
1059
+ - Optional
1060
+ - A function that will be called when a route is matched and loaded after not being matched in the previous location.
1061
+
1062
+ ### \`onStay\` property
1063
+
1064
+ - Type: \`(match: RouteMatch) => void\`
1065
+ - Optional
1066
+ - A function that will be called when a route is matched and loaded after being matched in the previous location.
1067
+
1068
+ ### \`onLeave\` property
1069
+
1070
+ - Type: \`(match: RouteMatch) => void\`
1071
+ - Optional
1072
+ - A function that will be called when a route is no longer matched after being matched in the previous location.
1073
+
1074
+ ### \`onCatch\` property
1075
+
1076
+ - Type: \`(error: Error, errorInfo: ErrorInfo) => void\`
1077
+ - Optional - Defaults to \`routerOptions.defaultOnCatch\`
1078
+ - A function that will be called when errors are caught when the route encounters an error.
1079
+
1080
+ ### \`remountDeps\` method
1081
+
1082
+ - Type:
1083
+
1084
+ \`\`\`tsx
1085
+ type remountDeps = (opts: RemountDepsOptions) => any
1086
+
1087
+ interface RemountDepsOptions<
1088
+ in out TRouteId,
1089
+ in out TFullSearchSchema,
1090
+ in out TAllParams,
1091
+ in out TLoaderDeps,
1092
+ > {
1093
+ routeId: TRouteId
1094
+ search: TFullSearchSchema
1095
+ params: TAllParams
1096
+ loaderDeps: TLoaderDeps
1097
+ }
1098
+ \`\`\`
1099
+
1100
+ - Optional
1101
+ - A function that will be called to determine whether a route component shall be remounted after navigation. If this function returns a different value than previously, it will remount.
1102
+ - The return value needs to be JSON serializable.
1103
+ - By default, a route component will not be remounted if it stays active after a navigation.
1104
+
1105
+ Example:
1106
+ If you want to configure to remount a route component upon \`params\` change, use:
1107
+
1108
+ \`\`\`tsx
1109
+ remountDeps: ({ params }) => params
1110
+ \`\`\`
1111
+
1112
+ # Route type
1113
+
1114
+ The \`Route\` type is used to describe a route instance.
1115
+
1116
+ ## \`Route\` properties and methods
1117
+
1118
+ An instance of the \`Route\` has the following properties and methods:
1119
+
1120
+ ### \`.addChildren\` method
1121
+
1122
+ - Type: \`(children: Route[]) => this\`
1123
+ - Adds child routes to the route instance and returns the route instance (but with updated types to reflect the new children).
1124
+
1125
+ ### \`.update\` method
1126
+
1127
+ - Type: \`(options: Partial<UpdatableRouteOptions>) => this\`
1128
+ - Updates the route instance with new options and returns the route instance (but with updated types to reflect the new options).
1129
+ - In some circumstances, it can be useful to update a route instance's options after it has been created to avoid circular type references.
1130
+ - ...\`RouteApi\` methods
1131
+
1132
+ ### \`.lazy\` method
1133
+
1134
+ - Type: \`(lazyImporter: () => Promise<Partial<UpdatableRouteOptions>>) => this\`
1135
+ - Updates the route instance with a new lazy importer which will be resolved lazily when loading the route. This can be useful for code splitting.
1136
+
1137
+ ### ...\`RouteApi\` methods
1138
+
1139
+ - All of the methods from [\`RouteApi\`](../RouteApiType.md) are available.
1140
+
1141
+ # Router Class
1142
+
1143
+ > [!CAUTION]
1144
+ > This class has been deprecated and will be removed in the next major version of TanStack Router.
1145
+ > Please use the [\`createRouter\`](../createRouterFunction.md) function instead.
1146
+
1147
+ The \`Router\` class is used to instantiate a new router instance.
1148
+
1149
+ ## \`Router\` constructor
1150
+
1151
+ The \`Router\` constructor accepts a single argument: the \`options\` that will be used to configure the router instance.
1152
+
1153
+ ### Constructor options
1154
+
1155
+ - Type: [\`RouterOptions\`](../RouterOptionsType.md)
1156
+ - Required
1157
+ - The options that will be used to configure the router instance.
1158
+
1159
+ ### Constructor returns
1160
+
1161
+ - An instance of the [\`Router\`](../RouterType.md).
1162
+
1163
+ ## Examples
1164
+
1165
+ \`\`\`tsx
1166
+ import { Router, RouterProvider } from '@tanstack/react-router'
1167
+ import { routeTree } from './routeTree.gen'
1168
+
1169
+ const router = new Router({
1170
+ routeTree,
1171
+ defaultPreload: 'intent',
1172
+ })
1173
+
1174
+ export default function App() {
1175
+ return <RouterProvider router={router} />
1176
+ }
1177
+ \`\`\`
1178
+
1179
+ # RouterEvents type
1180
+
1181
+ The \`RouterEvents\` type contains all of the events that the router can emit. Each top-level key of this type, represents the name of an event that the router can emit. The values of the keys are the event payloads.
1182
+
1183
+ \`\`\`tsx
1184
+ type RouterEvents = {
1185
+ onBeforeNavigate: {
1186
+ type: 'onBeforeNavigate'
1187
+ fromLocation?: ParsedLocation
1188
+ toLocation: ParsedLocation
1189
+ pathChanged: boolean
1190
+ hrefChanged: boolean
1191
+ }
1192
+ onBeforeLoad: {
1193
+ type: 'onBeforeLoad'
1194
+ fromLocation?: ParsedLocation
1195
+ toLocation: ParsedLocation
1196
+ pathChanged: boolean
1197
+ hrefChanged: boolean
1198
+ }
1199
+ onLoad: {
1200
+ type: 'onLoad'
1201
+ fromLocation?: ParsedLocation
1202
+ toLocation: ParsedLocation
1203
+ pathChanged: boolean
1204
+ hrefChanged: boolean
1205
+ }
1206
+ onResolved: {
1207
+ type: 'onResolved'
1208
+ fromLocation?: ParsedLocation
1209
+ toLocation: ParsedLocation
1210
+ pathChanged: boolean
1211
+ hrefChanged: boolean
1212
+ }
1213
+ onBeforeRouteMount: {
1214
+ type: 'onBeforeRouteMount'
1215
+ fromLocation?: ParsedLocation
1216
+ toLocation: ParsedLocation
1217
+ pathChanged: boolean
1218
+ hrefChanged: boolean
1219
+ }
1220
+ onInjectedHtml: {
1221
+ type: 'onInjectedHtml'
1222
+ promise: Promise<string>
1223
+ }
1224
+ onRendered: {
1225
+ type: 'onRendered'
1226
+ fromLocation?: ParsedLocation
1227
+ toLocation: ParsedLocation
1228
+ }
1229
+ }
1230
+ \`\`\`
1231
+
1232
+ ## RouterEvents properties
1233
+
1234
+ Once an event is emitted, the following properties will be present on the event payload.
1235
+
1236
+ ### \`type\` property
1237
+
1238
+ - Type: \`onBeforeNavigate | onBeforeLoad | onLoad | onBeforeRouteMount | onResolved\`
1239
+ - The type of the event
1240
+ - This is useful for discriminating between events in a listener function.
1241
+
1242
+ ### \`fromLocation\` property
1243
+
1244
+ - Type: [\`ParsedLocation\`](../ParsedLocationType.md)
1245
+ - The location that the router is transitioning from.
1246
+
1247
+ ### \`toLocation\` property
1248
+
1249
+ - Type: [\`ParsedLocation\`](../ParsedLocationType.md)
1250
+ - The location that the router is transitioning to.
1251
+
1252
+ ### \`pathChanged\` property
1253
+
1254
+ - Type: \`boolean\`
1255
+ - \`true\` if the path has changed between the \`fromLocation\` and \`toLocation\`.
1256
+
1257
+ ### \`hrefChanged\` property
1258
+
1259
+ - Type: \`boolean\`
1260
+ - \`true\` if the href has changed between the \`fromLocation\` and \`toLocation\`.
1261
+
1262
+ ## Example
1263
+
1264
+ \`\`\`tsx
1265
+ import { createRouter } from '@tanstack/react-router'
1266
+ import { routeTree } from './routeTree.gen'
1267
+
1268
+ const router = createRouter({ routeTree })
1269
+
1270
+ const unsub = router.subscribe('onResolved', (evt) => {
1271
+ // ...
1272
+ })
1273
+ \`\`\`
1274
+
1275
+ # RouterOptions
1276
+
1277
+ The \`RouterOptions\` type contains all of the options that can be used to configure a router instance.
1278
+
1279
+ ## RouterOptions properties
1280
+
1281
+ The \`RouterOptions\` type accepts an object with the following properties and methods:
1282
+
1283
+ ### \`routeTree\` property
1284
+
1285
+ - Type: \`AnyRoute\`
1286
+ - Required
1287
+ - The route tree that will be used to configure the router instance.
1288
+
1289
+ ### \`history\` property
1290
+
1291
+ - Type: \`RouterHistory\`
1292
+ - Optional
1293
+ - The history object that will be used to manage the browser history. If not provided, a new \`createBrowserHistory\` instance will be created and used.
1294
+
1295
+ ### \`stringifySearch\` method
1296
+
1297
+ - Type: \`(search: Record<string, any>) => string\`
1298
+ - Optional
1299
+ - A function that will be used to stringify search params when generating links.
1300
+ - Defaults to \`defaultStringifySearch\`.
1301
+
1302
+ ### \`parseSearch\` method
1303
+
1304
+ - Type: \`(search: string) => Record<string, any>\`
1305
+ - Optional
1306
+ - A function that will be used to parse search params when parsing the current location.
1307
+ - Defaults to \`defaultParseSearch\`.
1308
+
1309
+ ### \`search.strict\` property
1310
+
1311
+ - Type: \`boolean\`
1312
+ - Optional
1313
+ - Defaults to \`false\`
1314
+ - Configures how unknown search params (= not returned by any \`validateSearch\`) are treated.
1315
+ - If \`false\`, unknown search params will be kept.
1316
+ - If \`true\`, unknown search params will be removed.
1317
+
1318
+ ### \`defaultPreload\` property
1319
+
1320
+ - Type: \`undefined | false | 'intent' | 'viewport' | 'render'\`
1321
+ - Optional
1322
+ - Defaults to \`false\`
1323
+ - If \`false\`, routes will not be preloaded by default in any way.
1324
+ - If \`'intent'\`, routes will be preloaded by default when the user hovers over a link or a \`touchstart\` event is detected on a \`<Link>\`.
1325
+ - If \`'viewport'\`, routes will be preloaded by default when they are within the viewport of the browser.
1326
+ - If \`'render'\`, routes will be preloaded by default as soon as they are rendered in the DOM.
1327
+
1328
+ ### \`defaultPreloadDelay\` property
1329
+
1330
+ - Type: \`number\`
1331
+ - Optional
1332
+ - Defaults to \`50\`
1333
+ - The delay in milliseconds that a route must be hovered over or touched before it is preloaded.
1334
+
1335
+ ### \`defaultComponent\` property
1336
+
1337
+ - Type: \`RouteComponent\`
1338
+ - Optional
1339
+ - Defaults to \`Outlet\`
1340
+ - The default \`component\` a route should use if no component is provided.
1341
+
1342
+ ### \`defaultErrorComponent\` property
1343
+
1344
+ - Type: \`RouteComponent\`
1345
+ - Optional
1346
+ - Defaults to \`ErrorComponent\`
1347
+ - The default \`errorComponent\` a route should use if no error component is provided.
1348
+
1349
+ ### \`defaultNotFoundComponent\` property
1350
+
1351
+ - Type: \`NotFoundRouteComponent\`
1352
+ - Optional
1353
+ - Defaults to \`NotFound\`
1354
+ - The default \`notFoundComponent\` a route should use if no notFound component is provided.
1355
+
1356
+ ### \`defaultPendingComponent\` property
1357
+
1358
+ - Type: \`RouteComponent\`
1359
+ - Optional
1360
+ - The default \`pendingComponent\` a route should use if no pending component is provided.
1361
+
1362
+ ### \`defaultPendingMs\` property
1363
+
1364
+ - Type: \`number\`
1365
+ - Optional
1366
+ - Defaults to \`1000\`
1367
+ - The default \`pendingMs\` a route should use if no pendingMs is provided.
1368
+
1369
+ ### \`defaultPendingMinMs\` property
1370
+
1371
+ - Type: \`number\`
1372
+ - Optional
1373
+ - Defaults to \`500\`
1374
+ - The default \`pendingMinMs\` a route should use if no pendingMinMs is provided.
1375
+
1376
+ ### \`defaultStaleTime\` property
1377
+
1378
+ - Type: \`number\`
1379
+ - Optional
1380
+ - Defaults to \`0\`
1381
+ - The default \`staleTime\` a route should use if no staleTime is provided.
1382
+
1383
+ ### \`defaultPreloadStaleTime\` property
1384
+
1385
+ - Type: \`number\`
1386
+ - Optional
1387
+ - Defaults to \`30_000\` ms (30 seconds)
1388
+ - The default \`preloadStaleTime\` a route should use if no preloadStaleTime is provided.
1389
+
1390
+ ### \`defaultPreloadGcTime\` property
1391
+
1392
+ - Type: \`number\`
1393
+ - Optional
1394
+ - Defaults to \`routerOptions.defaultGcTime\`, which defaults to 30 minutes.
1395
+ - The default \`preloadGcTime\` a route should use if no preloadGcTime is provided.
1396
+
1397
+ ### \`defaultGcTime\` property
1398
+
1399
+ - Type: \`number\`
1400
+ - Optional
1401
+ - Defaults to 30 minutes.
1402
+ - The default \`gcTime\` a route should use if no gcTime is provided.
1403
+
1404
+ ### \`defaultOnCatch\` property
1405
+
1406
+ - Type: \`(error: Error, errorInfo: ErrorInfo) => void\`
1407
+ - Optional
1408
+ - The default \`onCatch\` handler for errors caught by the Router ErrorBoundary
1409
+
1410
+ ### \`defaultViewTransition\` property
1411
+
1412
+ - Type: \`boolean | ViewTransitionOptions\`
1413
+ - Optional
1414
+ - If \`true\`, route navigations will be called using \`document.startViewTransition()\`.
1415
+ - If [\`ViewTransitionOptions\`](../ViewTransitionOptionsType.md), route navigations will be called using \`document.startViewTransition({update, types})\`
1416
+ where \`types\` will be the strings array passed with \`ViewTransitionOptions["types"]\`. If the browser does not support viewTransition types,
1417
+ the navigation will fall back to normal \`document.startTransition()\`, same as if \`true\` was passed.
1418
+ - If the browser does not support this api, this option will be ignored.
1419
+ - See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for more information on how this function works.
1420
+ - See [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types) for more information on viewTransition types
1421
+
1422
+ ### \`defaultHashScrollIntoView\` property
1423
+
1424
+ - Type: \`boolean | ScrollIntoViewOptions\`
1425
+ - Optional
1426
+ - Defaults to \`true\` so the element with an id matching the hash will be scrolled into view after the location is committed to history.
1427
+ - If \`false\`, the element with an id matching the hash will not be scrolled into view after the location is committed to history.
1428
+ - If an object is provided, it will be passed to the \`scrollIntoView\` method as options.
1429
+ - See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on \`ScrollIntoViewOptions\`.
1430
+
1431
+ ### \`caseSensitive\` property
1432
+
1433
+ - Type: \`boolean\`
1434
+ - Optional
1435
+ - Defaults to \`false\`
1436
+ - If \`true\`, all routes will be matched as case-sensitive.
1437
+
1438
+ ### \`basepath\` property
1439
+
1440
+ - Type: \`string\`
1441
+ - Optional
1442
+ - Defaults to \`/\`
1443
+ - The basepath for then entire router. This is useful for mounting a router instance at a subpath.
1444
+
1445
+ ### \`context\` property
1446
+
1447
+ - Type: \`any\`
1448
+ - Optional or required if the root route was created with [\`createRootRouteWithContext()\`](../createRootRouteWithContextFunction.md).
1449
+ - The root context that will be provided to all routes in the route tree. This can be used to provide a context to all routes in the tree without having to provide it to each route individually.
1450
+
1451
+ ### \`dehydrate\` method
1452
+
1453
+ - Type: \`() => TDehydrated\`
1454
+ - Optional
1455
+ - A function that will be called when the router is dehydrated. The return value of this function will be serialized and stored in the router's dehydrated state.
1456
+
1457
+ ### \`hydrate\` method
1458
+
1459
+ - Type: \`(dehydrated: TDehydrated) => void\`
1460
+ - Optional
1461
+ - A function that will be called when the router is hydrated. The return value of this function will be serialized and stored in the router's dehydrated state.
1462
+
1463
+ ### \`routeMasks\` property
1464
+
1465
+ - Type: \`RouteMask[]\`
1466
+ - Optional
1467
+ - An array of route masks that will be used to mask routes in the route tree. 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.
1468
+
1469
+ ### \`unmaskOnReload\` property
1470
+
1471
+ - Type: \`boolean\`
1472
+ - Optional
1473
+ - Defaults to \`false\`
1474
+ - If \`true\`, route masks will, by default, be removed when the page is reloaded. 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.
1475
+
1476
+ ### \`Wrap\` property
1477
+
1478
+ - Type: \`React.Component\`
1479
+ - Optional
1480
+ - A component that will be used to wrap the entire router. This is useful for providing a context to the entire router. Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
1481
+
1482
+ **Example**
1483
+
1484
+ \`\`\`tsx
1485
+ import { createRouter } from '@tanstack/react-router'
1486
+
1487
+ const router = createRouter({
1488
+ // ...
1489
+ Wrap: ({ children }) => {
1490
+ return <MyContext.Provider value={myContext}>{children}</MyContext>
1491
+ },
1492
+ })
1493
+ \`\`\`
1494
+
1495
+ ### \`InnerWrap\` property
1496
+
1497
+ - Type: \`React.Component\`
1498
+ - Optional
1499
+ - A component that will be used to wrap the inner contents of the router. 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. Only non-DOM-rendering components like providers should be used, anything else will cause a hydration error.
1500
+
1501
+ **Example**
1502
+
1503
+ \`\`\`tsx
1504
+ import { createRouter } from '@tanstack/react-router'
1505
+
1506
+ const router = createRouter({
1507
+ // ...
1508
+ InnerWrap: ({ children }) => {
1509
+ const routerState = useRouterState()
1510
+
1511
+ return (
1512
+ <MyContext.Provider value={myContext}>
1513
+ {children}
1514
+ </MyContext>
1515
+ )
1516
+ },
1517
+ })
1518
+ \`\`\`
1519
+
1520
+ ### \`notFoundMode\` property
1521
+
1522
+ - Type: \`'root' | 'fuzzy'\`
1523
+ - Optional
1524
+ - Defaults to \`'fuzzy'\`
1525
+ - This property controls how TanStack Router will handle scenarios where it cannot find a route to match the current location. See the [Not Found Errors guide](../../../guide/not-found-errors.md) for more information.
1526
+
1527
+ ### \`notFoundRoute\` property
1528
+
1529
+ - **Deprecated**
1530
+ - Type: \`NotFoundRoute\`
1531
+ - Optional
1532
+ - A route that will be used as the default not found route for every branch of the route tree. This can be overridden on a per-branch basis by providing a not found route to the \`NotFoundRoute\` option on the root route of the branch.
1533
+
1534
+ ### \`errorSerializer\` property
1535
+
1536
+ - Type: [\`RouterErrorSerializer\`]
1537
+ - Optional
1538
+ - The serializer object that will be used to determine how errors are serialized and deserialized between the server and the client.
1539
+
1540
+ #### \`errorSerializer.serialize\` method
1541
+
1542
+ - Type: \`(err: unknown) => TSerializedError\`
1543
+ - This method is called to define how errors are serialized when they are stored in the router's dehydrated state.
1544
+
1545
+ #### \`errorSerializer.deserialize\` method
1546
+
1547
+ - Type: \`(err: TSerializedError) => unknown\`
1548
+ - This method is called to define how errors are deserialized from the router's dehydrated state.
1549
+
1550
+ ### \`trailingSlash\` property
1551
+
1552
+ - Type: \`'always' | 'never' | 'preserve'\`
1553
+ - Optional
1554
+ - Defaults to \`never\`
1555
+ - Configures how trailing slashes are treated. \`'always'\` will add a trailing slash if not present, \`'never'\` will remove the trailing slash if present and \`'preserve'\` will not modify the trailing slash.
1556
+
1557
+ ### \`pathParamsAllowedCharacters\` property
1558
+
1559
+ - Type: \`Array<';' | ':' | '@' | '&' | '=' | '+' | '$' | ','>\`
1560
+ - Optional
1561
+ - Configures which URI characters are allowed in path params that would ordinarily be escaped by encodeURIComponent.
1562
+
1563
+ ### \`defaultStructuralSharing\` property
1564
+
1565
+ - Type: \`boolean\`
1566
+ - Optional
1567
+ - Defaults to \`false\`
1568
+ - Configures whether structural sharing is enabled by default for fine-grained selectors.
1569
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
1570
+
1571
+ ### \`defaultRemountDeps\` property
1572
+
1573
+ - Type:
1574
+
1575
+ \`\`\`tsx
1576
+ type defaultRemountDeps = (opts: RemountDepsOptions) => any
1577
+
1578
+ interface RemountDepsOptions<
1579
+ in out TRouteId,
1580
+ in out TFullSearchSchema,
1581
+ in out TAllParams,
1582
+ in out TLoaderDeps,
1583
+ > {
1584
+ routeId: TRouteId
1585
+ search: TFullSearchSchema
1586
+ params: TAllParams
1587
+ loaderDeps: TLoaderDeps
1588
+ }
1589
+ \`\`\`
1590
+
1591
+ - Optional
1592
+ - A default function that will be called to determine whether a route component shall be remounted after navigation. If this function returns a different value than previously, it will remount.
1593
+ - The return value needs to be JSON serializable.
1594
+ - By default, a route component will not be remounted if it stays active after a navigation
1595
+
1596
+ Example:
1597
+ If you want to configure to remount all route components upon \`params\` change, use:
1598
+
1599
+ \`\`\`tsx
1600
+ remountDeps: ({ params }) => params
1601
+ \`\`\`
1602
+
1603
+ # RouterState type
1604
+
1605
+ The \`RouterState\` type represents shape of the internal state of the router. The Router's internal state is useful, if you need to access certain internals of the router, such as any pending matches, is the router in its loading state, etc.
1606
+
1607
+ \`\`\`tsx
1608
+ type RouterState = {
1609
+ status: 'pending' | 'idle'
1610
+ isLoading: boolean
1611
+ isTransitioning: boolean
1612
+ matches: Array<RouteMatch>
1613
+ pendingMatches: Array<RouteMatch>
1614
+ location: ParsedLocation
1615
+ resolvedLocation: ParsedLocation
1616
+ }
1617
+ \`\`\`
1618
+
1619
+ ## RouterState properties
1620
+
1621
+ The \`RouterState\` type contains all of the properties that are available on the router state.
1622
+
1623
+ ### \`status\` property
1624
+
1625
+ - Type: \`'pending' | 'idle'\`
1626
+ - The current status of the router. If the router is pending, it means that it is currently loading a route or the router is still transitioning to the new route.
1627
+
1628
+ ### \`isLoading\` property
1629
+
1630
+ - Type: \`boolean\`
1631
+ - \`true\` if the router is currently loading a route or waiting for a route to finish loading.
1632
+
1633
+ ### \`isTransitioning\` property
1634
+
1635
+ - Type: \`boolean\`
1636
+ - \`true\` if the router is currently transitioning to a new route.
1637
+
1638
+ ### \`matches\` property
1639
+
1640
+ - Type: [\`Array<RouteMatch>\`](../RouteMatchType.md)
1641
+ - An array of all of the route matches that have been resolved and are currently active.
1642
+
1643
+ ### \`pendingMatches\` property
1644
+
1645
+ - Type: [\`Array<RouteMatch>\`](../RouteMatchType.md)
1646
+ - An array of all of the route matches that are currently pending.
1647
+
1648
+ ### \`location\` property
1649
+
1650
+ - Type: [\`ParsedLocation\`](../ParsedLocationType.md)
1651
+ - The latest location that the router has parsed from the browser history. This location may not be resolved and loaded yet.
1652
+
1653
+ ### \`resolvedLocation\` property
1654
+
1655
+ - Type: [\`ParsedLocation\`](../ParsedLocationType.md)
1656
+ - The location that the router has resolved and loaded.
1657
+
1658
+ # Router type
1659
+
1660
+ The \`Router\` type is used to describe a router instance.
1661
+
1662
+ ## \`Router\` properties and methods
1663
+
1664
+ An instance of the \`Router\` has the following properties and methods:
1665
+
1666
+ ### \`.update\` method
1667
+
1668
+ - Type: \`(newOptions: RouterOptions) => void\`
1669
+ - Updates the router instance with new options.
1670
+
1671
+ ### \`state\` property
1672
+
1673
+ - Type: [\`RouterState\`](../RouterStateType.md)
1674
+ - The current state of the router.
1675
+
1676
+ > ⚠️⚠️⚠️ **\`router.state\` is always up to date, but NOT REACTIVE. If you use \`router.state\` in a component, the component will not re-render when the router state changes. To get a reactive version of the router state, use the [\`useRouterState\`](../useRouterStateHook.md) hook.**
1677
+
1678
+ ### \`.subscribe\` method
1679
+
1680
+ - Type: \`(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => (event: RouterEvent) => void\`
1681
+ - Subscribes to a [\`RouterEvent\`](../RouterEventsType.md).
1682
+ - Returns a function that can be used to unsubscribe from the event.
1683
+ - The callback provided to the returned function will be called with the event that was emitted.
1684
+
1685
+ ### \`.matchRoutes\` method
1686
+
1687
+ - Type: \`(pathname: string, locationSearch: Record<string, any>, opts?: { throwOnError?: boolean; }) => RouteMatch[]\`
1688
+ - Matches a pathname and search params against the router's route tree and returns an array of route matches.
1689
+ - If \`opts.throwOnError\` is \`true\`, any errors that occur during the matching process will be thrown (in addition to being returned in the route match's \`error\` property).
1690
+
1691
+ ### \`.cancelMatch\` method
1692
+
1693
+ - Type: \`(matchId: string) => void\`
1694
+ - Cancels a route match that is currently pending by calling \`match.abortController.abort()\`.
1695
+
1696
+ ### \`.cancelMatches\` method
1697
+
1698
+ - Type: \`() => void\`
1699
+ - Cancels all route matches that are currently pending by calling \`match.abortController.abort()\` on each one.
1700
+
1701
+ ### \`.buildLocation\` method
1702
+
1703
+ Builds a new parsed location object that can be used later to navigate to a new location.
1704
+
1705
+ - Type: \`(opts: BuildNextOptions) => ParsedLocation\`
1706
+ - Properties
1707
+ - \`from\`
1708
+ - Type: \`string\`
1709
+ - Optional
1710
+ - The path to navigate from. If not provided, the current path will be used.
1711
+ - \`to\`
1712
+ - Type: \`string | number | null\`
1713
+ - Optional
1714
+ - The path to navigate to. If \`null\`, the current path will be used.
1715
+ - \`params\`
1716
+ - Type: \`true | Updater<unknown>\`
1717
+ - Optional
1718
+ - If \`true\`, the current params will be used. If a function is provided, it will be called with the current params and the return value will be used.
1719
+ - \`search\`
1720
+ - Type: \`true | Updater<unknown>\`
1721
+ - Optional
1722
+ - If \`true\`, the current search params will be used. If a function is provided, it will be called with the current search params and the return value will be used.
1723
+ - \`hash\`
1724
+ - Type: \`true | Updater<string>\`
1725
+ - Optional
1726
+ - If \`true\`, the current hash will be used. If a function is provided, it will be called with the current hash and the return value will be used.
1727
+ - \`state\`
1728
+ - Type: \`true | NonNullableUpdater<ParsedHistoryState, HistoryState>\`
1729
+ - Optional
1730
+ - If \`true\`, the current state will be used. If a function is provided, it will be called with the current state and the return value will be used.
1731
+ - \`mask\`
1732
+ - Type: \`object\`
1733
+ - Optional
1734
+ - Contains all of the same BuildNextOptions, with the addition of \`unmaskOnReload\`.
1735
+ - \`unmaskOnReload\`
1736
+ - Type: \`boolean\`
1737
+ - Optional
1738
+ - If \`true\`, the route mask will be removed when the page is reloaded. This can be overridden on a per-navigation basis by setting the \`unmaskOnReload\` option in the \`Navigate\` options.
1739
+
1740
+ ### \`.commitLocation\` method
1741
+
1742
+ Commits a new location object to the browser history.
1743
+
1744
+ - Type
1745
+ \`\`\`tsx
1746
+ type commitLocation = (
1747
+ location: ParsedLocation & {
1748
+ replace?: boolean
1749
+ resetScroll?: boolean
1750
+ hashScrollIntoView?: boolean | ScrollIntoViewOptions
1751
+ ignoreBlocker?: boolean
1752
+ },
1753
+ ) => Promise<void>
1754
+ \`\`\`
1755
+ - Properties
1756
+ - \`location\`
1757
+ - Type: [\`ParsedLocation\`](../ParsedLocationType.md)
1758
+ - Required
1759
+ - The location to commit to the browser history.
1760
+ - \`replace\`
1761
+ - Type: \`boolean\`
1762
+ - Optional
1763
+ - Defaults to \`false\`.
1764
+ - If \`true\`, the location will be committed to the browser history using \`history.replace\` instead of \`history.push\`.
1765
+ - \`resetScroll\`
1766
+ - Type: \`boolean\`
1767
+ - Optional
1768
+ - Defaults to \`true\` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.
1769
+ - If \`false\`, the scroll position will not be reset to 0,0 after the location is committed to history.
1770
+ - \`hashScrollIntoView\`
1771
+ - Type: \`boolean | ScrollIntoViewOptions\`
1772
+ - Optional
1773
+ - Defaults to \`true\` so the element with an id matching the hash will be scrolled into view after the location is committed to history.
1774
+ - If \`false\`, the element with an id matching the hash will not be scrolled into view after the location is committed to history.
1775
+ - If an object is provided, it will be passed to the \`scrollIntoView\` method as options.
1776
+ - See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) for more information on \`ScrollIntoViewOptions\`.
1777
+ - \`ignoreBlocker\`
1778
+ - Type: \`boolean\`
1779
+ - Optional
1780
+ - Defaults to \`false\`.
1781
+ - If \`true\`, navigation will ignore any blockers that might prevent it.
1782
+
1783
+ ### \`.navigate\` method
1784
+
1785
+ Navigates to a new location.
1786
+
1787
+ - Type
1788
+ \`\`\`tsx
1789
+ type navigate = (options: NavigateOptions) => Promise<void>
1790
+ \`\`\`
1791
+
1792
+ ### \`.invalidate\` method
1793
+
1794
+ Invalidates route matches by forcing their \`beforeLoad\` and \`load\` functions to be called again.
1795
+
1796
+ - Type: \`(opts?: {filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean, sync?: boolean}) => Promise<void>\`
1797
+ - This is useful any time your loader data might be out of date or stale. For example, if you have a route that displays a list of posts, and you have a loader function that fetches the list of posts from an API, you might want to invalidate the route matches for that route any time a new post is created so that the list of posts is always up-to-date.
1798
+ - if \`filter\` is not supplied, all matches will be invalidated
1799
+ - if \`filter\` is supplied, only matches for which \`filter\` returns \`true\` will be invalidated.
1800
+ - if \`sync\` is true, the promise returned by this function will only resolve once all loaders have finished.
1801
+ - You might also want to invalidate the Router if you imperatively \`reset\` the router's \`CatchBoundary\` to trigger loaders again.
1802
+
1803
+ ### \`.clearCache\` method
1804
+
1805
+ Remove cached route matches.
1806
+
1807
+ - Type: \`(opts?: {filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean}) => void\`
1808
+ - if \`filter\` is not supplied, all cached matches will be removed
1809
+ - if \`filter\` is supplied, only matches for which \`filter\` returns \`true\` will be removed.
1810
+
1811
+ ### \`.load\` method
1812
+
1813
+ Loads all of the currently matched route matches and resolves when they are all loaded and ready to be rendered.
1814
+
1815
+ > ⚠️⚠️⚠️ **\`router.load()\` respects \`route.staleTime\` and will not forcefully reload a route match if it is still fresh. If you need to forcefully reload a route match, use \`router.invalidate()\` instead.**
1816
+
1817
+ - Type: \`(opts?: {sync?: boolean}) => Promise<void>\`
1818
+ - if \`sync\` is true, the promise returned by this function will only resolve once all loaders have finished.
1819
+ - The most common use case for this method is to call it when doing SSR to ensure that all of the critical data for the current route is loaded before attempting to stream or render the application to the client.
1820
+
1821
+ ### \`.preloadRoute\` method
1822
+
1823
+ Preloads all of the matches that match the provided \`NavigateOptions\`.
1824
+
1825
+ > ⚠️⚠️⚠️ **Preloaded route matches are not stored long-term in the router state. They are only stored until the next attempted navigation action.**
1826
+
1827
+ - Type: \`(opts?: NavigateOptions) => Promise<RouteMatch[]>\`
1828
+ - Properties
1829
+ - \`opts\`
1830
+ - Type: \`NavigateOptions\`
1831
+ - Optional, defaults to the current location.
1832
+ - The options that will be used to determine which route matches to preload.
1833
+ - Returns
1834
+ - A promise that resolves with an array of all of the route matches that were preloaded.
1835
+
1836
+ ### \`.loadRouteChunk\` method
1837
+
1838
+ Loads the JS chunk of the route.
1839
+
1840
+ - Type: \`(route: AnyRoute) => Promise<void>\`
1841
+
1842
+ ### \`.matchRoute\` method
1843
+
1844
+ Matches a pathname and search params against the router's route tree and returns a route match's params or false if no match was found.
1845
+
1846
+ - Type: \`(dest: ToOptions, matchOpts?: MatchRouteOptions) => RouteMatch['params'] | false\`
1847
+ - Properties
1848
+ - \`dest\`
1849
+ - Type: \`ToOptions\`
1850
+ - Required
1851
+ - The destination to match against.
1852
+ - \`matchOpts\`
1853
+ - Type: \`MatchRouteOptions\`
1854
+ - Optional
1855
+ - Options that will be used to match the destination.
1856
+ - Returns
1857
+ - A route match's params if a match was found.
1858
+ - \`false\` if no match was found.
1859
+
1860
+ ### \`.dehydrate\` method
1861
+
1862
+ Dehydrates the router's critical state into a serializable object that can be sent to the client in an initial request.
1863
+
1864
+ - Type: \`() => DehydratedRouter\`
1865
+ - Returns
1866
+ - A serializable object that contains the router's critical state.
1867
+
1868
+ ### \`.hydrate\` method
1869
+
1870
+ Hydrates the router's critical state from a serializable object that was sent from the server in an initial request.
1871
+
1872
+ - Type: \`(dehydrated: DehydratedRouter) => void\`
1873
+ - Properties
1874
+ - \`dehydrated\`
1875
+ - Type: \`DehydratedRouter\`
1876
+ - Required
1877
+ - The dehydrated router state that was sent from the server.
1878
+
1879
+ # ToMaskOptions type
1880
+
1881
+ The \`ToMaskOptions\` type extends the [\`ToOptions\`](../ToOptionsType.md) type and describes additional options available when using route masks.
1882
+
1883
+ \`\`\`tsx
1884
+ type ToMaskOptions = ToOptions & {
1885
+ unmaskOnReload?: boolean
1886
+ }
1887
+ \`\`\`
1888
+
1889
+ - [\`ToOptions\`](../ToOptionsType.md)
1890
+
1891
+ # ToOptions type
1892
+
1893
+ The \`ToOptions\` type contains several properties that can be used to describe a router destination.
1894
+
1895
+ \`\`\`tsx
1896
+ type ToOptions = {
1897
+ from?: ValidRoutePath | string
1898
+ to?: ValidRoutePath | string
1899
+ hash?: true | string | ((prev?: string) => string)
1900
+ state?: true | HistoryState | ((prev: HistoryState) => HistoryState)
1901
+ } & SearchParamOptions &
1902
+ PathParamOptions
1903
+
1904
+ type SearchParamOptions = {
1905
+ search?: true | TToSearch | ((prev: TFromSearch) => TToSearch)
1906
+ }
1907
+
1908
+ type PathParamOptions = {
1909
+ path?: true | Record<string, TPathParam> | ((prev: TFromParams) => TToParams)
1910
+ }
1911
+ \`\`\`
1912
+
1913
+ # UseMatchRouteOptions type
1914
+
1915
+ The \`UseMatchRouteOptions\` type extends the [\`ToOptions\`](../ToOptionsType.md) type and describes additional options available when using the [\`useMatchRoute\`](../useMatchRouteHook.md) hook.
1916
+
1917
+ \`\`\`tsx
1918
+ export type UseMatchRouteOptions = ToOptions & MatchRouteOptions
1919
+ \`\`\`
1920
+
1921
+ - [\`ToOptions\`](../ToOptionsType.md)
1922
+ - [\`MatchRouteOptions\`](../MatchRouteOptionsType.md)
1923
+
1924
+ # ViewTransitionOptions type
1925
+
1926
+ The \`ViewTransitionOptions\` type is used to define a
1927
+ [viewTransition type](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types).
1928
+
1929
+ \`\`\`tsx
1930
+ interface ViewTransitionOptions {
1931
+ types: Array<string>
1932
+ }
1933
+ \`\`\`
1934
+
1935
+ ## ViewTransitionOptions properties
1936
+
1937
+ The \`ViewTransitionOptions\` type accepts an object with a single property:
1938
+
1939
+ ### \`types\` property
1940
+
1941
+ - Type: \`Array<string>\`
1942
+ - Required
1943
+ - The types array that will be passed to the \`document.startViewTransition({update, types}) call\`;
1944
+
1945
+ # Await component
1946
+
1947
+ The \`Await\` component is a component that suspends until the provided promise is resolved or rejected.
1948
+ This is only necessary for React 18.
1949
+ If you are using React 19, you can use the \`use()\` hook instead.
1950
+
1951
+ ## Await props
1952
+
1953
+ The \`Await\` component accepts the following props:
1954
+
1955
+ ### \`props.promise\` prop
1956
+
1957
+ - Type: \`Promise<T>\`
1958
+ - Required
1959
+ - The promise to await.
1960
+
1961
+ ### \`props.children\` prop
1962
+
1963
+ - Type: \`(result: T) => React.ReactNode\`
1964
+ - Required
1965
+ - A function that will be called with the resolved value of the promise.
1966
+
1967
+ ## Await returns
1968
+
1969
+ - Throws an error if the promise is rejected.
1970
+ - Suspends (throws a promise) if the promise is pending.
1971
+ - Returns the resolved value of a deferred promise if the promise is resolved using \`props.children\` as the render function.
1972
+
1973
+ ## Examples
1974
+
1975
+ \`\`\`tsx
1976
+ import { Await } from '@tanstack/react-router'
1977
+
1978
+ function Component() {
1979
+ const { deferredPromise } = route.useLoaderData()
1980
+
1981
+ return (
1982
+ <Await promise={deferredPromise}>
1983
+ {(data) => <div>{JSON.stringify(data)}</div>}
1984
+ </Await>
1985
+ )
1986
+ }
1987
+ \`\`\`
1988
+
1989
+ # CatchBoundary component
1990
+
1991
+ The \`CatchBoundary\` component is a component that catches errors thrown by its children, renders an error component and optionally calls the \`onCatch\` callback. It also accepts a \`getResetKey\` function that can be used to declaratively reset the component's state when the key changes.
1992
+
1993
+ ## CatchBoundary props
1994
+
1995
+ The \`CatchBoundary\` component accepts the following props:
1996
+
1997
+ ### \`props.getResetKey\` prop
1998
+
1999
+ - Type: \`() => string\`
2000
+ - Required
2001
+ - A function that returns a string that will be used to reset the component's state when the key changes.
2002
+
2003
+ ### \`props.children\` prop
2004
+
2005
+ - Type: \`React.ReactNode\`
2006
+ - Required
2007
+ - The component's children to render when there is no error
2008
+
2009
+ ### \`props.errorComponent\` prop
2010
+
2011
+ - Type: \`React.ReactNode\`
2012
+ - Optional - [\`default: ErrorComponent\`](../errorComponentComponent.md)
2013
+ - The component to render when there is an error.
2014
+
2015
+ ### \`props.onCatch\` prop
2016
+
2017
+ - Type: \`(error: any) => void\`
2018
+ - Optional
2019
+ - A callback that will be called with the error that was thrown by the component's children.
2020
+
2021
+ ## CatchBoundary returns
2022
+
2023
+ - Returns the component's children if there is no error.
2024
+ - Returns the \`errorComponent\` if there is an error.
2025
+
2026
+ ## Examples
2027
+
2028
+ \`\`\`tsx
2029
+ import { CatchBoundary } from '@tanstack/react-router'
2030
+
2031
+ function Component() {
2032
+ return (
2033
+ <CatchBoundary
2034
+ getResetKey={() => 'reset'}
2035
+ onCatch={(error) => console.error(error)}
2036
+ >
2037
+ <div>My Component</div>
2038
+ </CatchBoundary>
2039
+ )
2040
+ }
2041
+ \`\`\`
2042
+
2043
+ # CatchNotFound Component
2044
+
2045
+ The \`CatchNotFound\` component is a component that catches not-found errors thrown by its children, renders a fallback component and optionally calls the \`onCatch\` callback. It resets when the pathname changes.
2046
+
2047
+ ## CatchNotFound props
2048
+
2049
+ The \`CatchNotFound\` component accepts the following props:
2050
+
2051
+ ### \`props.children\` prop
2052
+
2053
+ - Type: \`React.ReactNode\`
2054
+ - Required
2055
+ - The component's children to render when there is no error
2056
+
2057
+ ### \`props.fallback\` prop
2058
+
2059
+ - Type: \`(error: NotFoundError) => React.ReactElement\`
2060
+ - Optional
2061
+ - The component to render when there is an error
2062
+
2063
+ ### \`props.onCatch\` prop
2064
+
2065
+ - Type: \`(error: any) => void\`
2066
+ - Optional
2067
+ - A callback that will be called with the error that was thrown by the component's children
2068
+
2069
+ ## CatchNotFound returns
2070
+
2071
+ - Returns the component's children if there is no error.
2072
+ - Returns the \`fallback\` if there is an error.
2073
+
2074
+ ## Examples
2075
+
2076
+ \`\`\`tsx
2077
+ import { CatchNotFound } from '@tanstack/react-router'
2078
+
2079
+ function Component() {
2080
+ return (
2081
+ <CatchNotFound
2082
+ fallback={(error) => <p>Not found error! {JSON.stringify(error)}</p>}
2083
+ >
2084
+ <ComponentThatMightThrowANotFoundError />
2085
+ </CatchNotFound>
2086
+ )
2087
+ }
2088
+ \`\`\`
2089
+
2090
+ # ClientOnly Component
2091
+
2092
+ The \`ClientOnly\` component is used to render a components only in the client, without breaking the server-side rendering due to hydration errors. It accepts a \`fallback\` prop that will be rendered if the JS is not yet loaded in the client.
2093
+
2094
+ ## Props
2095
+
2096
+ The \`ClientOnly\` component accepts the following props:
2097
+
2098
+ ### \`props.fallback\` prop
2099
+
2100
+ The fallback component to render if the JS is not yet loaded in the client.
2101
+
2102
+ ### \`props.children\` prop
2103
+
2104
+ The component to render if the JS is loaded in the client.
2105
+
2106
+ ## Returns
2107
+
2108
+ - Returns the component's children if the JS is loaded in the client.
2109
+ - Returns the \`fallback\` component if the JS is not yet loaded in the client.
2110
+
2111
+ ## Examples
2112
+
2113
+ \`\`\`tsx
2114
+ // src/routes/dashboard.tsx
2115
+ import { ClientOnly, createFileRoute } from '@tanstack/react-router'
2116
+ import {
2117
+ Charts,
2118
+ FallbackCharts,
2119
+ } from './charts-that-break-server-side-rendering'
2120
+
2121
+ export const Route = createFileRoute('/dashboard')({
2122
+ component: Dashboard,
2123
+ // ... other route options
2124
+ })
2125
+
2126
+ function Dashboard() {
2127
+ return (
2128
+ <div>
2129
+ <p>Dashboard</p>
2130
+ <ClientOnly fallback={<FallbackCharts />}>
2131
+ <Charts />
2132
+ </ClientOnly>
2133
+ </div>
2134
+ )
2135
+ }
2136
+ \`\`\`
2137
+
2138
+ # createFileRoute function
2139
+
2140
+ The \`createFileRoute\` function is a factory that can be used to create a file-based route instance. This route instance can then be used to automatically generate a route tree with the \`tsr generate\` and \`tsr watch\` commands.
2141
+
2142
+ ## createFileRoute options
2143
+
2144
+ The \`createFileRoute\` function accepts a single argument of type \`string\` that represents the \`path\` of the file that the route will be generated from.
2145
+
2146
+ ### \`path\` option
2147
+
2148
+ - Type: \`string\` literal
2149
+ - Required, but **automatically inserted and updated by the \`tsr generate\` and \`tsr watch\` commands**
2150
+ - The full path of the file that the route will be generated from
2151
+
2152
+ ## createFileRoute returns
2153
+
2154
+ A new function that accepts a single argument of type [\`RouteOptions\`](../RouteOptionsType.md) that will be used to configure the file [\`Route\`](../RouteType.md) instance.
2155
+
2156
+ > ⚠️ Note: For \`tsr generate\` and \`tsr watch\` to work properly, the file route instance must be exported from the file using the \`Route\` identifier.
2157
+
2158
+ ## Examples
2159
+
2160
+ \`\`\`tsx
2161
+ import { createFileRoute } from '@tanstack/react-router'
2162
+
2163
+ export const Route = createFileRoute('/')({
2164
+ loader: () => {
2165
+ return 'Hello World'
2166
+ },
2167
+ component: IndexComponent,
2168
+ })
2169
+
2170
+ function IndexComponent() {
2171
+ const data = Route.useLoaderData()
2172
+ return <div>{data}</div>
2173
+ }
2174
+ \`\`\`
2175
+
2176
+ # createLazyFileRoute function
2177
+
2178
+ The \`createLazyFileRoute\` function is used for creating a partial file-based route route instance that is lazily loaded when matched. This route instance can only be used to configure the [non-critical properties](../../../guide/code-splitting.md#how-does-tanstack-router-split-code) of the route, such as \`component\`, \`pendingComponent\`, \`errorComponent\`, and the \`notFoundComponent\`.
2179
+
2180
+ ## createLazyFileRoute options
2181
+
2182
+ The \`createLazyFileRoute\` function accepts a single argument of type \`string\` that represents the \`path\` of the file that the route will be generated from.
2183
+
2184
+ ### \`path\`
2185
+
2186
+ - Type: \`string\`
2187
+ - Required, but **automatically inserted and updated by the \`tsr generate\` and \`tsr watch\` commands**
2188
+ - The full path of the file that the route will be generated from.
2189
+
2190
+ ### createLazyFileRoute returns
2191
+
2192
+ A new function that accepts a single argument of partial of the type [\`RouteOptions\`](../RouteOptionsType.md) that will be used to configure the file [\`Route\`](../RouteType.md) instance.
2193
+
2194
+ - Type:
2195
+
2196
+ \`\`\`tsx
2197
+ Pick<
2198
+ RouteOptions,
2199
+ 'component' | 'pendingComponent' | 'errorComponent' | 'notFoundComponent'
2200
+ >
2201
+ \`\`\`
2202
+
2203
+ - [\`RouteOptions\`](../RouteOptionsType.md)
2204
+
2205
+ > ⚠️ Note: For \`tsr generate\` and \`tsr watch\` to work properly, the file route instance must be exported from the file using the \`Route\` identifier.
2206
+
2207
+ ### Examples
2208
+
2209
+ \`\`\`tsx
2210
+ import { createLazyFileRoute } from '@tanstack/react-router'
2211
+
2212
+ export const Route = createLazyFileRoute('/')({
2213
+ component: IndexComponent,
2214
+ })
2215
+
2216
+ function IndexComponent() {
2217
+ const data = Route.useLoaderData()
2218
+ return <div>{data}</div>
2219
+ }
2220
+ \`\`\`
2221
+
2222
+ # createLazyRoute function
2223
+
2224
+ The \`createLazyRoute\` function is used for creating a partial code-based route route instance that is lazily loaded when matched. This route instance can only be used to configure the [non-critical properties](../../../guide/code-splitting.md#how-does-tanstack-router-split-code) of the route, such as \`component\`, \`pendingComponent\`, \`errorComponent\`, and the \`notFoundComponent\`.
2225
+
2226
+ ## createLazyRoute options
2227
+
2228
+ The \`createLazyRoute\` function accepts a single argument of type \`string\` that represents the \`id\` of the route.
2229
+
2230
+ ### \`id\`
2231
+
2232
+ - Type: \`string\`
2233
+ - Required
2234
+ - The route id of the route.
2235
+
2236
+ ### createLazyRoute returns
2237
+
2238
+ A new function that accepts a single argument of partial of the type [\`RouteOptions\`](../RouteOptionsType.md) that will be used to configure the file [\`Route\`](../RouteType.md) instance.
2239
+
2240
+ - Type:
2241
+
2242
+ \`\`\`tsx
2243
+ Pick<
2244
+ RouteOptions,
2245
+ 'component' | 'pendingComponent' | 'errorComponent' | 'notFoundComponent'
2246
+ >
2247
+ \`\`\`
2248
+
2249
+ - [\`RouteOptions\`](../RouteOptionsType.md)
2250
+
2251
+ > ⚠️ Note: This route instance must be manually lazily loaded against its critical route instance using the \`lazy\` method returned by the \`createRoute\` function.
2252
+
2253
+ ### Examples
2254
+
2255
+ \`\`\`tsx
2256
+ // src/route-pages/index.tsx
2257
+ import { createLazyRoute } from '@tanstack/react-router'
2258
+
2259
+ export const Route = createLazyRoute('/')({
2260
+ component: IndexComponent,
2261
+ })
2262
+
2263
+ function IndexComponent() {
2264
+ const data = Route.useLoaderData()
2265
+ return <div>{data}</div>
2266
+ }
2267
+
2268
+ // src/routeTree.tsx
2269
+ import {
2270
+ createRootRouteWithContext,
2271
+ createRoute,
2272
+ Outlet,
2273
+ } from '@tanstack/react-router'
2274
+
2275
+ interface MyRouterContext {
2276
+ foo: string
2277
+ }
2278
+
2279
+ const rootRoute = createRootRouteWithContext<MyRouterContext>()({
2280
+ component: () => <Outlet />,
2281
+ })
2282
+
2283
+ const indexRoute = createRoute({
2284
+ getParentRoute: () => rootRoute,
2285
+ path: '/',
2286
+ }).lazy(() => import('./route-pages/index').then((d) => d.Route))
2287
+
2288
+ export const routeTree = rootRoute.addChildren([indexRoute])
2289
+ \`\`\`
2290
+
2291
+ # createRootRoute function
2292
+
2293
+ The \`createRootRoute\` function returns a new root route instance. A root route instance can then be used to create a route-tree.
2294
+
2295
+ ## createRootRoute options
2296
+
2297
+ The options that will be used to configure the root route instance.
2298
+
2299
+ - Type:
2300
+
2301
+ \`\`\`tsx
2302
+ Omit<
2303
+ RouteOptions,
2304
+ | 'path'
2305
+ | 'id'
2306
+ | 'getParentRoute'
2307
+ | 'caseSensitive'
2308
+ | 'parseParams'
2309
+ | 'stringifyParams'
2310
+ >
2311
+ \`\`\`
2312
+
2313
+ - [\`RouteOptions\`](../RouteOptionsType.md)
2314
+ - Optional
2315
+
2316
+ ## createRootRoute returns
2317
+
2318
+ A new [\`Route\`](../RouteType.md) instance.
2319
+
2320
+ ## Examples
2321
+
2322
+ \`\`\`tsx
2323
+ import { createRootRoute, createRouter, Outlet } from '@tanstack/react-router'
2324
+
2325
+ const rootRoute = createRootRoute({
2326
+ component: () => <Outlet />,
2327
+ // ... root route options
2328
+ })
2329
+
2330
+ const routeTree = rootRoute.addChildren([
2331
+ // ... other routes
2332
+ ])
2333
+
2334
+ const router = createRouter({
2335
+ routeTree,
2336
+ })
2337
+ \`\`\`
2338
+
2339
+ # createRootRouteWithContext function
2340
+
2341
+ The \`createRootRouteWithContext\` function is a helper function that can be used to create a root route instance that requires a context type to be fulfilled when the router is created.
2342
+
2343
+ ## createRootRouteWithContext generics
2344
+
2345
+ The \`createRootRouteWithContext\` function accepts a single generic argument:
2346
+
2347
+ ### \`TRouterContext\` generic
2348
+
2349
+ - Type: \`TRouterContext\`
2350
+ - Optional, **but recommended**.
2351
+ - The context type that will be required to be fulfilled when the router is created
2352
+
2353
+ ## createRootRouteWithContext returns
2354
+
2355
+ - A factory function that can be used to create a new [\`createRootRoute\`](../createRootRouteFunction.md) instance.
2356
+ - It accepts a single argument, the same as the [\`createRootRoute\`](../createRootRouteFunction.md) function.
2357
+
2358
+ ## Examples
2359
+
2360
+ \`\`\`tsx
2361
+ import {
2362
+ createRootRouteWithContext,
2363
+ createRouter,
2364
+ } from '@tanstack/react-router'
2365
+ import { QueryClient } from '@tanstack/react-query'
2366
+
2367
+ interface MyRouterContext {
2368
+ queryClient: QueryClient
2369
+ }
2370
+
2371
+ const rootRoute = createRootRouteWithContext<MyRouterContext>()({
2372
+ component: () => <Outlet />,
2373
+ // ... root route options
2374
+ })
2375
+
2376
+ const routeTree = rootRoute.addChildren([
2377
+ // ... other routes
2378
+ ])
2379
+
2380
+ const queryClient = new QueryClient()
2381
+
2382
+ const router = createRouter({
2383
+ routeTree,
2384
+ context: {
2385
+ queryClient,
2386
+ },
2387
+ })
2388
+ \`\`\`
2389
+
2390
+ # createRoute function
2391
+
2392
+ The \`createRoute\` function implements returns a [\`Route\`](../RouteType.md) instance. A route instance can then be passed to a root route's children to create a route tree, which is then passed to the router.
2393
+
2394
+ ## createRoute options
2395
+
2396
+ - Type: [\`RouteOptions\`](../RouteOptionsType.md)
2397
+ - Required
2398
+ - The options that will be used to configure the route instance
2399
+
2400
+ ## createRoute returns
2401
+
2402
+ A new [\`Route\`](../RouteType.md) instance.
2403
+
2404
+ ## Examples
2405
+
2406
+ \`\`\`tsx
2407
+ import { createRoute } from '@tanstack/react-router'
2408
+ import { rootRoute } from './__root'
2409
+
2410
+ const Route = createRoute({
2411
+ getParentRoute: () => rootRoute,
2412
+ path: '/',
2413
+ loader: () => {
2414
+ return 'Hello World'
2415
+ },
2416
+ component: IndexComponent,
2417
+ })
2418
+
2419
+ function IndexComponent() {
2420
+ const data = Route.useLoaderData()
2421
+ return <div>{data}</div>
2422
+ }
2423
+ \`\`\`
2424
+
2425
+ # createRouteMask function
2426
+
2427
+ The \`createRouteMask\` function is a helper function that can be used to create a route mask configuration that can be passed to the \`RouterOptions.routeMasks\` option.
2428
+
2429
+ ## createRouteMask options
2430
+
2431
+ - Type: [\`RouteMask\`](../RouteMaskType.md)
2432
+ - Required
2433
+ - The options that will be used to configure the route mask
2434
+
2435
+ ## createRouteMask returns
2436
+
2437
+ - A object with the type signature of [\`RouteMask\`](../RouteMaskType.md) that can be passed to the \`RouterOptions.routeMasks\` option.
2438
+
2439
+ ## Examples
2440
+
2441
+ \`\`\`tsx
2442
+ import { createRouteMask, createRouter } from '@tanstack/react-router'
2443
+
2444
+ const photoModalToPhotoMask = createRouteMask({
2445
+ routeTree,
2446
+ from: '/photos/$photoId/modal',
2447
+ to: '/photos/$photoId',
2448
+ params: true,
2449
+ })
2450
+
2451
+ // Set up a Router instance
2452
+ const router = createRouter({
2453
+ routeTree,
2454
+ routeMasks: [photoModalToPhotoMask],
2455
+ })
2456
+ \`\`\`
2457
+
2458
+ # createRouter function
2459
+
2460
+ The \`createRouter\` function accepts a [\`RouterOptions\`](../RouterOptionsType.md) object and creates a new [\`Router\`](../RouterClass.md) instance.
2461
+
2462
+ ## createRouter options
2463
+
2464
+ - Type: [\`RouterOptions\`](../RouterOptionsType.md)
2465
+ - Required
2466
+ - The options that will be used to configure the router instance.
2467
+
2468
+ ## createRouter returns
2469
+
2470
+ - An instance of the [\`Router\`](../RouterType.md).
2471
+
2472
+ ## Examples
2473
+
2474
+ \`\`\`tsx
2475
+ import { createRouter, RouterProvider } from '@tanstack/react-router'
2476
+ import { routeTree } from './routeTree.gen'
2477
+
2478
+ const router = createRouter({
2479
+ routeTree,
2480
+ defaultPreload: 'intent',
2481
+ })
2482
+
2483
+ export default function App() {
2484
+ return <RouterProvider router={router} />
2485
+ }
2486
+ \`\`\`
2487
+
2488
+ # DefaultGlobalNotFound component
2489
+
2490
+ The \`DefaultGlobalNotFound\` component is a component that renders "Not Found" on the root route when there is no other route that matches and a \`notFoundComponent\` is not provided.
2491
+
2492
+ ## DefaultGlobalNotFound returns
2493
+
2494
+ \`\`\`tsx
2495
+ <p>Not Found</p>
2496
+ \`\`\`
2497
+
2498
+ # defer function
2499
+
2500
+ > [!CAUTION]
2501
+ > You don't need to call \`defer\` manually anymore, Promises are handled automatically now.
2502
+
2503
+ The \`defer\` function wraps a promise with a deferred state object that can be used to inspect the promise's state. This deferred promise can then be passed to the [\`useAwaited\`](../useAwaitedHook.md) hook or the [\`<Await>\`](../awaitComponent.md) component for suspending until the promise is resolved or rejected.
2504
+
2505
+ The \`defer\` function accepts a single argument, the \`promise\` to wrap with a deferred state object.
2506
+
2507
+ ## defer options
2508
+
2509
+ - Type: \`Promise<T>\`
2510
+ - Required
2511
+ - The promise to wrap with a deferred state object.
2512
+
2513
+ ## defer returns
2514
+
2515
+ - A promise that can be passed to the [\`useAwaited\`](../useAwaitedHook.md) hook or the [\`<Await>\`](../awaitComponent.md) component.
2516
+
2517
+ ## Examples
2518
+
2519
+ \`\`\`tsx
2520
+ import { defer } from '@tanstack/react-router'
2521
+
2522
+ const route = createRoute({
2523
+ loader: () => {
2524
+ const deferredPromise = defer(fetch('/api/data'))
2525
+ return { deferredPromise }
2526
+ },
2527
+ component: MyComponent,
2528
+ })
2529
+
2530
+ function MyComponent() {
2531
+ const { deferredPromise } = Route.useLoaderData()
2532
+
2533
+ const data = useAwaited({ promise: deferredPromise })
2534
+
2535
+ // or
2536
+
2537
+ return (
2538
+ <Await promise={deferredPromise}>
2539
+ {(data) => <div>{JSON.stringify(data)}</div>}
2540
+ </Await>
2541
+ )
2542
+ }
2543
+ \`\`\`
2544
+
2545
+ # ErrorComponent component
2546
+
2547
+ The \`ErrorComponent\` component is a component that renders an error message and optionally the error's message.
2548
+
2549
+ ## ErrorComponent props
2550
+
2551
+ The \`ErrorComponent\` component accepts the following props:
2552
+
2553
+ ### \`props.error\` prop
2554
+
2555
+ - Type: \`any\`
2556
+ - The error that was thrown by the component's children
2557
+
2558
+ ### \`props.reset\` prop
2559
+
2560
+ - Type: \`() => void\`
2561
+ - A function to programmatically reset the error state
2562
+
2563
+ ## ErrorComponent returns
2564
+
2565
+ - Returns a formatted error message with the error's message if it exists.
2566
+ - The error message can be toggled by clicking the "Show Error" button.
2567
+ - By default, the error message will be shown in development.
2568
+
2569
+ # getRouteApi function
2570
+
2571
+ The \`getRouteApi\` function provides type-safe version of common hooks like \`useParams\`, \`useSearch\`, \`useRouteContext\`, \`useNavigate\`, \`useLoaderData\`, and \`useLoaderDeps\` that are pre-bound to a specific route ID and corresponding registered route types.
2572
+
2573
+ ## getRouteApi options
2574
+
2575
+ The \`getRouteApi\` function accepts a single argument, a \`routeId\` string literal.
2576
+
2577
+ ### \`routeId\` option
2578
+
2579
+ - Type: \`string\`
2580
+ - Required
2581
+ - The route ID to which the [\`RouteApi\`](../RouteApiClass.md) instance will be bound
2582
+
2583
+ ## getRouteApi returns
2584
+
2585
+ - An instance of the [\`RouteApi\`](../RouteApiType.md) that is pre-bound to the route ID that the \`getRouteApi\` function was called with.
2586
+
2587
+ ## Examples
2588
+
2589
+ \`\`\`tsx
2590
+ import { getRouteApi } from '@tanstack/react-router'
2591
+
2592
+ const routeApi = getRouteApi('/posts')
2593
+
2594
+ export function PostsPage() {
2595
+ const posts = routeApi.useLoaderData()
2596
+ // ...
2597
+ }
2598
+ \`\`\`
2599
+
2600
+ # HistoryState interface
2601
+
2602
+ The \`HistoryState\` interface is an interface exported by the \`history\` package that describes the shape of the state object that can be used in conjunction with the \`history\` package and the \`window.location\` API.
2603
+
2604
+ You can extend this interface to add additional properties to the state object across your application.
2605
+
2606
+ \`\`\`tsx
2607
+ // src/main.tsx
2608
+ declare module '@tanstack/react-router' {
2609
+ // ...
2610
+
2611
+ interface HistoryState {
2612
+ additionalRequiredProperty: number
2613
+ additionalProperty?: string
2614
+ }
2615
+ }
2616
+ \`\`\`
2617
+
2618
+ # isNotFound function
2619
+
2620
+ The \`isNotFound\` function can be used to determine if an object is a [\`NotFoundError\`](../NotFoundErrorType.md) object.
2621
+
2622
+ ## isNotFound options
2623
+
2624
+ The \`isNotFound\` function accepts a single argument, an \`input\`.
2625
+
2626
+ ### \`input\` option
2627
+
2628
+ - Type: \`unknown\`
2629
+ - Required
2630
+ - An object to check if it is a [\`NotFoundError\`](../NotFoundErrorType.md).
2631
+
2632
+ ## isNotFound returns
2633
+
2634
+ - Type: \`boolean\`
2635
+ - \`true\` if the object is a [\`NotFoundError\`](../NotFoundErrorType.md).
2636
+ - \`false\` if the object is not a [\`NotFoundError\`](../NotFoundErrorType.md).
2637
+
2638
+ ## Examples
2639
+
2640
+ \`\`\`tsx
2641
+ import { isNotFound } from '@tanstack/react-router'
2642
+
2643
+ function somewhere(obj: unknown) {
2644
+ if (isNotFound(obj)) {
2645
+ // ...
2646
+ }
2647
+ }
2648
+ \`\`\`
2649
+
2650
+ # isRedirect function
2651
+
2652
+ The \`isRedirect\` function can be used to determine if an object is a redirect object.
2653
+
2654
+ ## isRedirect options
2655
+
2656
+ The \`isRedirect\` function accepts a single argument, an \`input\`.
2657
+
2658
+ #### \`input\`
2659
+
2660
+ - Type: \`unknown\`
2661
+ - Required
2662
+ - An object to check if it is a redirect object
2663
+
2664
+ ## isRedirect returns
2665
+
2666
+ - Type: \`boolean\`
2667
+ - \`true\` if the object is a redirect object
2668
+ - \`false\` if the object is not a redirect object
2669
+
2670
+ ## Examples
2671
+
2672
+ \`\`\`tsx
2673
+ import { isRedirect } from '@tanstack/react-router'
2674
+
2675
+ function somewhere(obj: unknown) {
2676
+ if (isRedirect(obj)) {
2677
+ // ...
2678
+ }
2679
+ }
2680
+ \`\`\`
2681
+
2682
+ # lazyRouteComponent function
2683
+
2684
+ > [!IMPORTANT]
2685
+ > If you are using file-based routing, it's recommended to use the \`createLazyFileRoute\` function instead.
2686
+
2687
+ The \`lazyRouteComponent\` function can be used to create a one-off code-split route component that can be preloaded using a \`component.preload()\` method.
2688
+
2689
+ ## lazyRouteComponent options
2690
+
2691
+ The \`lazyRouteComponent\` function accepts two arguments:
2692
+
2693
+ ### \`importer\` option
2694
+
2695
+ - Type: \`() => Promise<T>\`
2696
+ - Required
2697
+ - A function that returns a promise that resolves to an object that contains the component to be loaded.
2698
+
2699
+ ### \`exportName\` option
2700
+
2701
+ - Type: \`string\`
2702
+ - Optional
2703
+ - The name of the component to be loaded from the imported object. Defaults to \`'default'\`.
2704
+
2705
+ ## lazyRouteComponent returns
2706
+
2707
+ - A \`React.lazy\` component that can be preloaded using a \`component.preload()\` method.
2708
+
2709
+ ## Examples
2710
+
2711
+ \`\`\`tsx
2712
+ import { lazyRouteComponent } from '@tanstack/react-router'
2713
+
2714
+ const route = createRoute({
2715
+ path: '/posts/$postId',
2716
+ component: lazyRouteComponent(() => import('./Post')), // default export
2717
+ })
2718
+
2719
+ // or
2720
+
2721
+ const route = createRoute({
2722
+ path: '/posts/$postId',
2723
+ component: lazyRouteComponent(
2724
+ () => import('./Post'),
2725
+ 'PostByIdPageComponent', // named export
2726
+ ),
2727
+ })
2728
+ \`\`\`
2729
+
2730
+ # Link component
2731
+
2732
+ The \`Link\` component is a component that can be used to create a link that can be used to navigate to a new location. This includes changes to the pathname, search params, hash, and location state.
2733
+
2734
+ ## Link props
2735
+
2736
+ The \`Link\` component accepts the following props:
2737
+
2738
+ ### \`...props\`
2739
+
2740
+ - Type: \`LinkProps & React.RefAttributes<HTMLAnchorElement>\`
2741
+ - [\`LinkProps\`](../LinkPropsType.md)
2742
+
2743
+ ## Link returns
2744
+
2745
+ An anchor element that can be used to navigate to a new location.
2746
+
2747
+ ## Examples
2748
+
2749
+ \`\`\`tsx
2750
+ import { Link } from '@tanstack/react-router'
2751
+
2752
+ function Component() {
2753
+ return (
2754
+ <Link
2755
+ to="/somewhere/$somewhereId"
2756
+ params={{ somewhereId: 'baz' }}
2757
+ search={(prev) => ({ ...prev, foo: 'bar' })}
2758
+ >
2759
+ Click me
2760
+ </Link>
2761
+ )
2762
+ }
2763
+ \`\`\`
2764
+
2765
+ # Link options
2766
+
2767
+ \`linkOptions\` is a function which type checks an object literal with the intention of being used for \`Link\`, \`navigate\` or \`redirect\`
2768
+
2769
+ ## linkOptions props
2770
+
2771
+ The \`linkOptions\` accepts the following option:
2772
+
2773
+ ### \`...props\`
2774
+
2775
+ - Type: \`LinkProps & React.RefAttributes<HTMLAnchorElement>\`
2776
+ - [\`LinkProps\`](../LinkPropsType.md)
2777
+
2778
+ ## \`linkOptions\` returns
2779
+
2780
+ An object literal with the exact type inferred from the input
2781
+
2782
+ ## Examples
2783
+
2784
+ \`\`\`tsx
2785
+ const userLinkOptions = linkOptions({
2786
+ to: '/dashboard/users/user',
2787
+ search: {
2788
+ usersView: {
2789
+ sortBy: 'email',
2790
+ filterBy: 'filter',
2791
+ },
2792
+ userId: 0,
2793
+ },
2794
+ })
2795
+
2796
+ function DashboardComponent() {
2797
+ return <Link {...userLinkOptions} />
2798
+ }
2799
+ \`\`\`
2800
+
2801
+ # MatchRoute component
2802
+
2803
+ A component version of the \`useMatchRoute\` hook. It accepts the same options as the \`useMatchRoute\` with additional props to aid in conditional rendering.
2804
+
2805
+ ## MatchRoute props
2806
+
2807
+ The \`MatchRoute\` component accepts the same options as the \`useMatchRoute\` hook with additional props to aid in conditional rendering.
2808
+
2809
+ ### \`...props\` prop
2810
+
2811
+ - Type: [\`UseMatchRouteOptions\`](../UseMatchRouteOptionsType.md)
2812
+
2813
+ ### \`children\` prop
2814
+
2815
+ - Optional
2816
+ - \`React.ReactNode\`
2817
+ - The component that will be rendered if the route is matched.
2818
+ - \`((params: TParams | false) => React.ReactNode)\`
2819
+ - A function that will be called with the matched route's params or \`false\` if no route was matched. This can be useful for components that need to always render, but render different props based on a route match or not.
2820
+
2821
+ ## MatchRoute returns
2822
+
2823
+ Either the \`children\` prop or the return value of the \`children\` function.
2824
+
2825
+ ## Examples
2826
+
2827
+ \`\`\`tsx
2828
+ import { MatchRoute } from '@tanstack/react-router'
2829
+
2830
+ function Component() {
2831
+ return (
2832
+ <div>
2833
+ <MatchRoute to="/posts/$postId" params={{ postId: '123' }} pending>
2834
+ {(match) => <Spinner show={!!match} wait="delay-50" />}
2835
+ </MatchRoute>
2836
+ </div>
2837
+ )
2838
+ }
2839
+ \`\`\`
2840
+
2841
+ # Navigate component
2842
+
2843
+ The \`Navigate\` component is a component that can be used to navigate to a new location when rendered. This includes changes to the pathname, search params, hash, and location state. The underlying navigation will happen inside of a \`useEffect\` hook when successfully rendered.
2844
+
2845
+ ## Navigate props
2846
+
2847
+ The \`Navigate\` component accepts the following props:
2848
+
2849
+ ### \`...options\`
2850
+
2851
+ - Type: [\`NavigateOptions\`](../NavigateOptionsType.md)
2852
+
2853
+ ## Navigate returns
2854
+
2855
+ - \`null\`
2856
+
2857
+ # notFound function
2858
+
2859
+ The \`notFound\` function returns a new \`NotFoundError\` object that can be either returned or thrown from places like a Route's \`beforeLoad\` or \`loader\` callbacks to trigger the \`notFoundComponent\`.
2860
+
2861
+ ## notFound options
2862
+
2863
+ The \`notFound\` function accepts a single optional argument, the \`options\` to create the not-found error object.
2864
+
2865
+ - Type: [\`Partial<NotFoundError>\`](../NotFoundErrorType.md)
2866
+ - Optional
2867
+
2868
+ ## notFound returns
2869
+
2870
+ - If the \`throw\` property is \`true\` in the \`options\` object, the \`NotFoundError\` object will be thrown from within the function call.
2871
+ - If the \`throw\` property is \`false | undefined\` in the \`options\` object, the \`NotFoundError\` object will be returned.
2872
+
2873
+ ## Examples
2874
+
2875
+ \`\`\`tsx
2876
+ import { notFound, createFileRoute, rootRouteId } from '@tanstack/react-router'
2877
+
2878
+ const Route = new createFileRoute('/posts/$postId')({
2879
+ // throwing a not-found object
2880
+ loader: ({ context: { post } }) => {
2881
+ if (!post) {
2882
+ throw notFound()
2883
+ }
2884
+ },
2885
+ // or if you want to show a not-found on the whole page
2886
+ loader: ({ context: { team } }) => {
2887
+ if (!team) {
2888
+ throw notFound({ routeId: rootRouteId })
2889
+ }
2890
+ },
2891
+ // ... other route options
2892
+ })
2893
+ \`\`\`
2894
+
2895
+ # Outlet component
2896
+
2897
+ The \`Outlet\` component is a component that can be used to render the next child route of a parent route.
2898
+
2899
+ ## Outlet props
2900
+
2901
+ The \`Outlet\` component does not accept any props.
2902
+
2903
+ ## Outlet returns
2904
+
2905
+ - If matched, the child route match's \`component\`/\`errorComponent\`/\`pendingComponent\`/\`notFoundComponent\`.
2906
+ - If not matched, \`null\`.
2907
+
2908
+ # redirect function
2909
+
2910
+ The \`redirect\` function returns a new \`Redirect\` object that can be either returned or thrown from places like a Route's \`beforeLoad\` or \`loader\` callbacks to trigger _redirect_ to a new location.
2911
+
2912
+ ## redirect options
2913
+
2914
+ The \`redirect\` function accepts a single argument, the \`options\` to determine the redirect behavior.
2915
+
2916
+ - Type: [\`Redirect\`](../RedirectType.md)
2917
+ - Required
2918
+
2919
+ ## redirect returns
2920
+
2921
+ - If the \`throw\` property is \`true\` in the \`options\` object, the \`Redirect\` object will be thrown from within the function call.
2922
+ - If the \`throw\` property is \`false | undefined\` in the \`options\` object, the \`Redirect\` object will be returned.
2923
+
2924
+ ## Examples
2925
+
2926
+ \`\`\`tsx
2927
+ import { redirect } from '@tanstack/react-router'
2928
+
2929
+ const route = createRoute({
2930
+ // throwing a redirect object
2931
+ loader: () => {
2932
+ if (!user) {
2933
+ throw redirect({
2934
+ to: '/login',
2935
+ })
2936
+ }
2937
+ },
2938
+ // or forcing \`redirect\` to throw itself
2939
+ loader: () => {
2940
+ if (!user) {
2941
+ redirect({
2942
+ to: '/login',
2943
+ throw: true,
2944
+ })
2945
+ }
2946
+ },
2947
+ // ... other route options
2948
+ })
2949
+ \`\`\`
2950
+
2951
+ # Search middleware to retain search params
2952
+
2953
+ \`retainSearchParams\` is a search middleware that allows to keep search params.
2954
+
2955
+ ## retainSearchParams props
2956
+
2957
+ The \`retainSearchParams\` either accepts \`true\` or a list of keys of those search params that shall be retained.
2958
+ If \`true\` is passed in, all search params will be retained.
2959
+
2960
+ ## Examples
2961
+
2962
+ \`\`\`tsx
2963
+ import { z } from 'zod'
2964
+ import { createRootRoute, retainSearchParams } from '@tanstack/react-router'
2965
+ import { zodValidator } from '@tanstack/zod-adapter'
2966
+
2967
+ const searchSchema = z.object({
2968
+ rootValue: z.string().optional(),
2969
+ })
2970
+
2971
+ export const Route = createRootRoute({
2972
+ validateSearch: zodValidator(searchSchema),
2973
+ search: {
2974
+ middlewares: [retainSearchParams(['rootValue'])],
2975
+ },
2976
+ })
2977
+ \`\`\`
2978
+
2979
+ \`\`\`tsx
2980
+ import { z } from 'zod'
2981
+ import { createFileRoute, retainSearchParams } from '@tanstack/react-router'
2982
+ import { zodValidator } from '@tanstack/zod-adapter'
2983
+
2984
+ const searchSchema = z.object({
2985
+ one: z.string().optional(),
2986
+ two: z.string().optional(),
2987
+ })
2988
+
2989
+ export const Route = createFileRoute('/hello')({
2990
+ validateSearch: zodValidator(searchSchema),
2991
+ search: {
2992
+ middlewares: [retainSearchParams(true)],
2993
+ },
2994
+ })
2995
+ \`\`\`
2996
+
2997
+ # rootRouteWithContext function
2998
+
2999
+ > [!CAUTION]
3000
+ > This function is deprecated and will be removed in the next major version of TanStack Router.
3001
+ > Please use the [\`createRootRouteWithContext\`](../createRootRouteWithContextFunction.md) function instead.
3002
+
3003
+ The \`rootRouteWithContext\` function is a helper function that can be used to create a root route instance that requires a context type to be fulfilled when the router is created.
3004
+
3005
+ ## rootRouteWithContext generics
3006
+
3007
+ The \`rootRouteWithContext\` function accepts a single generic argument:
3008
+
3009
+ ### \`TRouterContext\` generic
3010
+
3011
+ - Type: \`TRouterContext\`
3012
+ - Optional, **but recommended**.
3013
+ - The context type that will be required to be fulfilled when the router is created
3014
+
3015
+ ## rootRouteWithContext returns
3016
+
3017
+ - A factory function that can be used to create a new [\`createRootRoute\`](../createRootRouteFunction.md) instance.
3018
+ - It accepts a single argument, the same as the [\`createRootRoute\`](../createRootRouteFunction.md) function.
3019
+
3020
+ ## Examples
3021
+
3022
+ \`\`\`tsx
3023
+ import { rootRouteWithContext, createRouter } from '@tanstack/react-router'
3024
+ import { QueryClient } from '@tanstack/react-query'
3025
+
3026
+ interface MyRouterContext {
3027
+ queryClient: QueryClient
3028
+ }
3029
+
3030
+ const rootRoute = rootRouteWithContext<MyRouterContext>()({
3031
+ component: () => <Outlet />,
3032
+ // ... root route options
3033
+ })
3034
+
3035
+ const routeTree = rootRoute.addChildren([
3036
+ // ... other routes
3037
+ ])
3038
+
3039
+ const queryClient = new QueryClient()
3040
+
3041
+ const router = createRouter({
3042
+ routeTree,
3043
+ context: {
3044
+ queryClient,
3045
+ },
3046
+ })
3047
+ \`\`\`
3048
+
3049
+ # Search middleware to strip search params
3050
+
3051
+ \`stripSearchParams\` is a search middleware that allows to remove search params.
3052
+
3053
+ ## stripSearchParams props
3054
+
3055
+ \`stripSearchParams\` accepts one of the following inputs:
3056
+
3057
+ - \`true\`: if the search schema has no required params, \`true\` can be used to strip all search params
3058
+ - a list of keys of those search params that shall be removed; only keys of optional search params are allowed.
3059
+ - an object that conforms to the partial input search schema. The search params are compared against the values of this object; if the value is deeply equal, it will be removed. This is especially useful to strip out default search params.
3060
+
3061
+ ## Examples
3062
+
3063
+ \`\`\`tsx
3064
+ import { z } from 'zod'
3065
+ import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
3066
+ import { zodValidator } from '@tanstack/zod-adapter'
3067
+
3068
+ const defaultValues = {
3069
+ one: 'abc',
3070
+ two: 'xyz',
3071
+ }
3072
+
3073
+ const searchSchema = z.object({
3074
+ one: z.string().default(defaultValues.one),
3075
+ two: z.string().default(defaultValues.two),
3076
+ })
3077
+
3078
+ export const Route = createFileRoute('/hello')({
3079
+ validateSearch: zodValidator(searchSchema),
3080
+ search: {
3081
+ // strip default values
3082
+ middlewares: [stripSearchParams(defaultValues)],
3083
+ },
3084
+ })
3085
+ \`\`\`
3086
+
3087
+ \`\`\`tsx
3088
+ import { z } from 'zod'
3089
+ import { createRootRoute, stripSearchParams } from '@tanstack/react-router'
3090
+ import { zodValidator } from '@tanstack/zod-adapter'
3091
+
3092
+ const searchSchema = z.object({
3093
+ hello: z.string().default('world'),
3094
+ requiredParam: z.string(),
3095
+ })
3096
+
3097
+ export const Route = createRootRoute({
3098
+ validateSearch: zodValidator(searchSchema),
3099
+ search: {
3100
+ // always remove \`hello\`
3101
+ middlewares: [stripSearchParams(['hello'])],
3102
+ },
3103
+ })
3104
+ \`\`\`
3105
+
3106
+ \`\`\`tsx
3107
+ import { z } from 'zod'
3108
+ import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
3109
+ import { zodValidator } from '@tanstack/zod-adapter'
3110
+
3111
+ const searchSchema = z.object({
3112
+ one: z.string().default('abc'),
3113
+ two: z.string().default('xyz'),
3114
+ })
3115
+
3116
+ export const Route = createFileRoute('/hello')({
3117
+ validateSearch: zodValidator(searchSchema),
3118
+ search: {
3119
+ // remove all search params
3120
+ middlewares: [stripSearchParams(true)],
3121
+ },
3122
+ })
3123
+ \`\`\`
3124
+
3125
+ # useAwaited hook
3126
+
3127
+ The \`useAwaited\` method is a hook that suspends until the provided promise is resolved or rejected.
3128
+
3129
+ ## useAwaited options
3130
+
3131
+ The \`useAwaited\` hook accepts a single argument, an \`options\` object.
3132
+
3133
+ ### \`options.promise\` option
3134
+
3135
+ - Type: \`Promise<T>\`
3136
+ - Required
3137
+ - The deferred promise to await.
3138
+
3139
+ ## useAwaited returns
3140
+
3141
+ - Throws an error if the promise is rejected.
3142
+ - Suspends (throws a promise) if the promise is pending.
3143
+ - Returns the resolved value of a deferred promise if the promise is resolved.
3144
+
3145
+ ## Examples
3146
+
3147
+ \`\`\`tsx
3148
+ import { useAwaited } from '@tanstack/react-router'
3149
+
3150
+ function Component() {
3151
+ const { deferredPromise } = route.useLoaderData()
3152
+
3153
+ const data = useAwaited({ promise: myDeferredPromise })
3154
+ // ...
3155
+ }
3156
+ \`\`\`
3157
+
3158
+ # useBlocker hook
3159
+
3160
+ The \`useBlocker\` method is a hook that [blocks navigation](../../../guide/navigation-blocking.md) when a condition is met.
3161
+
3162
+ > ⚠️ The following new \`useBlocker\` API is currently _experimental_.
3163
+
3164
+ ## useBlocker options
3165
+
3166
+ The \`useBlocker\` hook accepts a single _required_ argument, an option object:
3167
+
3168
+ ### \`options.shouldBlockFn\` option
3169
+
3170
+ - Required
3171
+ - Type: \`ShouldBlockFn\`
3172
+ - This function should return a \`boolean\` or a \`Promise<boolean>\` that tells the blocker if it should block the current navigation
3173
+ - The function has the argument of type \`ShouldBlockFnArgs\` passed to it, which tells you information about the current and next route and the action performed
3174
+ - Think of this function as telling the router if it should block the navigation, so returning \`true\` mean that it should block the navigation and \`false\` meaning that it should be allowed
3175
+
3176
+ \`\`\`ts
3177
+ interface ShouldBlockFnLocation<...> {
3178
+ routeId: TRouteId
3179
+ fullPath: TFullPath
3180
+ pathname: string
3181
+ params: TAllParams
3182
+ search: TFullSearchSchema
3183
+ }
3184
+
3185
+ type ShouldBlockFnArgs = {
3186
+ current: ShouldBlockFnLocation
3187
+ next: ShouldBlockFnLocation
3188
+ action: HistoryAction
3189
+ }
3190
+ \`\`\`
3191
+
3192
+ ### \`options.disabled\` option
3193
+
3194
+ - Optional - defaults to \`false\`
3195
+ - Type: \`boolean\`
3196
+ - Specifies if the blocker should be entirely disabled or not
3197
+
3198
+ ### \`options.enableBeforeUnload\` option
3199
+
3200
+ - Optional - defaults to \`true\`
3201
+ - Type: \`boolean | (() => boolean)\`
3202
+ - Tell the blocker to sometimes or always block the browser \`beforeUnload\` event or not
3203
+
3204
+ ### \`options.withResolver\` option
3205
+
3206
+ - Optional - defaults to \`false\`
3207
+ - Type: \`boolean\`
3208
+ - Specify if the resolver returned by the hook should be used or whether your \`shouldBlockFn\` function itself resolves the blocking
3209
+
3210
+ ### \`options.blockerFn\` option (⚠️ deprecated)
3211
+
3212
+ - Optional
3213
+ - Type: \`BlockerFn\`
3214
+ - The function that returns a \`boolean\` or \`Promise<boolean>\` indicating whether to allow navigation.
3215
+
3216
+ ### \`options.condition\` option (⚠️ deprecated)
3217
+
3218
+ - Optional - defaults to \`true\`
3219
+ - Type: \`boolean\`
3220
+ - A navigation attempt is blocked when this condition is \`true\`.
3221
+
3222
+ ## useBlocker returns
3223
+
3224
+ An object with the controls to allow manual blocking and unblocking of navigation.
3225
+
3226
+ - \`status\` - A string literal that can be either \`'blocked'\` or \`'idle'\`
3227
+ - \`next\` - When status is \`blocked\`, a type narrrowable object that contains information about the next location
3228
+ - \`current\` - When status is \`blocked\`, a type narrrowable object that contains information about the current location
3229
+ - \`action\` - When status is \`blocked\`, a \`HistoryAction\` string that shows the action that triggered the navigation
3230
+ - \`proceed\` - When status is \`blocked\`, a function that allows navigation to continue
3231
+ - \`reset\` - When status is \`blocked\`, a function that cancels navigation (\`status\` will be reset to \`'idle'\`)
3232
+
3233
+ or
3234
+
3235
+ \`void\` when \`withResolver\` is \`false\`
3236
+
3237
+ ## Examples
3238
+
3239
+ Two common use cases for the \`useBlocker\` hook are:
3240
+
3241
+ ### Basic usage
3242
+
3243
+ \`\`\`tsx
3244
+ import { useBlocker } from '@tanstack/react-router'
3245
+
3246
+ function MyComponent() {
3247
+ const [formIsDirty, setFormIsDirty] = useState(false)
3248
+
3249
+ useBlocker({
3250
+ shouldBlockFn: () => formIsDirty,
3251
+ })
3252
+
3253
+ // ...
3254
+ }
3255
+ \`\`\`
3256
+
3257
+ ### Custom UI
3258
+
3259
+ \`\`\`tsx
3260
+ import { useBlocker } from '@tanstack/react-router'
3261
+
3262
+ function MyComponent() {
3263
+ const [formIsDirty, setFormIsDirty] = useState(false)
3264
+
3265
+ const { proceed, reset, status, next } = useBlocker({
3266
+ shouldBlockFn: () => formIsDirty,
3267
+ withResolver: true,
3268
+ })
3269
+
3270
+ // ...
3271
+
3272
+ return (
3273
+ <>
3274
+ {/* ... */}
3275
+ {status === 'blocked' && (
3276
+ <div>
3277
+ <p>You are navigating to {next.pathname}</p>
3278
+ <p>Are you sure you want to leave?</p>
3279
+ <button onClick={proceed}>Yes</button>
3280
+ <button onClick={reset}>No</button>
3281
+ </div>
3282
+ )}
3283
+ </>
3284
+ }
3285
+ \`\`\`
3286
+
3287
+ ### Conditional blocking
3288
+
3289
+ \`\`\`tsx
3290
+ import { useBlocker } from '@tanstack/react-router'
3291
+
3292
+ function MyComponent() {
3293
+ const { proceed, reset, status } = useBlocker({
3294
+ shouldBlockFn: ({ next }) => {
3295
+ return !next.pathname.includes('step/')
3296
+ },
3297
+ withResolver: true,
3298
+ })
3299
+
3300
+ // ...
3301
+
3302
+ return (
3303
+ <>
3304
+ {/* ... */}
3305
+ {status === 'blocked' && (
3306
+ <div>
3307
+ <p>Are you sure you want to leave?</p>
3308
+ <button onClick={proceed}>Yes</button>
3309
+ <button onClick={reset}>No</button>
3310
+ </div>
3311
+ )}
3312
+ </>
3313
+ )
3314
+ }
3315
+ \`\`\`
3316
+
3317
+ ### Without resolver
3318
+
3319
+ \`\`\`tsx
3320
+ import { useBlocker } from '@tanstack/react-router'
3321
+
3322
+ function MyComponent() {
3323
+ const [formIsDirty, setFormIsDirty] = useState(false)
3324
+
3325
+ useBlocker({
3326
+ shouldBlockFn: ({ next }) => {
3327
+ if (next.pathname.includes('step/')) {
3328
+ return false
3329
+ }
3330
+
3331
+ const shouldLeave = confirm('Are you sure you want to leave?')
3332
+ return !shouldLeave
3333
+ },
3334
+ })
3335
+
3336
+ // ...
3337
+ }
3338
+ \`\`\`
3339
+
3340
+ ### Type narrowing
3341
+
3342
+ \`\`\`tsx
3343
+ import { useBlocker } from '@tanstack/react-router'
3344
+
3345
+ function MyComponent() {
3346
+ const [formIsDirty, setFormIsDirty] = useState(false)
3347
+
3348
+ // block going from editor-1 to /foo/123?hello=world
3349
+ const { proceed, reset, status } = useBlocker({
3350
+ shouldBlockFn: ({ current, next }) => {
3351
+ if (
3352
+ current.routeId === '/editor-1' &&
3353
+ next.fullPath === '/foo/$id' &&
3354
+ next.params.id === '123' &&
3355
+ next.search.hello === 'world'
3356
+ ) {
3357
+ return true
3358
+ }
3359
+ return false
3360
+ },
3361
+ enableBeforeUnload: false,
3362
+ withResolver: true,
3363
+ })
3364
+
3365
+ // ...
3366
+ }
3367
+ \`\`\`
3368
+
3369
+ # useCanGoBack hook
3370
+
3371
+ The \`useCanGoBack\` hook returns a boolean representing if the router history can safely go back without exiting the application.
3372
+
3373
+ > ⚠️ The following new \`useCanGoBack\` API is currently _experimental_.
3374
+
3375
+ ## useCanGoBack returns
3376
+
3377
+ - If the router history is not at index \`0\`, \`true\`.
3378
+ - If the router history is at index \`0\`, \`false\`.
3379
+
3380
+ ## Limitations
3381
+
3382
+ The router history index is reset after a navigation with [\`reloadDocument\`](../NavigateOptionsType.md#reloaddocument) set as \`true\`. This causes the router history to consider the new location as the initial one and will cause \`useCanGoBack\` to return \`false\`.
3383
+
3384
+ ## Examples
3385
+
3386
+ ### Showing a back button
3387
+
3388
+ \`\`\`tsx
3389
+ import { useRouter, useCanGoBack } from '@tanstack/react-router'
3390
+
3391
+ function Component() {
3392
+ const router = useRouter()
3393
+ const canGoBack = useCanGoBack()
3394
+
3395
+ return (
3396
+ <div>
3397
+ {canGoBack ? (
3398
+ <button onClick={() => router.history.back()}>Go back</button>
3399
+ ) : null}
3400
+
3401
+ {/* ... */}
3402
+ </div>
3403
+ )
3404
+ }
3405
+ \`\`\`
3406
+
3407
+ # useChildMatches hook
3408
+
3409
+ The \`useChildMatches\` hook returns all of the child [\`RouteMatch\`](../RouteMatchType.md) objects from the closest match down to the leaf-most match. **It does not include the current match, which can be obtained using the \`useMatch\` hook.**
3410
+
3411
+ > [!IMPORTANT]
3412
+ > If the router has pending matches and they are showing their pending component fallbacks, \`router.state.pendingMatches\` will used instead of \`router.state.matches\`.
3413
+
3414
+ ## useChildMatches options
3415
+
3416
+ The \`useChildMatches\` hook accepts a single _optional_ argument, an \`options\` object.
3417
+
3418
+ ### \`opts.select\` option
3419
+
3420
+ - Optional
3421
+ - \`(matches: RouteMatch[]) => TSelected\`
3422
+ - If supplied, this function will be called with the route matches and the return value will be returned from \`useChildMatches\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3423
+
3424
+ ### \`opts.structuralSharing\` option
3425
+
3426
+ - Type: \`boolean\`
3427
+ - Optional
3428
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3429
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3430
+
3431
+ ## useChildMatches returns
3432
+
3433
+ - If a \`select\` function is provided, the return value of the \`select\` function.
3434
+ - If no \`select\` function is provided, an array of [\`RouteMatch\`](../RouteMatchType.md) objects.
3435
+
3436
+ ## Examples
3437
+
3438
+ \`\`\`tsx
3439
+ import { useChildMatches } from '@tanstack/react-router'
3440
+
3441
+ function Component() {
3442
+ const childMatches = useChildMatches()
3443
+ // ...
3444
+ }
3445
+ \`\`\`
3446
+
3447
+ # useLinkProps hook
3448
+
3449
+ The \`useLinkProps\` hook that takes an object as its argument and returns a \`React.AnchorHTMLAttributes<HTMLAnchorElement>\` props object. These props can then be safely applied to an anchor element to create a link that can be used to navigate to the new location. This includes changes to the pathname, search params, hash, and location state.
3450
+
3451
+ ## useLinkProps options
3452
+
3453
+ \`\`\`tsx
3454
+ type UseLinkPropsOptions = ActiveLinkOptions &
3455
+ React.AnchorHTMLAttributes<HTMLAnchorElement>
3456
+ \`\`\`
3457
+
3458
+ - [\`ActiveLinkOptions\`](../ActiveLinkOptionsType.md)
3459
+ - The \`useLinkProps\` options are used to build a [\`LinkProps\`](../LinkPropsType.md) object.
3460
+ - It also extends the \`React.AnchorHTMLAttributes<HTMLAnchorElement>\` type, so that any additional props that are passed to the \`useLinkProps\` hook will be merged with the [\`LinkProps\`](../LinkPropsType.md) object.
3461
+
3462
+ ## useLinkProps returns
3463
+
3464
+ - A \`React.AnchorHTMLAttributes<HTMLAnchorElement>\` object that can be applied to an anchor element to create a link that can be used to navigate to the new location
3465
+
3466
+ # useLoaderData hook
3467
+
3468
+ The \`useLoaderData\` hook returns the loader data from the closest [\`RouteMatch\`](../RouteMatchType.md) in the component tree.
3469
+
3470
+ ## useLoaderData options
3471
+
3472
+ The \`useLoaderData\` hook accepts an \`options\` object.
3473
+
3474
+ ### \`opts.from\` option
3475
+
3476
+ - Type: \`string\`
3477
+ - The route id of the closest parent match
3478
+ - Optional, but recommended for full type safety.
3479
+ - If \`opts.strict\` is \`true\`, TypeScript will warn for this option if it is not provided.
3480
+ - If \`opts.strict\` is \`false\`, TypeScript will provided loosened types for the returned loader data.
3481
+
3482
+ ### \`opts.strict\` option
3483
+
3484
+ - Type: \`boolean\`
3485
+ - Optional - \`default: true\`
3486
+ - If \`false\`, the \`opts.from\` option will be ignored and types will be loosened to to reflect the shared types of all possible loader data.
3487
+
3488
+ ### \`opts.select\` option
3489
+
3490
+ - Optional
3491
+ - \`(loaderData: TLoaderData) => TSelected\`
3492
+ - If supplied, this function will be called with the loader data and the return value will be returned from \`useLoaderData\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3493
+
3494
+ ### \`opts.structuralSharing\` option
3495
+
3496
+ - Type: \`boolean\`
3497
+ - Optional
3498
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3499
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3500
+
3501
+ ## useLoaderData returns
3502
+
3503
+ - If a \`select\` function is provided, the return value of the \`select\` function.
3504
+ - If no \`select\` function is provided, the loader data or a loosened version of the loader data if \`opts.strict\` is \`false\`.
3505
+
3506
+ ## Examples
3507
+
3508
+ \`\`\`tsx
3509
+ import { useLoaderData } from '@tanstack/react-router'
3510
+
3511
+ function Component() {
3512
+ const loaderData = useLoaderData({ from: '/posts/$postId' })
3513
+ // ^? { postId: string, body: string, ... }
3514
+ // ...
3515
+ }
3516
+ \`\`\`
3517
+
3518
+ # useLoaderDeps hook
3519
+
3520
+ The \`useLoaderDeps\` hook is a hook that returns an object with the dependencies that are used to trigger the \`loader\` for a given route.
3521
+
3522
+ ## useLoaderDepsHook options
3523
+
3524
+ The \`useLoaderDepsHook\` hook accepts an \`options\` object.
3525
+
3526
+ ### \`opts.from\` option
3527
+
3528
+ - Type: \`string\`
3529
+ - Required
3530
+ - The RouteID or path to get the loader dependencies from.
3531
+
3532
+ ### \`opts.select\` option
3533
+
3534
+ - Type: \`(deps: TLoaderDeps) => TSelected\`
3535
+ - Optional
3536
+ - If supplied, this function will be called with the loader dependencies object and the return value will be returned from \`useLoaderDeps\`.
3537
+
3538
+ ### \`opts.structuralSharing\` option
3539
+
3540
+ - Type: \`boolean\`
3541
+ - Optional
3542
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3543
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3544
+
3545
+ ## useLoaderDeps returns
3546
+
3547
+ - An object of the loader dependencies or \`TSelected\` if a \`select\` function is provided.
3548
+
3549
+ ## Examples
3550
+
3551
+ \`\`\`tsx
3552
+ import { useLoaderDeps } from '@tanstack/react-router'
3553
+
3554
+ const routeApi = getRouteApi('/posts/$postId')
3555
+
3556
+ function Component() {
3557
+ const deps = useLoaderDeps({ from: '/posts/$postId' })
3558
+
3559
+ // OR
3560
+
3561
+ const routeDeps = routeApi.useLoaderDeps()
3562
+
3563
+ // OR
3564
+
3565
+ const postId = useLoaderDeps({
3566
+ from: '/posts',
3567
+ select: (deps) => deps.view,
3568
+ })
3569
+
3570
+ // ...
3571
+ }
3572
+ \`\`\`
3573
+
3574
+ # useLocation hook
3575
+
3576
+ The \`useLocation\` method is a hook that returns the current [\`location\`](../ParsedLocationType.md) object. This hook is useful for when you want to perform some side effect whenever the current location changes.
3577
+
3578
+ ## useLocation options
3579
+
3580
+ The \`useLocation\` hook accepts an optional \`options\` object.
3581
+
3582
+ ### \`opts.select\` option
3583
+
3584
+ - Type: \`(state: ParsedLocationType) => TSelected\`
3585
+ - Optional
3586
+ - If supplied, this function will be called with the [\`location\`](../ParsedLocationType.md) object and the return value will be returned from \`useLocation\`.
3587
+
3588
+ ## useLocation returns
3589
+
3590
+ - The current [\`location\`](../ParsedLocationType.md) object or \`TSelected\` if a \`select\` function is provided.
3591
+
3592
+ ## Examples
3593
+
3594
+ \`\`\`tsx
3595
+ import { useLocation } from '@tanstack/react-router'
3596
+
3597
+ function Component() {
3598
+ const location = useLocation()
3599
+ // ^ ParsedLocation
3600
+
3601
+ // OR
3602
+
3603
+ const pathname = useLocation({
3604
+ select: (location) => location.pathname,
3605
+ })
3606
+ // ^ string
3607
+
3608
+ // ...
3609
+ }
3610
+ \`\`\`
3611
+
3612
+ # useMatch hook
3613
+
3614
+ The \`useMatch\` hook returns a [\`RouteMatch\`](../RouteMatchType.md) in the component tree. The raw route match contains all of the information about a route match in the router and also powers many other hooks under the hood like \`useParams\`, \`useLoaderData\`, \`useRouteContext\`, and \`useSearch\`.
3615
+
3616
+ ## useMatch options
3617
+
3618
+ The \`useMatch\` hook accepts a single argument, an \`options\` object.
3619
+
3620
+ ### \`opts.from\` option
3621
+
3622
+ - Type: \`string\`
3623
+ - The route id of a match
3624
+ - Optional, but recommended for full type safety.
3625
+ - If \`opts.strict\` is \`true\`, \`from\` is required and TypeScript will warn for this option if it is not provided.
3626
+ - If \`opts.strict\` is \`false\`, \`from\` must not be set and TypeScript will provided loosened types for the returned [\`RouteMatch\`](../RouteMatchType.md).
3627
+
3628
+ ### \`opts.strict\` option
3629
+
3630
+ - Type: \`boolean\`
3631
+ - Optional
3632
+ - \`default: true\`
3633
+ - If \`false\`, the \`opts.from\` must not be set and types will be loosened to \`Partial<RouteMatch>\` to reflect the shared types of all matches.
3634
+
3635
+ ### \`opts.select\` option
3636
+
3637
+ - Optional
3638
+ - \`(match: RouteMatch) => TSelected\`
3639
+ - If supplied, this function will be called with the route match and the return value will be returned from \`useMatch\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3640
+
3641
+ ### \`opts.structuralSharing\` option
3642
+
3643
+ - Type: \`boolean\`
3644
+ - Optional
3645
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3646
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3647
+
3648
+ ### \`opts.shouldThrow\` option
3649
+
3650
+ - Type: \`boolean\`
3651
+ - Optional
3652
+ - \`default: true\`
3653
+ - If \`false\`,\`useMatch\` will not throw an invariant exception in case a match was not found in the currently rendered matches; in this case, it will return \`undefined\`.
3654
+
3655
+ ## useMatch returns
3656
+
3657
+ - If a \`select\` function is provided, the return value of the \`select\` function.
3658
+ - If no \`select\` function is provided, the [\`RouteMatch\`](../RouteMatchType.md) object or a loosened version of the \`RouteMatch\` object if \`opts.strict\` is \`false\`.
3659
+
3660
+ ## Examples
3661
+
3662
+ ### Accessing a route match
3663
+
3664
+ \`\`\`tsx
3665
+ import { useMatch } from '@tanstack/react-router'
3666
+
3667
+ function Component() {
3668
+ const match = useMatch({ from: '/posts/$postId' })
3669
+ // ^? strict match for RouteMatch
3670
+ // ...
3671
+ }
3672
+ \`\`\`
3673
+
3674
+ ### Accessing the root route's match
3675
+
3676
+ \`\`\`tsx
3677
+ import {
3678
+ useMatch,
3679
+ rootRouteId, // <<<< use this token!
3680
+ } from '@tanstack/react-router'
3681
+
3682
+ function Component() {
3683
+ const match = useMatch({ from: rootRouteId })
3684
+ // ^? strict match for RouteMatch
3685
+ // ...
3686
+ }
3687
+ \`\`\`
3688
+
3689
+ ### Checking if a specific route is currently rendered
3690
+
3691
+ \`\`\`tsx
3692
+ import { useMatch } from '@tanstack/react-router'
3693
+
3694
+ function Component() {
3695
+ const match = useMatch({ from: '/posts', shouldThrow: false })
3696
+ // ^? RouteMatch | undefined
3697
+ if (match !== undefined) {
3698
+ // ...
3699
+ }
3700
+ }
3701
+ \`\`\`
3702
+
3703
+ # useMatchRoute hook
3704
+
3705
+ The \`useMatchRoute\` hook is a hook that returns a \`matchRoute\` function that can be used to match a route against either the current or pending location.
3706
+
3707
+ ## useMatchRoute returns
3708
+
3709
+ - A \`matchRoute\` function that can be used to match a route against either the current or pending location.
3710
+
3711
+ ## matchRoute function
3712
+
3713
+ The \`matchRoute\` function is a function that can be used to match a route against either the current or pending location.
3714
+
3715
+ ### matchRoute function options
3716
+
3717
+ The \`matchRoute\` function accepts a single argument, an \`options\` object.
3718
+
3719
+ - Type: [\`UseMatchRouteOptions\`](../UseMatchRouteOptionsType.md)
3720
+
3721
+ ### matchRoute function returns
3722
+
3723
+ - The matched route's params or \`false\` if no route was matched
3724
+
3725
+ ## Examples
3726
+
3727
+ \`\`\`tsx
3728
+ import { useMatchRoute } from '@tanstack/react-router'
3729
+
3730
+ // Current location: /posts/123
3731
+ function Component() {
3732
+ const matchRoute = useMatchRoute()
3733
+ const params = matchRoute({ to: '/posts/$postId' })
3734
+ // ^ { postId: '123' }
3735
+ }
3736
+
3737
+ // Current location: /posts/123
3738
+ function Component() {
3739
+ const matchRoute = useMatchRoute()
3740
+ const params = matchRoute({ to: '/posts' })
3741
+ // ^ false
3742
+ }
3743
+
3744
+ // Current location: /posts/123
3745
+ function Component() {
3746
+ const matchRoute = useMatchRoute()
3747
+ const params = matchRoute({ to: '/posts', fuzzy: true })
3748
+ // ^ {}
3749
+ }
3750
+
3751
+ // Current location: /posts
3752
+ // Pending location: /posts/123
3753
+ function Component() {
3754
+ const matchRoute = useMatchRoute()
3755
+ const params = matchRoute({ to: '/posts/$postId', pending: true })
3756
+ // ^ { postId: '123' }
3757
+ }
3758
+
3759
+ // Current location: /posts/123/foo/456
3760
+ function Component() {
3761
+ const matchRoute = useMatchRoute()
3762
+ const params = matchRoute({ to: '/posts/$postId/foo/$fooId' })
3763
+ // ^ { postId: '123', fooId: '456' }
3764
+ }
3765
+
3766
+ // Current location: /posts/123/foo/456
3767
+ function Component() {
3768
+ const matchRoute = useMatchRoute()
3769
+ const params = matchRoute({
3770
+ to: '/posts/$postId/foo/$fooId',
3771
+ params: { postId: '123' },
3772
+ })
3773
+ // ^ { postId: '123', fooId: '456' }
3774
+ }
3775
+
3776
+ // Current location: /posts/123/foo/456
3777
+ function Component() {
3778
+ const matchRoute = useMatchRoute()
3779
+ const params = matchRoute({
3780
+ to: '/posts/$postId/foo/$fooId',
3781
+ params: { postId: '789' },
3782
+ })
3783
+ // ^ false
3784
+ }
3785
+
3786
+ // Current location: /posts/123/foo/456
3787
+ function Component() {
3788
+ const matchRoute = useMatchRoute()
3789
+ const params = matchRoute({
3790
+ to: '/posts/$postId/foo/$fooId',
3791
+ params: { fooId: '456' },
3792
+ })
3793
+ // ^ { postId: '123', fooId: '456' }
3794
+ }
3795
+
3796
+ // Current location: /posts/123/foo/456
3797
+ function Component() {
3798
+ const matchRoute = useMatchRoute()
3799
+ const params = matchRoute({
3800
+ to: '/posts/$postId/foo/$fooId',
3801
+ params: { postId: '123', fooId: '456' },
3802
+ })
3803
+ // ^ { postId: '123', fooId: '456' }
3804
+ }
3805
+
3806
+ // Current location: /posts/123/foo/456
3807
+ function Component() {
3808
+ const matchRoute = useMatchRoute()
3809
+ const params = matchRoute({
3810
+ to: '/posts/$postId/foo/$fooId',
3811
+ params: { postId: '789', fooId: '456' },
3812
+ })
3813
+ // ^ false
3814
+ }
3815
+ \`\`\`
3816
+
3817
+ # useMatches hook
3818
+
3819
+ The \`useMatches\` hook returns all of the [\`RouteMatch\`](../RouteMatchType.md) objects from the router **regardless of its callers position in the React component tree**.
3820
+
3821
+ > [!TIP]
3822
+ > If you only want the parent or child matches, then you can use the [\`useParentMatches\`](../useParentMatchesHook.md) or the [\`useChildMatches\`](../useChildMatchesHook.md) based on the selection you need.
3823
+
3824
+ ## useMatches options
3825
+
3826
+ The \`useMatches\` hook accepts a single _optional_ argument, an \`options\` object.
3827
+
3828
+ ### \`opts.select\` option
3829
+
3830
+ - Optional
3831
+ - \`(matches: RouteMatch[]) => TSelected\`
3832
+ - If supplied, this function will be called with the route matches and the return value will be returned from \`useMatches\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3833
+
3834
+ ### \`opts.structuralSharing\` option
3835
+
3836
+ - Type: \`boolean\`
3837
+ - Optional
3838
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3839
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3840
+
3841
+ ## useMatches returns
3842
+
3843
+ - If a \`select\` function is provided, the return value of the \`select\` function.
3844
+ - If no \`select\` function is provided, an array of [\`RouteMatch\`](../RouteMatchType.md) objects.
3845
+
3846
+ ## Examples
3847
+
3848
+ \`\`\`tsx
3849
+ import { useMatches } from '@tanstack/react-router'
3850
+
3851
+ function Component() {
3852
+ const matches = useMatches()
3853
+ // ^? [RouteMatch, RouteMatch, ...]
3854
+ // ...
3855
+ }
3856
+ \`\`\`
3857
+
3858
+ # useNavigate hook
3859
+
3860
+ The \`useNavigate\` hook is a hook that returns a \`navigate\` function that can be used to navigate to a new location. This includes changes to the pathname, search params, hash, and location state.
3861
+
3862
+ ## useNavigate options
3863
+
3864
+ The \`useNavigate\` hook accepts a single argument, an \`options\` object.
3865
+
3866
+ ### \`opts.from\` option
3867
+
3868
+ - Type: \`string\`
3869
+ - Optional
3870
+ - Description: The location to navigate from. This is useful when you want to navigate to a new location from a specific location, rather than the current location.
3871
+
3872
+ ## useNavigate returns
3873
+
3874
+ - A \`navigate\` function that can be used to navigate to a new location.
3875
+
3876
+ ## navigate function
3877
+
3878
+ The \`navigate\` function is a function that can be used to navigate to a new location.
3879
+
3880
+ ### navigate function options
3881
+
3882
+ The \`navigate\` function accepts a single argument, an \`options\` object.
3883
+
3884
+ - Type: [\`NavigateOptions\`](../NavigateOptionsType.md)
3885
+
3886
+ ### navigate function returns
3887
+
3888
+ - A \`Promise\` that resolves when the navigation is complete
3889
+
3890
+ ## Examples
3891
+
3892
+ \`\`\`tsx
3893
+ import { useNavigate } from '@tanstack/react-router'
3894
+
3895
+ function PostsPage() {
3896
+ const navigate = useNavigate({ from: '/posts' })
3897
+ const handleClick = () => navigate({ search: { page: 2 } })
3898
+ // ...
3899
+ }
3900
+
3901
+ function Component() {
3902
+ const navigate = useNavigate()
3903
+ return (
3904
+ <div>
3905
+ <button
3906
+ onClick={() =>
3907
+ navigate({
3908
+ to: '/posts',
3909
+ })
3910
+ }
3911
+ >
3912
+ Posts
3913
+ </button>
3914
+ <button
3915
+ onClick={() =>
3916
+ navigate({
3917
+ to: '/posts',
3918
+ search: { page: 2 },
3919
+ })
3920
+ }
3921
+ >
3922
+ Posts (Page 2)
3923
+ </button>
3924
+ <button
3925
+ onClick={() =>
3926
+ navigate({
3927
+ to: '/posts',
3928
+ hash: 'my-hash',
3929
+ })
3930
+ }
3931
+ >
3932
+ Posts (Hash)
3933
+ </button>
3934
+ <button
3935
+ onClick={() =>
3936
+ navigate({
3937
+ to: '/posts',
3938
+ state: { from: 'home' },
3939
+ })
3940
+ }
3941
+ >
3942
+ Posts (State)
3943
+ </button>
3944
+ </div>
3945
+ )
3946
+ }
3947
+ \`\`\`
3948
+
3949
+ # useParams hook
3950
+
3951
+ The \`useParams\` method returns all of the path parameters that were parsed for the closest match and all of its parent matches.
3952
+
3953
+ ## useParams options
3954
+
3955
+ The \`useParams\` hook accepts an optional \`options\` object.
3956
+
3957
+ ### \`opts.strict\` option
3958
+
3959
+ - Type: \`boolean\`
3960
+ - Optional - \`default: true\`
3961
+ - If \`false\`, the \`opts.from\` option will be ignored and types will be loosened to \`Partial<AllParams>\` to reflect the shared types of all params.
3962
+
3963
+ ### \`opts.shouldThrow\` option
3964
+
3965
+ - Type: \`boolean\`
3966
+ - Optional
3967
+ - \`default: true\`
3968
+ - If \`false\`,\`useParams\` will not throw an invariant exception in case a match was not found in the currently rendered matches; in this case, it will return \`undefined\`.
3969
+
3970
+ ### \`opts.select\` option
3971
+
3972
+ - Optional
3973
+ - \`(params: AllParams) => TSelected\`
3974
+ - If supplied, this function will be called with the params object and the return value will be returned from \`useParams\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
3975
+
3976
+ ### \`opts.structuralSharing\` option
3977
+
3978
+ - Type: \`boolean\`
3979
+ - Optional
3980
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
3981
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
3982
+
3983
+ ## useParams returns
3984
+
3985
+ - An object of of the match's and parent match path params or \`TSelected\` if a \`select\` function is provided.
3986
+
3987
+ ## Examples
3988
+
3989
+ \`\`\`tsx
3990
+ import { useParams } from '@tanstack/react-router'
3991
+
3992
+ const routeApi = getRouteApi('/posts/$postId')
3993
+
3994
+ function Component() {
3995
+ const params = useParams({ from: '/posts/$postId' })
3996
+
3997
+ // OR
3998
+
3999
+ const routeParams = routeApi.useParams()
4000
+
4001
+ // OR
4002
+
4003
+ const postId = useParams({
4004
+ from: '/posts/$postId',
4005
+ select: (params) => params.postId,
4006
+ })
4007
+
4008
+ // OR
4009
+
4010
+ const looseParams = useParams({ strict: false })
4011
+
4012
+ // ...
4013
+ }
4014
+ \`\`\`
4015
+
4016
+ # useParentMatches hook
4017
+
4018
+ The \`useParentMatches\` hook returns all of the parent [\`RouteMatch\`](../RouteMatchType.md) objects from the root down to the immediate parent of the current match in context. **It does not include the current match, which can be obtained using the \`useMatch\` hook.**
4019
+
4020
+ > [!IMPORTANT]
4021
+ > If the router has pending matches and they are showing their pending component fallbacks, \`router.state.pendingMatches\` will used instead of \`router.state.matches\`.
4022
+
4023
+ ## useParentMatches options
4024
+
4025
+ The \`useParentMatches\` hook accepts an optional \`options\` object.
4026
+
4027
+ ### \`opts.select\` option
4028
+
4029
+ - Optional
4030
+ - \`(matches: RouteMatch[]) => TSelected\`
4031
+ - If supplied, this function will be called with the route matches and the return value will be returned from \`useParentMatches\`. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks.
4032
+
4033
+ ### \`opts.structuralSharing\` option
4034
+
4035
+ - Type: \`boolean\`
4036
+ - Optional
4037
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
4038
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
4039
+
4040
+ ## useParentMatches returns
4041
+
4042
+ - If a \`select\` function is provided, the return value of the \`select\` function.
4043
+ - If no \`select\` function is provided, an array of [\`RouteMatch\`](../RouteMatchType.md) objects.
4044
+
4045
+ ## Examples
4046
+
4047
+ \`\`\`tsx
4048
+ import { useParentMatches } from '@tanstack/react-router'
4049
+
4050
+ function Component() {
4051
+ const parentMatches = useParentMatches()
4052
+ // ^ [RouteMatch, RouteMatch, ...]
4053
+ }
4054
+ \`\`\`
4055
+
4056
+ # useRouteContext hook
4057
+
4058
+ The \`useRouteContext\` method is a hook that returns the current context for the current route. This hook is useful for accessing the current route context in a component.
4059
+
4060
+ ## useRouteContext options
4061
+
4062
+ The \`useRouteContext\` hook accepts an \`options\` object.
4063
+
4064
+ ### \`opts.from\` option
4065
+
4066
+ - Type: \`string\`
4067
+ - Required
4068
+ - The RouteID to match the route context from.
4069
+
4070
+ ### \`opts.select\` option
4071
+
4072
+ - Type: \`(context: RouteContext) => TSelected\`
4073
+ - Optional
4074
+ - If supplied, this function will be called with the route context object and the return value will be returned from \`useRouteContext\`.
4075
+
4076
+ ## useRouteContext returns
4077
+
4078
+ - The current context for the current route or \`TSelected\` if a \`select\` function is provided.
4079
+
4080
+ ## Examples
4081
+
4082
+ \`\`\`tsx
4083
+ import { useRouteContext } from '@tanstack/react-router'
4084
+
4085
+ function Component() {
4086
+ const context = useRouteContext({ from: '/posts/$postId' })
4087
+ // ^ RouteContext
4088
+
4089
+ // OR
4090
+
4091
+ const selected = useRouteContext({
4092
+ from: '/posts/$postId',
4093
+ select: (context) => context.postId,
4094
+ })
4095
+ // ^ string
4096
+
4097
+ // ...
4098
+ }
4099
+ \`\`\`
4100
+
4101
+ # useRouter hook
4102
+
4103
+ The \`useRouter\` method is a hook that returns the current instance of [\`Router\`](../RouterType.md) from context. This hook is useful for accessing the router instance in a component.
4104
+
4105
+ ## useRouter returns
4106
+
4107
+ - The current [\`Router\`](../RouterType.md) instance.
4108
+
4109
+ > ⚠️⚠️⚠️ **\`router.state\` is always up to date, but NOT REACTIVE. If you use \`router.state\` in a component, the component will not re-render when the router state changes. To get a reactive version of the router state, use the [\`useRouterState\`](../useRouterStateHook.md) hook.**
4110
+
4111
+ ## Examples
4112
+
4113
+ \`\`\`tsx
4114
+ import { useRouter } from '@tanstack/react-router'
4115
+
4116
+ function Component() {
4117
+ const router = useRouter()
4118
+ // ^ Router
4119
+
4120
+ // ...
4121
+ }
4122
+ \`\`\`
4123
+
4124
+ # useRouterState hook
4125
+
4126
+ The \`useRouterState\` method is a hook that returns the current internal state of the router. This hook is useful for accessing the current state of the router in a component.
4127
+
4128
+ > [!TIP]
4129
+ > If you want to access the current location or the current matches, you should try out the [\`useLocation\`](../useLocationHook.md) and [\`useMatches\`](../useMatchesHook.md) hooks first. These hooks are designed to be more ergonomic and easier to use than accessing the router state directly.
4130
+
4131
+ ## useRouterState options
4132
+
4133
+ The \`useRouterState\` hook accepts an optional \`options\` object.
4134
+
4135
+ ### \`opts.select\` option
4136
+
4137
+ - Type: \`(state: RouterState) => TSelected\`
4138
+ - Optional
4139
+ - If supplied, this function will be called with the [\`RouterState\`](../RouterStateType.md) object and the return value will be returned from \`useRouterState\`.
4140
+
4141
+ ### \`opts.structuralSharing\` option
4142
+
4143
+ - Type: \`boolean\`
4144
+ - Optional
4145
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
4146
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
4147
+
4148
+ ## useRouterState returns
4149
+
4150
+ - The current [\`RouterState\`](../RouterStateType.md) object or \`TSelected\` if a \`select\` function is provided.
4151
+
4152
+ ## Examples
4153
+
4154
+ \`\`\`tsx
4155
+ import { useRouterState } from '@tanstack/react-router'
4156
+
4157
+ function Component() {
4158
+ const state = useRouterState()
4159
+ // ^ RouterState
4160
+
4161
+ // OR
4162
+
4163
+ const selected = useRouterState({
4164
+ select: (state) => state.location,
4165
+ })
4166
+ // ^ ParsedLocation
4167
+
4168
+ // ...
4169
+ }
4170
+ \`\`\`
4171
+
4172
+ # useSearch hook
4173
+
4174
+ The \`useSearch\` method is a hook that returns the current search query parameters as an object for the current location. This hook is useful for accessing the current search string and query parameters in a component.
4175
+
4176
+ ## useSearch options
4177
+
4178
+ The \`useSearch\` hook accepts an \`options\` object.
4179
+
4180
+ ### \`opts.from\` option
4181
+
4182
+ - Type: \`string\`
4183
+ - Required
4184
+ - The RouteID to match the search query parameters from.
4185
+
4186
+ ### \`opts.shouldThrow\` option
4187
+
4188
+ - Type: \`boolean\`
4189
+ - Optional
4190
+ - \`default: true\`
4191
+ - If \`false\`,\`useSearch\` will not throw an invariant exception in case a match was not found in the currently rendered matches; in this case, it will return \`undefined\`.
4192
+
4193
+ ### \`opts.select\` option
4194
+
4195
+ - Type: \`(search: SelectedSearchSchema) => TSelected\`
4196
+ - Optional
4197
+ - If supplied, this function will be called with the search object and the return value will be returned from \`useSearch\`.
4198
+
4199
+ ### \`opts.structuralSharing\` option
4200
+
4201
+ - Type: \`boolean\`
4202
+ - Optional
4203
+ - Configures whether structural sharing is enabled for the value returned by \`select\`.
4204
+ - See the [Render Optimizations guide](../../../guide/render-optimizations.md) for more information.
4205
+
4206
+ ### \`opts.strict\` option
4207
+
4208
+ - Type: \`boolean\`
4209
+ - Optional - \`default: true\`
4210
+ - If \`false\`, the \`opts.from\` option will be ignored and types will be loosened to \`Partial<FullSearchSchema>\` to reflect the shared types of all search query parameters.
4211
+
4212
+ ## useSearch returns
4213
+
4214
+ - If \`opts.from\` is provided, an object of the search query parameters for the current location or \`TSelected\` if a \`select\` function is provided.
4215
+ - If \`opts.strict\` is \`false\`, an object of the search query parameters for the current location or \`TSelected\` if a \`select\` function is provided.
4216
+
4217
+ ## Examples
4218
+
4219
+ \`\`\`tsx
4220
+ import { useSearch } from '@tanstack/react-router'
4221
+
4222
+ function Component() {
4223
+ const search = useSearch({ from: '/posts/$postId' })
4224
+ // ^ FullSearchSchema
4225
+
4226
+ // OR
4227
+
4228
+ const selected = useSearch({
4229
+ from: '/posts/$postId',
4230
+ select: (search) => search.postView,
4231
+ })
4232
+ // ^ string
4233
+
4234
+ // OR
4235
+
4236
+ const looseSearch = useSearch({ strict: false })
4237
+ // ^ Partial<FullSearchSchema>
4238
+
4239
+ // ...
4240
+ }
4241
+ \`\`\`
4242
+
4243
+ `;
4244
+ exports.default = content;