@depup/tanstack__react-router 1.166.4-depup.0

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