@tanstack/react-router 1.121.0-alpha.22 → 1.121.0-alpha.28

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