@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,313 @@
1
+ import warning from 'tiny-warning'
2
+ import { createRoute } from './route'
3
+
4
+ import { useMatch } from './useMatch'
5
+ import { useLoaderDeps } from './useLoaderDeps'
6
+ import { useLoaderData } from './useLoaderData'
7
+ import { useSearch } from './useSearch'
8
+ import { useParams } from './useParams'
9
+ import { useNavigate } from './useNavigate'
10
+ import { useRouter } from './useRouter'
11
+ import { useRouteContext } from './useRouteContext'
12
+ import type { UseParamsRoute } from './useParams'
13
+ import type { UseMatchRoute } from './useMatch'
14
+ import type { UseSearchRoute } from './useSearch'
15
+ import type {
16
+ AnyContext,
17
+ AnyRoute,
18
+ AnyRouter,
19
+ Constrain,
20
+ ConstrainLiteral,
21
+ FileBaseRouteOptions,
22
+ FileRoutesByPath,
23
+ LazyRouteOptions,
24
+ Register,
25
+ RegisteredRouter,
26
+ ResolveParams,
27
+ Route,
28
+ RouteById,
29
+ RouteConstraints,
30
+ RouteIds,
31
+ RouteLoaderFn,
32
+ UpdatableRouteOptions,
33
+ UseNavigateResult,
34
+ } from '@tanstack/router-core'
35
+ import type { UseLoaderDepsRoute } from './useLoaderDeps'
36
+ import type { UseLoaderDataRoute } from './useLoaderData'
37
+ import type { UseRouteContextRoute } from './useRouteContext'
38
+
39
+ /**
40
+ * Creates a file-based Route factory for a given path.
41
+ *
42
+ * Used by TanStack Router's file-based routing to associate a file with a
43
+ * route. The returned function accepts standard route options. In normal usage
44
+ * the `path` string is inserted and maintained by the `tsr` generator.
45
+ *
46
+ * @param path File path literal for the route (usually auto-generated).
47
+ * @returns A function that accepts Route options and returns a Route instance.
48
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction
49
+ */
50
+ export function createFileRoute<
51
+ TFilePath extends keyof FileRoutesByPath,
52
+ TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
53
+ TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],
54
+ TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],
55
+ TFullPath extends RouteConstraints['TFullPath'] =
56
+ FileRoutesByPath[TFilePath]['fullPath'],
57
+ >(
58
+ path?: TFilePath,
59
+ ): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {
60
+ if (typeof path === 'object') {
61
+ return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
62
+ silent: true,
63
+ }).createRoute(path) as any
64
+ }
65
+ return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
66
+ silent: true,
67
+ }).createRoute
68
+ }
69
+
70
+ /**
71
+ @deprecated It's no longer recommended to use the `FileRoute` class directly.
72
+ Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
73
+ */
74
+ export class FileRoute<
75
+ TFilePath extends keyof FileRoutesByPath,
76
+ TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
77
+ TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],
78
+ TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],
79
+ TFullPath extends RouteConstraints['TFullPath'] =
80
+ FileRoutesByPath[TFilePath]['fullPath'],
81
+ > {
82
+ silent?: boolean
83
+
84
+ constructor(
85
+ public path?: TFilePath,
86
+ _opts?: { silent: boolean },
87
+ ) {
88
+ this.silent = _opts?.silent
89
+ }
90
+
91
+ createRoute = <
92
+ TRegister = Register,
93
+ TSearchValidator = undefined,
94
+ TParams = ResolveParams<TPath>,
95
+ TRouteContextFn = AnyContext,
96
+ TBeforeLoadFn = AnyContext,
97
+ TLoaderDeps extends Record<string, any> = {},
98
+ TLoaderFn = undefined,
99
+ TChildren = unknown,
100
+ TSSR = unknown,
101
+ const TMiddlewares = unknown,
102
+ THandlers = undefined,
103
+ >(
104
+ options?: FileBaseRouteOptions<
105
+ TRegister,
106
+ TParentRoute,
107
+ TId,
108
+ TPath,
109
+ TSearchValidator,
110
+ TParams,
111
+ TLoaderDeps,
112
+ TLoaderFn,
113
+ AnyContext,
114
+ TRouteContextFn,
115
+ TBeforeLoadFn,
116
+ AnyContext,
117
+ TSSR,
118
+ TMiddlewares,
119
+ THandlers
120
+ > &
121
+ UpdatableRouteOptions<
122
+ TParentRoute,
123
+ TId,
124
+ TFullPath,
125
+ TParams,
126
+ TSearchValidator,
127
+ TLoaderFn,
128
+ TLoaderDeps,
129
+ AnyContext,
130
+ TRouteContextFn,
131
+ TBeforeLoadFn
132
+ >,
133
+ ): Route<
134
+ TRegister,
135
+ TParentRoute,
136
+ TPath,
137
+ TFullPath,
138
+ TFilePath,
139
+ TId,
140
+ TSearchValidator,
141
+ TParams,
142
+ AnyContext,
143
+ TRouteContextFn,
144
+ TBeforeLoadFn,
145
+ TLoaderDeps,
146
+ TLoaderFn,
147
+ TChildren,
148
+ unknown,
149
+ TSSR,
150
+ TMiddlewares,
151
+ THandlers
152
+ > => {
153
+ if (process.env.NODE_ENV !== 'production') {
154
+ warning(
155
+ this.silent,
156
+ 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
157
+ )
158
+ }
159
+ const route = createRoute(options as any)
160
+ ;(route as any).isRoot = false
161
+ return route as any
162
+ }
163
+ }
164
+
165
+ /**
166
+ @deprecated It's recommended not to split loaders into separate files.
167
+ Instead, place the loader function in the main route file via `createFileRoute`.
168
+ */
169
+ export function FileRouteLoader<
170
+ TFilePath extends keyof FileRoutesByPath,
171
+ TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
172
+ >(
173
+ _path: TFilePath,
174
+ ): <TLoaderFn>(
175
+ loaderFn: Constrain<
176
+ TLoaderFn,
177
+ RouteLoaderFn<
178
+ Register,
179
+ TRoute['parentRoute'],
180
+ TRoute['types']['id'],
181
+ TRoute['types']['params'],
182
+ TRoute['types']['loaderDeps'],
183
+ TRoute['types']['routerContext'],
184
+ TRoute['types']['routeContextFn'],
185
+ TRoute['types']['beforeLoadFn']
186
+ >
187
+ >,
188
+ ) => TLoaderFn {
189
+ if (process.env.NODE_ENV !== 'production') {
190
+ warning(
191
+ false,
192
+ `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
193
+ )
194
+ }
195
+ return (loaderFn) => loaderFn as any
196
+ }
197
+
198
+ declare module '@tanstack/router-core' {
199
+ export interface LazyRoute<in out TRoute extends AnyRoute> {
200
+ useMatch: UseMatchRoute<TRoute['id']>
201
+ useRouteContext: UseRouteContextRoute<TRoute['id']>
202
+ useSearch: UseSearchRoute<TRoute['id']>
203
+ useParams: UseParamsRoute<TRoute['id']>
204
+ useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>
205
+ useLoaderData: UseLoaderDataRoute<TRoute['id']>
206
+ useNavigate: () => UseNavigateResult<TRoute['fullPath']>
207
+ }
208
+ }
209
+
210
+ export class LazyRoute<TRoute extends AnyRoute> {
211
+ options: {
212
+ id: string
213
+ } & LazyRouteOptions
214
+
215
+ constructor(
216
+ opts: {
217
+ id: string
218
+ } & LazyRouteOptions,
219
+ ) {
220
+ this.options = opts
221
+ ;(this as any).$$typeof = Symbol.for('react.memo')
222
+ }
223
+
224
+ useMatch: UseMatchRoute<TRoute['id']> = (opts) => {
225
+ return useMatch({
226
+ select: opts?.select,
227
+ from: this.options.id,
228
+ structuralSharing: opts?.structuralSharing,
229
+ } as any) as any
230
+ }
231
+
232
+ useRouteContext: UseRouteContextRoute<TRoute['id']> = (opts) => {
233
+ return useRouteContext({ ...(opts as any), from: this.options.id })
234
+ }
235
+
236
+ useSearch: UseSearchRoute<TRoute['id']> = (opts) => {
237
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
238
+ return useSearch({
239
+ select: opts?.select,
240
+ structuralSharing: opts?.structuralSharing,
241
+ from: this.options.id,
242
+ } as any) as any
243
+ }
244
+
245
+ useParams: UseParamsRoute<TRoute['id']> = (opts) => {
246
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
247
+ return useParams({
248
+ select: opts?.select,
249
+ structuralSharing: opts?.structuralSharing,
250
+ from: this.options.id,
251
+ } as any) as any
252
+ }
253
+
254
+ useLoaderDeps: UseLoaderDepsRoute<TRoute['id']> = (opts) => {
255
+ return useLoaderDeps({ ...opts, from: this.options.id } as any)
256
+ }
257
+
258
+ useLoaderData: UseLoaderDataRoute<TRoute['id']> = (opts) => {
259
+ return useLoaderData({ ...opts, from: this.options.id } as any)
260
+ }
261
+
262
+ useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {
263
+ const router = useRouter()
264
+ return useNavigate({ from: router.routesById[this.options.id].fullPath })
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Creates a lazily-configurable code-based route stub by ID.
270
+ *
271
+ * Use this for code-splitting with code-based routes. The returned function
272
+ * accepts only non-critical route options like `component`, `pendingComponent`,
273
+ * `errorComponent`, and `notFoundComponent` which are applied when the route
274
+ * is matched.
275
+ *
276
+ * @param id Route ID string literal to associate with the lazy route.
277
+ * @returns A function that accepts lazy route options and returns a `LazyRoute`.
278
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction
279
+ */
280
+ export function createLazyRoute<
281
+ TRouter extends AnyRouter = RegisteredRouter,
282
+ TId extends string = string,
283
+ TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>,
284
+ >(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {
285
+ return (opts: LazyRouteOptions) => {
286
+ return new LazyRoute<TRoute>({
287
+ id: id,
288
+ ...opts,
289
+ })
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Creates a lazily-configurable file-based route stub by file path.
295
+ *
296
+ * Use this for code-splitting with file-based routes (eg. `.lazy.tsx` files).
297
+ * The returned function accepts only non-critical route options like
298
+ * `component`, `pendingComponent`, `errorComponent`, and `notFoundComponent`.
299
+ *
300
+ * @param id File path literal for the route file.
301
+ * @returns A function that accepts lazy route options and returns a `LazyRoute`.
302
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction
303
+ */
304
+ export function createLazyFileRoute<
305
+ TFilePath extends keyof FileRoutesByPath,
306
+ TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
307
+ >(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute> {
308
+ if (typeof id === 'object') {
309
+ return new LazyRoute<TRoute>(id) as any
310
+ }
311
+
312
+ return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })
313
+ }
@@ -0,0 +1,217 @@
1
+ import * as React from 'react'
2
+ import { escapeHtml } from '@tanstack/router-core'
3
+ import { useRouter } from './useRouter'
4
+ import { useRouterState } from './useRouterState'
5
+ import type { RouterManagedTag } from '@tanstack/router-core'
6
+
7
+ /**
8
+ * Build the list of head/link/meta/script tags to render for active matches.
9
+ * Used internally by `HeadContent`.
10
+ */
11
+ export const useTags = () => {
12
+ const router = useRouter()
13
+ const nonce = router.options.ssr?.nonce
14
+ const routeMeta = useRouterState({
15
+ select: (state) => {
16
+ return state.matches.map((match) => match.meta!).filter(Boolean)
17
+ },
18
+ })
19
+
20
+ const meta: Array<RouterManagedTag> = React.useMemo(() => {
21
+ const resultMeta: Array<RouterManagedTag> = []
22
+ const metaByAttribute: Record<string, true> = {}
23
+ let title: RouterManagedTag | undefined
24
+ for (let i = routeMeta.length - 1; i >= 0; i--) {
25
+ const metas = routeMeta[i]!
26
+ for (let j = metas.length - 1; j >= 0; j--) {
27
+ const m = metas[j]
28
+ if (!m) continue
29
+
30
+ if (m.title) {
31
+ if (!title) {
32
+ title = {
33
+ tag: 'title',
34
+ children: m.title,
35
+ }
36
+ }
37
+ } else if ('script:ld+json' in m) {
38
+ // Handle JSON-LD structured data
39
+ // Content is HTML-escaped to prevent XSS when injected via dangerouslySetInnerHTML
40
+ try {
41
+ const json = JSON.stringify(m['script:ld+json'])
42
+ resultMeta.push({
43
+ tag: 'script',
44
+ attrs: {
45
+ type: 'application/ld+json',
46
+ },
47
+ children: escapeHtml(json),
48
+ })
49
+ } catch {
50
+ // Skip invalid JSON-LD objects
51
+ }
52
+ } else {
53
+ const attribute = m.name ?? m.property
54
+ if (attribute) {
55
+ if (metaByAttribute[attribute]) {
56
+ continue
57
+ } else {
58
+ metaByAttribute[attribute] = true
59
+ }
60
+ }
61
+
62
+ resultMeta.push({
63
+ tag: 'meta',
64
+ attrs: {
65
+ ...m,
66
+ nonce,
67
+ },
68
+ })
69
+ }
70
+ }
71
+ }
72
+
73
+ if (title) {
74
+ resultMeta.push(title)
75
+ }
76
+
77
+ if (nonce) {
78
+ resultMeta.push({
79
+ tag: 'meta',
80
+ attrs: {
81
+ property: 'csp-nonce',
82
+ content: nonce,
83
+ },
84
+ })
85
+ }
86
+ resultMeta.reverse()
87
+
88
+ return resultMeta
89
+ }, [routeMeta, nonce])
90
+
91
+ const links = useRouterState({
92
+ select: (state) => {
93
+ const constructed = state.matches
94
+ .map((match) => match.links!)
95
+ .filter(Boolean)
96
+ .flat(1)
97
+ .map((link) => ({
98
+ tag: 'link',
99
+ attrs: {
100
+ ...link,
101
+ nonce,
102
+ },
103
+ })) satisfies Array<RouterManagedTag>
104
+
105
+ const manifest = router.ssr?.manifest
106
+
107
+ // These are the assets extracted from the ViteManifest
108
+ // using the `startManifestPlugin`
109
+ const assets = state.matches
110
+ .map((match) => manifest?.routes[match.routeId]?.assets ?? [])
111
+ .filter(Boolean)
112
+ .flat(1)
113
+ .filter((asset) => asset.tag === 'link')
114
+ .map(
115
+ (asset) =>
116
+ ({
117
+ tag: 'link',
118
+ attrs: {
119
+ ...asset.attrs,
120
+ suppressHydrationWarning: true,
121
+ nonce,
122
+ },
123
+ }) satisfies RouterManagedTag,
124
+ )
125
+
126
+ return [...constructed, ...assets]
127
+ },
128
+ structuralSharing: true as any,
129
+ })
130
+
131
+ const preloadLinks = useRouterState({
132
+ select: (state) => {
133
+ const preloadLinks: Array<RouterManagedTag> = []
134
+
135
+ state.matches
136
+ .map((match) => router.looseRoutesById[match.routeId]!)
137
+ .forEach((route) =>
138
+ router.ssr?.manifest?.routes[route.id]?.preloads
139
+ ?.filter(Boolean)
140
+ .forEach((preload) => {
141
+ preloadLinks.push({
142
+ tag: 'link',
143
+ attrs: {
144
+ rel: 'modulepreload',
145
+ href: preload,
146
+ nonce,
147
+ },
148
+ })
149
+ }),
150
+ )
151
+
152
+ return preloadLinks
153
+ },
154
+ structuralSharing: true as any,
155
+ })
156
+
157
+ const styles = useRouterState({
158
+ select: (state) =>
159
+ (
160
+ state.matches
161
+ .map((match) => match.styles!)
162
+ .flat(1)
163
+ .filter(Boolean) as Array<RouterManagedTag>
164
+ ).map(({ children, ...attrs }) => ({
165
+ tag: 'style',
166
+ attrs: {
167
+ ...attrs,
168
+ nonce,
169
+ },
170
+ children,
171
+ })),
172
+ structuralSharing: true as any,
173
+ })
174
+
175
+ const headScripts: Array<RouterManagedTag> = useRouterState({
176
+ select: (state) =>
177
+ (
178
+ state.matches
179
+ .map((match) => match.headScripts!)
180
+ .flat(1)
181
+ .filter(Boolean) as Array<RouterManagedTag>
182
+ ).map(({ children, ...script }) => ({
183
+ tag: 'script',
184
+ attrs: {
185
+ ...script,
186
+ nonce,
187
+ },
188
+ children,
189
+ })),
190
+ structuralSharing: true as any,
191
+ })
192
+
193
+ return uniqBy(
194
+ [
195
+ ...meta,
196
+ ...preloadLinks,
197
+ ...links,
198
+ ...styles,
199
+ ...headScripts,
200
+ ] as Array<RouterManagedTag>,
201
+ (d) => {
202
+ return JSON.stringify(d)
203
+ },
204
+ )
205
+ }
206
+
207
+ export function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {
208
+ const seen = new Set<string>()
209
+ return arr.filter((item) => {
210
+ const key = fn(item)
211
+ if (seen.has(key)) {
212
+ return false
213
+ }
214
+ seen.add(key)
215
+ return true
216
+ })
217
+ }
package/src/history.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { HistoryLocation } from '@tanstack/history'
2
+
3
+ declare module '@tanstack/history' {
4
+ interface HistoryState {
5
+ __tempLocation?: HistoryLocation
6
+ __tempKey?: string
7
+ __hashScrollIntoViewOptions?: boolean | ScrollIntoViewOptions
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ // Development entry point - re-exports everything from index.tsx
2
+ // but overrides HeadContent with the dev version that handles
3
+ // dev styles cleanup after hydration
4
+
5
+ export * from './index'
6
+ export { HeadContent } from './HeadContent.dev'