@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,78 @@
1
+ import * as React from 'react'
2
+ import { useLayoutEffect } from './utils'
3
+ import { useRouter } from './useRouter'
4
+ import type {
5
+ AnyRouter,
6
+ FromPathOption,
7
+ NavigateOptions,
8
+ RegisteredRouter,
9
+ UseNavigateResult,
10
+ } from '@tanstack/router-core'
11
+
12
+ /**
13
+ * Imperative navigation hook.
14
+ *
15
+ * Returns a stable `navigate(options)` function to change the current location
16
+ * programmatically. Prefer the `Link` component for user-initiated navigation,
17
+ * and use this hook from effects, callbacks, or handlers where imperative
18
+ * navigation is required.
19
+ *
20
+ * Options:
21
+ * - `from`: Optional route base used to resolve relative `to` paths.
22
+ *
23
+ * @returns A function that accepts `NavigateOptions`.
24
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook
25
+ */
26
+ export function useNavigate<
27
+ TRouter extends AnyRouter = RegisteredRouter,
28
+ TDefaultFrom extends string = string,
29
+ >(_defaultOpts?: {
30
+ from?: FromPathOption<TRouter, TDefaultFrom>
31
+ }): UseNavigateResult<TDefaultFrom> {
32
+ const router = useRouter()
33
+
34
+ return React.useCallback(
35
+ (options: NavigateOptions) => {
36
+ return router.navigate({
37
+ ...options,
38
+ from: options.from ?? _defaultOpts?.from,
39
+ })
40
+ },
41
+ [_defaultOpts?.from, router],
42
+ ) as UseNavigateResult<TDefaultFrom>
43
+ }
44
+
45
+ /**
46
+ * Component that triggers a navigation when rendered. Navigation executes
47
+ * in an effect after mount/update.
48
+ *
49
+ * Props are the same as `NavigateOptions` used by `navigate()`.
50
+ *
51
+ * @returns null
52
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/navigateComponent
53
+ */
54
+ export function Navigate<
55
+ TRouter extends AnyRouter = RegisteredRouter,
56
+ const TFrom extends string = string,
57
+ const TTo extends string | undefined = undefined,
58
+ const TMaskFrom extends string = TFrom,
59
+ const TMaskTo extends string = '',
60
+ >(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {
61
+ const router = useRouter()
62
+ const navigate = useNavigate()
63
+
64
+ const previousPropsRef = React.useRef<NavigateOptions<
65
+ TRouter,
66
+ TFrom,
67
+ TTo,
68
+ TMaskFrom,
69
+ TMaskTo
70
+ > | null>(null)
71
+ useLayoutEffect(() => {
72
+ if (previousPropsRef.current !== props) {
73
+ navigate(props)
74
+ previousPropsRef.current = props
75
+ }
76
+ }, [router, props, navigate])
77
+ return null
78
+ }
@@ -0,0 +1,107 @@
1
+ import { useMatch } from './useMatch'
2
+ import type {
3
+ StructuralSharingOption,
4
+ ValidateSelected,
5
+ } from './structuralSharing'
6
+ import type {
7
+ AnyRouter,
8
+ RegisteredRouter,
9
+ ResolveUseParams,
10
+ StrictOrFrom,
11
+ ThrowConstraint,
12
+ ThrowOrOptional,
13
+ UseParamsResult,
14
+ } from '@tanstack/router-core'
15
+
16
+ export interface UseParamsBaseOptions<
17
+ TRouter extends AnyRouter,
18
+ TFrom,
19
+ TStrict extends boolean,
20
+ TThrow extends boolean,
21
+ TSelected,
22
+ TStructuralSharing,
23
+ > {
24
+ select?: (
25
+ params: ResolveUseParams<TRouter, TFrom, TStrict>,
26
+ ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
27
+ shouldThrow?: TThrow
28
+ }
29
+
30
+ export type UseParamsOptions<
31
+ TRouter extends AnyRouter,
32
+ TFrom extends string | undefined,
33
+ TStrict extends boolean,
34
+ TThrow extends boolean,
35
+ TSelected,
36
+ TStructuralSharing,
37
+ > = StrictOrFrom<TRouter, TFrom, TStrict> &
38
+ UseParamsBaseOptions<
39
+ TRouter,
40
+ TFrom,
41
+ TStrict,
42
+ TThrow,
43
+ TSelected,
44
+ TStructuralSharing
45
+ > &
46
+ StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
47
+
48
+ export type UseParamsRoute<out TFrom> = <
49
+ TRouter extends AnyRouter = RegisteredRouter,
50
+ TSelected = unknown,
51
+ TStructuralSharing extends boolean = boolean,
52
+ >(
53
+ opts?: UseParamsBaseOptions<
54
+ TRouter,
55
+ TFrom,
56
+ /* TStrict */ true,
57
+ /* TThrow */ true,
58
+ TSelected,
59
+ TStructuralSharing
60
+ > &
61
+ StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
62
+ ) => UseParamsResult<TRouter, TFrom, true, TSelected>
63
+
64
+ /**
65
+ * Access the current route's path parameters with type-safety.
66
+ *
67
+ * Options:
68
+ * - `from`/`strict`: Specify the matched route and whether to enforce strict typing
69
+ * - `select`: Project the params object to a derived value for memoized renders
70
+ * - `structuralSharing`: Enable structural sharing for stable references
71
+ * - `shouldThrow`: Throw if the route is not found in strict contexts
72
+ *
73
+ * @returns The params object (or selected value) for the matched route.
74
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
75
+ */
76
+ export function useParams<
77
+ TRouter extends AnyRouter = RegisteredRouter,
78
+ const TFrom extends string | undefined = undefined,
79
+ TStrict extends boolean = true,
80
+ TThrow extends boolean = true,
81
+ TSelected = unknown,
82
+ TStructuralSharing extends boolean = boolean,
83
+ >(
84
+ opts: UseParamsOptions<
85
+ TRouter,
86
+ TFrom,
87
+ TStrict,
88
+ ThrowConstraint<TStrict, TThrow>,
89
+ TSelected,
90
+ TStructuralSharing
91
+ >,
92
+ ): ThrowOrOptional<
93
+ UseParamsResult<TRouter, TFrom, TStrict, TSelected>,
94
+ TThrow
95
+ > {
96
+ return useMatch({
97
+ from: opts.from!,
98
+ shouldThrow: opts.shouldThrow,
99
+ structuralSharing: opts.structuralSharing,
100
+ strict: opts.strict,
101
+ select: (match) => {
102
+ const params = opts.strict === false ? match.params : match._strictParams
103
+
104
+ return opts.select ? opts.select(params) : params
105
+ },
106
+ }) as any
107
+ }
@@ -0,0 +1,30 @@
1
+ import { useMatch } from './useMatch'
2
+ import type {
3
+ AnyRouter,
4
+ RegisteredRouter,
5
+ UseRouteContextBaseOptions,
6
+ UseRouteContextOptions,
7
+ UseRouteContextResult,
8
+ } from '@tanstack/router-core'
9
+
10
+ export type UseRouteContextRoute<out TFrom> = <
11
+ TRouter extends AnyRouter = RegisteredRouter,
12
+ TSelected = unknown,
13
+ >(
14
+ opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>,
15
+ ) => UseRouteContextResult<TRouter, TFrom, true, TSelected>
16
+
17
+ export function useRouteContext<
18
+ TRouter extends AnyRouter = RegisteredRouter,
19
+ const TFrom extends string | undefined = undefined,
20
+ TStrict extends boolean = true,
21
+ TSelected = unknown,
22
+ >(
23
+ opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>,
24
+ ): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected> {
25
+ return useMatch({
26
+ ...(opts as any),
27
+ select: (match) =>
28
+ opts.select ? opts.select(match.context) : match.context,
29
+ }) as UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>
30
+ }
@@ -0,0 +1,25 @@
1
+ import * as React from 'react'
2
+ import warning from 'tiny-warning'
3
+ import { routerContext } from './routerContext'
4
+ import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
5
+
6
+ /**
7
+ * Access the current TanStack Router instance from React context.
8
+ * Must be used within a `RouterProvider`.
9
+ *
10
+ * Options:
11
+ * - `warn`: Log a warning if no router context is found (default: true).
12
+ *
13
+ * @returns The registered router instance.
14
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
15
+ */
16
+ export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
17
+ warn?: boolean
18
+ }): TRouter {
19
+ const value = React.useContext(routerContext)
20
+ warning(
21
+ !((opts?.warn ?? true) && !value),
22
+ 'useRouter must be used inside a <RouterProvider> component!',
23
+ )
24
+ return value as any
25
+ }
@@ -0,0 +1,86 @@
1
+ import { useStore } from '@tanstack/react-store'
2
+ import { useRef } from 'react'
3
+ import { replaceEqualDeep } from '@tanstack/router-core'
4
+ import { isServer } from '@tanstack/router-core/isServer'
5
+ import { useRouter } from './useRouter'
6
+ import type {
7
+ AnyRouter,
8
+ RegisteredRouter,
9
+ RouterState,
10
+ } from '@tanstack/router-core'
11
+ import type {
12
+ StructuralSharingOption,
13
+ ValidateSelected,
14
+ } from './structuralSharing'
15
+
16
+ export type UseRouterStateOptions<
17
+ TRouter extends AnyRouter,
18
+ TSelected,
19
+ TStructuralSharing,
20
+ > = {
21
+ router?: TRouter
22
+ select?: (
23
+ state: RouterState<TRouter['routeTree']>,
24
+ ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
25
+ } & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
26
+
27
+ export type UseRouterStateResult<
28
+ TRouter extends AnyRouter,
29
+ TSelected,
30
+ > = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected
31
+
32
+ /**
33
+ * Subscribe to the router's state store with optional selection and
34
+ * structural sharing for render optimization.
35
+ *
36
+ * Options:
37
+ * - `select`: Project the full router state to a derived slice
38
+ * - `structuralSharing`: Replace-equal semantics for stable references
39
+ * - `router`: Read state from a specific router instance instead of context
40
+ *
41
+ * @returns The selected router state (or the full state by default).
42
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
43
+ */
44
+ export function useRouterState<
45
+ TRouter extends AnyRouter = RegisteredRouter,
46
+ TSelected = unknown,
47
+ TStructuralSharing extends boolean = boolean,
48
+ >(
49
+ opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,
50
+ ): UseRouterStateResult<TRouter, TSelected> {
51
+ const contextRouter = useRouter<TRouter>({
52
+ warn: opts?.router === undefined,
53
+ })
54
+ const router = opts?.router || contextRouter
55
+
56
+ // During SSR we render exactly once and do not need reactivity.
57
+ // Avoid subscribing to the store (and any structural sharing work) on the server.
58
+ const _isServer = isServer ?? router.isServer
59
+ if (_isServer) {
60
+ const state = router.state as RouterState<TRouter['routeTree']>
61
+ return (opts?.select ? opts.select(state) : state) as UseRouterStateResult<
62
+ TRouter,
63
+ TSelected
64
+ >
65
+ }
66
+
67
+ const previousResult =
68
+ // eslint-disable-next-line react-hooks/rules-of-hooks
69
+ useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)
70
+
71
+ // eslint-disable-next-line react-hooks/rules-of-hooks
72
+ return useStore(router.__store, (state) => {
73
+ if (opts?.select) {
74
+ if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
75
+ const newSlice = replaceEqualDeep(
76
+ previousResult.current,
77
+ opts.select(state),
78
+ )
79
+ previousResult.current = newSlice
80
+ return newSlice
81
+ }
82
+ return opts.select(state)
83
+ }
84
+ return state
85
+ }) as UseRouterStateResult<TRouter, TSelected>
86
+ }
@@ -0,0 +1,105 @@
1
+ import { useMatch } from './useMatch'
2
+ import type {
3
+ StructuralSharingOption,
4
+ ValidateSelected,
5
+ } from './structuralSharing'
6
+ import type {
7
+ AnyRouter,
8
+ RegisteredRouter,
9
+ ResolveUseSearch,
10
+ StrictOrFrom,
11
+ ThrowConstraint,
12
+ ThrowOrOptional,
13
+ UseSearchResult,
14
+ } from '@tanstack/router-core'
15
+
16
+ export interface UseSearchBaseOptions<
17
+ TRouter extends AnyRouter,
18
+ TFrom,
19
+ TStrict extends boolean,
20
+ TThrow extends boolean,
21
+ TSelected,
22
+ TStructuralSharing,
23
+ > {
24
+ select?: (
25
+ state: ResolveUseSearch<TRouter, TFrom, TStrict>,
26
+ ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
27
+ shouldThrow?: TThrow
28
+ }
29
+
30
+ export type UseSearchOptions<
31
+ TRouter extends AnyRouter,
32
+ TFrom,
33
+ TStrict extends boolean,
34
+ TThrow extends boolean,
35
+ TSelected,
36
+ TStructuralSharing,
37
+ > = StrictOrFrom<TRouter, TFrom, TStrict> &
38
+ UseSearchBaseOptions<
39
+ TRouter,
40
+ TFrom,
41
+ TStrict,
42
+ TThrow,
43
+ TSelected,
44
+ TStructuralSharing
45
+ > &
46
+ StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
47
+
48
+ export type UseSearchRoute<out TFrom> = <
49
+ TRouter extends AnyRouter = RegisteredRouter,
50
+ TSelected = unknown,
51
+ TStructuralSharing extends boolean = boolean,
52
+ >(
53
+ opts?: UseSearchBaseOptions<
54
+ TRouter,
55
+ TFrom,
56
+ /* TStrict */ true,
57
+ /* TThrow */ true,
58
+ TSelected,
59
+ TStructuralSharing
60
+ > &
61
+ StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
62
+ ) => UseSearchResult<TRouter, TFrom, true, TSelected>
63
+
64
+ /**
65
+ * Read and select the current route's search parameters with type-safety.
66
+ *
67
+ * Options:
68
+ * - `from`/`strict`: Control which route's search is read and how strictly it's typed
69
+ * - `select`: Map the search object to a derived value for render optimization
70
+ * - `structuralSharing`: Enable structural sharing for stable references
71
+ * - `shouldThrow`: Throw when the route is not found (strict contexts)
72
+ *
73
+ * @returns The search object (or selected value) for the matched route.
74
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
75
+ */
76
+ export function useSearch<
77
+ TRouter extends AnyRouter = RegisteredRouter,
78
+ const TFrom extends string | undefined = undefined,
79
+ TStrict extends boolean = true,
80
+ TThrow extends boolean = true,
81
+ TSelected = unknown,
82
+ TStructuralSharing extends boolean = boolean,
83
+ >(
84
+ opts: UseSearchOptions<
85
+ TRouter,
86
+ TFrom,
87
+ TStrict,
88
+ ThrowConstraint<TStrict, TThrow>,
89
+ TSelected,
90
+ TStructuralSharing
91
+ >,
92
+ ): ThrowOrOptional<
93
+ UseSearchResult<TRouter, TFrom, TStrict, TSelected>,
94
+ TThrow
95
+ > {
96
+ return useMatch({
97
+ from: opts.from!,
98
+ strict: opts.strict,
99
+ shouldThrow: opts.shouldThrow,
100
+ structuralSharing: opts.structuralSharing,
101
+ select: (match: any) => {
102
+ return opts.select ? opts.select(match.search) : match.search
103
+ },
104
+ }) as any
105
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,125 @@
1
+ import * as React from 'react'
2
+
3
+ // Safe version of React.use() that will not cause compilation errors against
4
+ // React 18 with Webpack, which statically analyzes imports and fails when it
5
+ // sees React.use referenced (since 'use' is not exported from React 18).
6
+ // This uses a dynamic string lookup to avoid the static analysis.
7
+ const REACT_USE = 'use'
8
+
9
+ /**
10
+ * React.use if available (React 19+), undefined otherwise.
11
+ * Use dynamic lookup to avoid Webpack compilation errors with React 18.
12
+ */
13
+ export const reactUse:
14
+ | (<T>(usable: Promise<T> | React.Context<T>) => T)
15
+ | undefined = (React as any)[REACT_USE]
16
+
17
+ export function useStableCallback<T extends (...args: Array<any>) => any>(
18
+ fn: T,
19
+ ): T {
20
+ const fnRef = React.useRef(fn)
21
+ fnRef.current = fn
22
+
23
+ const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))
24
+ return ref.current as T
25
+ }
26
+
27
+ export const useLayoutEffect =
28
+ typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
29
+
30
+ /**
31
+ * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
32
+ */
33
+ export function usePrevious<T>(value: T): T | null {
34
+ // initialise the ref with previous and current values
35
+ const ref = React.useRef<{ value: T; prev: T | null }>({
36
+ value: value,
37
+ prev: null,
38
+ })
39
+
40
+ const current = ref.current.value
41
+
42
+ // if the value passed into hook doesn't match what we store as "current"
43
+ // move the "current" to the "previous"
44
+ // and store the passed value as "current"
45
+ if (value !== current) {
46
+ ref.current = {
47
+ value: value,
48
+ prev: current,
49
+ }
50
+ }
51
+
52
+ // return the previous value only
53
+ return ref.current.prev
54
+ }
55
+
56
+ /**
57
+ * React hook to wrap `IntersectionObserver`.
58
+ *
59
+ * This hook will create an `IntersectionObserver` and observe the ref passed to it.
60
+ *
61
+ * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.
62
+ *
63
+ * @param ref - The ref to observe
64
+ * @param intersectionObserverOptions - The options to pass to the IntersectionObserver
65
+ * @param options - The options to pass to the hook
66
+ * @param callback - The callback to call when the intersection changes
67
+ * @returns The IntersectionObserver instance
68
+ * @example
69
+ * ```tsx
70
+ * const MyComponent = () => {
71
+ * const ref = React.useRef<HTMLDivElement>(null)
72
+ * useIntersectionObserver(
73
+ * ref,
74
+ * (entry) => { doSomething(entry) },
75
+ * { rootMargin: '10px' },
76
+ * { disabled: false }
77
+ * )
78
+ * return <div ref={ref} />
79
+ * ```
80
+ */
81
+ export function useIntersectionObserver<T extends Element>(
82
+ ref: React.RefObject<T | null>,
83
+ callback: (entry: IntersectionObserverEntry | undefined) => void,
84
+ intersectionObserverOptions: IntersectionObserverInit = {},
85
+ options: { disabled?: boolean } = {},
86
+ ) {
87
+ React.useEffect(() => {
88
+ if (
89
+ !ref.current ||
90
+ options.disabled ||
91
+ typeof IntersectionObserver !== 'function'
92
+ ) {
93
+ return
94
+ }
95
+
96
+ const observer = new IntersectionObserver(([entry]) => {
97
+ callback(entry)
98
+ }, intersectionObserverOptions)
99
+
100
+ observer.observe(ref.current)
101
+
102
+ return () => {
103
+ observer.disconnect()
104
+ }
105
+ }, [callback, intersectionObserverOptions, options.disabled, ref])
106
+ }
107
+
108
+ /**
109
+ * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.
110
+ *
111
+ * @param ref - The forwarded ref
112
+ * @returns The inner ref returned by `useRef`
113
+ * @example
114
+ * ```tsx
115
+ * const MyComponent = React.forwardRef((props, ref) => {
116
+ * const innerRef = useForwardedRef(ref)
117
+ * return <div ref={innerRef} />
118
+ * })
119
+ * ```
120
+ */
121
+ export function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {
122
+ const innerRef = React.useRef<T>(null)
123
+ React.useImperativeHandle(ref, () => innerRef.current!, [])
124
+ return innerRef
125
+ }