@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,920 @@
1
+ export default `# Overview
2
+
3
+ **TanStack Router is a router for building React and Solid applications**. Some of its features include:
4
+
5
+ - 100% inferred TypeScript support
6
+ - Typesafe navigation
7
+ - Nested Routing and layout routes (with pathless layouts)
8
+ - Built-in Route Loaders w/ SWR Caching
9
+ - Designed for client-side data caches (TanStack Query, SWR, etc.)
10
+ - Automatic route prefetching
11
+ - Asynchronous route elements and error boundaries
12
+ - File-based Route Generation
13
+ - Typesafe JSON-first Search Params state management APIs
14
+ - Path and Search Parameter Schema Validation
15
+ - Search Param Navigation APIs
16
+ - Custom Search Param parser/serializer support
17
+ - Search param middleware
18
+ - Route matching/loading middleware
19
+
20
+ To get started quickly, head to the next page. For a more lengthy explanation, buckle up while I bring you up to speed!
21
+
22
+ ## "A Fork in the Route"
23
+
24
+ Using a router to build applications is widely regarded as a must-have and is usually one of the first choices you’ll make in your tech stack.
25
+
26
+ ## Why TanStack Router?
27
+
28
+ TanStack Router delivers on the same fundamental expectations as other routers that you’ve come to expect:
29
+
30
+ - Nested routes, layout routes, grouped routes
31
+ - File-based Routing
32
+ - Parallel data loading
33
+ - Prefetching
34
+ - URL Path Params
35
+ - Error Boundaries and Handling
36
+ - SSR
37
+ - Route Masking
38
+
39
+ And it also delivers some new features that raise the bar:
40
+
41
+ - 100% inferred TypeScript support
42
+ - Typesafe navigation
43
+ - Built-in SWR Caching for loaders
44
+ - Designed for client-side data caches (TanStack Query, SWR, etc.)
45
+ - Typesafe JSON-first Search Params state management APIs
46
+ - Path and Search Parameter Schema Validation
47
+ - Search Parameter Navigation APIs
48
+ - Custom Search Param parser/serializer support
49
+ - Search param middleware
50
+ - Inherited Route Context
51
+ - Mixed file-based and code-based routing
52
+
53
+ Let’s dive into some of the more important ones in more detail!
54
+
55
+ ## 100% Inferred TypeScript Support
56
+
57
+ Everything these days is written “in Typescript” or at the very least offers type definitions that are veneered over runtime functionality, but too few packages in the ecosystem actually design their APIs with TypeScript in mind. So while I’m pleased that your router is auto-completing your option fields and catching a few property/method typos here and there, there is much more to be had.
58
+
59
+ - TanStack Router is fully aware of all of your routes and their configuration at any given point in your code. This includes the path, path params, search params, context, and any other configuration you’ve provided. Ultimately this means that you can navigate to any route in your app with 100% type safety and confidence that your link or navigate call will succeed.
60
+ - TanStack Router provides lossless type-inference. It uses countless generic type parameters to enforce and propagate any type information you give it throughout the rest of its API and ultimately your app. No other router offers this level of type safety and developer confidence.
61
+
62
+ What does all of that mean for you?
63
+
64
+ - Faster feature development with auto-completion and type hints
65
+ - Safer and faster refactors
66
+ - Confidence that your code will work as expected
67
+
68
+ ## 1st Class Search Parameters
69
+
70
+ Search parameters are often an afterthought, treated like a black box of strings (or string) that you can parse and update, but not much else. Existing solutions are **not** type-safe either, adding to the caution that is required to deal with them. Even the most "modern" frameworks and routers leave it up to you to figure out how to manage this state. Sometimes they'll parse the search string into an object for you, or sometimes you're left to do it yourself with \`URLSearchParams\`.
71
+
72
+ Let's step back and remember that **search params are the most powerful state manager in your entire application.** They are global, serializable, bookmarkable, and shareable making them the perfect place to store any kind of state that needs to survive a page refresh or a social share.
73
+
74
+ To live up to that responsibility, search parameters are a first-class citizen in TanStack Router. While still based on standard URLSearchParams, TanStack Router uses a powerful parser/serializer to manage deeper and more complex data structures in your search params, all while keeping them type-safe and easy to work with.
75
+
76
+ **It's like having \`useState\` right in the URL!**
77
+
78
+ Search parameters are:
79
+
80
+ - Automatically parsed and serialized as JSON
81
+ - Validated and typed
82
+ - Inherited from parent routes
83
+ - Accessible in loaders, components, and hooks
84
+ - Easily modified with the useSearch hook, Link, navigate, and router.navigate APIs
85
+ - Customizable with a custom search filters and middleware
86
+ - Subscribed via fine-grained search param selectors for efficient re-renders
87
+
88
+ Once you start using TanStack Router's search parameters, you'll wonder how you ever lived without them.
89
+
90
+ ## Built-In Caching and Friendly Data Loading
91
+
92
+ Data loading is a critical part of any application and while most existing routers offer some form of critical data loading APIs, they often fall short when it comes to caching and data lifecycle management. Existing solutions suffer from a few common problems:
93
+
94
+ - No caching at all. Data is always fresh, but your users are left waiting for frequently accessed data to load over and over again.
95
+ - Overly-aggressive caching. Data is cached for too long, leading to stale data and a poor user experience.
96
+ - Blunt invalidation strategies and APIs. Data may be invalidated too often, leading to unnecessary network requests and wasted resources, or you may not have any fine-grained control over when data is invalidated at all.
97
+
98
+ TanStack Router solves these problems with a two-prong approach to caching and data loading:
99
+
100
+ ### Built-in Cache
101
+
102
+ TanStack Router provides a light-weight built-in caching layer that works seamlessly with the Router. This caching layer is loosely based on TanStack Query, but with fewer features and a much smaller API surface area. Like TanStack Query, sane but powerful defaults guarantee that your data is cached for reuse, invalidated when necessary, and garbage collected when not in use. It also provides a simple API for invalidating the cache manually when needed.
103
+
104
+ ### Flexible & Powerful Data Lifecycle APIs
105
+
106
+ TanStack Router is designed with a flexible and powerful data loading API that more easily integrates with existing data fetching libraries like TanStack Query, SWR, Apollo, Relay, or even your own custom data fetching solution. Configurable APIs like \`context\`, \`beforeLoad\`, \`loaderDeps\` and \`loader\` work in unison to make it easy to define declarative data dependencies, prefetch data, and manage the lifecycle of an external data source with ease.
107
+
108
+ ## Inherited Route Context
109
+
110
+ TanStack Router's router and route context is a powerful feature that allows you to define context that is specific to a route which is then inherited by all child routes. Even the router and root routes themselves can provide context. Context can be built up both synchronously and asynchronously, and can be used to share data, configuration, or even functions between routes and route configurations. This is especially useful for scenarios like:
111
+
112
+ - Authentication and Authorization
113
+ - Hybrid SSR/CSR data fetching and preloading
114
+ - Theming
115
+ - Singletons and global utilities
116
+ - Curried or partial application across preloading, loading, and rendering stages
117
+
118
+ Also, what would route context be if it weren't type-safe? TanStack Router's route context is fully type-safe and inferred at zero cost to you.
119
+
120
+ ## File-based and/or Code-Based Routing
121
+
122
+ TanStack Router supports both file-based and code-based routing at the same time. This flexibility allows you to choose the approach that best fits your project's needs.
123
+
124
+ TanStack Router's file-based routing approach is uniquely user-facing. Route configuration is generated for you either by the Vite plugin or TanStack Router CLI, leaving the usage of said generated code up to you! This means that you're always in total control of your routes and router, even if you use file-based routing.
125
+
126
+ ## Acknowledgements
127
+
128
+ TanStack Router builds on concepts and patterns popularized by many other OSS projects, including:
129
+
130
+ - [TRPC](https://trpc.io/)
131
+ - [Remix](https://remix.run)
132
+ - [Chicane](https://swan-io.github.io/chicane/)
133
+ - [Next.js](https://nextjs.org)
134
+
135
+ We acknowledge the investment, risk and research that went into their development, but are excited to push the bar they have set even higher.
136
+
137
+ ## Let's go!
138
+
139
+ Enough overview, there's so much more to do with TanStack Router. Hit that next button and let's get started!
140
+
141
+ # Quick Start
142
+
143
+ ## Impatient?
144
+
145
+ The fastest way to get started with TanStack Router is to scaffold a new project. Just run:
146
+
147
+ <!-- ::start:tabs variant="package-managers" mode="local-install" -->
148
+
149
+ react: create-tsrouter-app@latest
150
+ solid: create-tsrouter-app@latest --framework solid
151
+
152
+ <!-- ::end:tabs -->
153
+
154
+ The CLI will guide you through a short series of prompts to customize your setup, including options for:
155
+
156
+ - File-based or code-based route configuration
157
+ - TypeScript support
158
+ - Tailwind CSS integration
159
+ - Toolchain setup
160
+ - Git initialization
161
+
162
+ Once complete, a new project will be generated with TanStack Router installed and ready to use.
163
+
164
+ > [!TIP]
165
+ > For full details on available options and templates, visit the [\`create-tsrouter-app\` documentation](https://github.com/TanStack/create-tsrouter-app/tree/main/cli/create-tsrouter-app).
166
+
167
+ ## Routing Options
168
+
169
+ TanStack Router supports both file-based and code-based route configurations. You can specify your preference during the CLI setup, or use these commands directly:
170
+
171
+ ### File-Based Route Generation
172
+
173
+ The file-based approach is the recommended option for most projects. It automatically creates routes based on your file structure, giving you the best mix of performance, simplicity, and developer experience.
174
+
175
+ <!-- ::start:tabs variant="package-manager" mode="local-install" -->
176
+
177
+ react: create-tsrouter-app@latest my-app --template file-router
178
+ solid: create-tsrouter-app@latest my-app --framework solid --template file-router
179
+
180
+ <!-- ::end:tabs -->
181
+
182
+ ### Code-Based Route Configuration
183
+
184
+ If you prefer to define routes programmatically, you can use the code-based route configuration. This approach gives you full control over routing logic.
185
+
186
+ <!-- ::start:tabs variant="package-manager" mode="local-install" -->
187
+
188
+ react: create-tsrouter-app@latest my-app
189
+ solid: create-tsrouter-app@latest my-app --framework solid
190
+
191
+ <!-- ::end:tabs -->
192
+
193
+ With either approach, navigate to your project directory and start the development server.
194
+
195
+ ## Existing Project
196
+
197
+ If you have an existing React project and want to add TanStack Router to it, you can install it manually.
198
+
199
+ ### Requirements
200
+
201
+ Before installing TanStack Router, please ensure your project meets the following requirements:
202
+
203
+ <!-- ::start:framework -->
204
+
205
+ # React
206
+
207
+ - \`react\` v18 or later with \`createRoot\` support.
208
+ - \`react-dom\` v18 or later.
209
+
210
+ # Solid
211
+
212
+ - \`solid-js\` v1.x.x
213
+
214
+ <!-- ::end:framework -->
215
+
216
+ > [!NOTE]
217
+ > Using TypeScript (\`v5.3.x or higher\`) is recommended for the best development experience, though not strictly required. We aim to support the last 5 minor versions of TypeScript, but using the latest version will help avoid potential issues.
218
+
219
+ TanStack Router is currently only compatible with React (with ReactDOM) and Solid. If you're interested in contributing to support other frameworks, such as React Native, Angular, or Vue, please reach out to us on [Discord](https://tlinz.com/discord).
220
+
221
+ ### Installation
222
+
223
+ To install TanStack Router in your project, run the following command using your preferred package manager:
224
+
225
+ <!-- ::start:tabs variant="package-managers" -->
226
+
227
+ react: @tanstack/react-router
228
+ solid: @tanstack/solid-router
229
+
230
+ <!-- ::end:tabs -->
231
+
232
+ Once installed, you can verify the installation by checking your \`package.json\` file for the dependency.
233
+
234
+ <!-- ::start:framework -->
235
+
236
+ # React
237
+
238
+ \`\`\`json
239
+ {
240
+ "dependencies": {
241
+ "@tanstack/react-router": "^x.x.x"
242
+ }
243
+ }
244
+ \`\`\`
245
+
246
+ # Solid
247
+
248
+ \`\`\`json
249
+ {
250
+ "dependencies": {
251
+ "@tanstack/solid-router": "^x.x.x"
252
+ }
253
+ }
254
+ \`\`\`
255
+
256
+ <!-- ::end:framework -->
257
+
258
+ # Decisions on Developer Experience
259
+
260
+ When people first start using TanStack Router, they often have a lot of questions that revolve around the following themes:
261
+
262
+ > Why do I have to do things this way?
263
+
264
+ > Why is it done this way? and not that way?
265
+
266
+ > I'm used to doing it this way, why should I change?
267
+
268
+ And they are all valid questions. For the most part, people are used to using routing libraries that are very similar to each other. They all have a similar API, similar concepts, and similar ways of doing things.
269
+
270
+ But TanStack Router is different. It's not your average routing library. It's not your average state management library. It's not your average anything.
271
+
272
+ > [!TIP]
273
+ > The examples in this guide use React for components and code snippets, but the same principles apply to Solid. The only difference is in the syntax and API of the framework, but the underlying concepts and design decisions are the same.
274
+
275
+ ## TanStack Router's origin story
276
+
277
+ It's important to remember that TanStack Router's origins stem from [Nozzle.io](https://nozzle.io?utm_source=tanstack)'s need for a client-side routing solution that offered a first-in-class _URL Search Parameters_ experience without compromising on the **_type-safety_** that was required to power its complex dashboards.
278
+
279
+ And so, from TanStack Router's very inception, every facet of its design was meticulously thought out to ensure that its type-safety and developer experience were second to none.
280
+
281
+ ## How does TanStack Router achieve this?
282
+
283
+ > TypeScript! TypeScript! TypeScript!
284
+
285
+ Every aspect of TanStack Router is designed to be as type-safe as possible, and this is achieved by leveraging TypeScript's type system to its fullest extent. This involves using some very advanced and complex types, type inference, and other features to ensure that the developer experience is as smooth as possible.
286
+
287
+ But to achieve this, we had to make some decisions that deviate from the norms in the routing world.
288
+
289
+ 1. [**Route configuration boilerplate?**](#why-is-the-routers-configuration-done-this-way): You have to define your routes in a way that allows TypeScript to infer the types of your routes as much as possible.
290
+ 2. [**TypeScript module declaration for the router?**](#declaring-the-router-instance-for-type-inference): You have to pass the \`Router\` instance to the rest of your application using TypeScript's module declaration.
291
+ 3. [**Why push for file-based routing over code-based?**](#why-is-file-based-routing-the-preferred-way-to-define-routes): We push for file-based routing as the preferred way to define your routes.
292
+
293
+ > TLDR; All the design decisions in the developer experience of using TanStack Router are made so that you can have a best-in-class type-safety experience without compromising on the control, flexibility, and maintainability of your route configurations.
294
+
295
+ ## Why is the Router's configuration done this way?
296
+
297
+ When you want to leverage the TypeScript's inference features to its fullest, you'll quickly realize that _Generics_ are your best friend. And so, TanStack Router uses Generics everywhere to ensure that the types of your routes are inferred as much as possible.
298
+
299
+ This means that you have to define your routes in a way that allows TypeScript to infer the types of your routes as much as possible.
300
+
301
+ > Can I use JSX to define my routes?
302
+
303
+ Using JSX for defining your routes is **out of the question**, as TypeScript will not be able to infer the route configuration types of your router.
304
+
305
+ \`\`\`tsx
306
+ // ⛔️ This is not possible
307
+ function App() {
308
+ return (
309
+ <Router>
310
+ <Route path="/posts" component={PostsPage} />
311
+ <Route path="/posts/$postId" component={PostIdPage} />
312
+ {/* ... */}
313
+ </Router>
314
+ // ^? TypeScript cannot infer the routes in this configuration
315
+ )
316
+ }
317
+ \`\`\`
318
+
319
+ And since this would mean that you'd have to manually type the \`to\` prop of the \`<Link>\` component and wouldn't catch any errors until runtime, it's not a viable option.
320
+
321
+ > Maybe I could define my routes as a tree of nested objects?
322
+
323
+ \`\`\`tsx
324
+ // ⛔️ This file will just keep growing and growing...
325
+ const router = createRouter({
326
+ routes: {
327
+ posts: {
328
+ component: PostsPage, // /posts
329
+ children: {
330
+ $postId: {
331
+ component: PostIdPage, // /posts/$postId
332
+ },
333
+ },
334
+ },
335
+ // ...
336
+ },
337
+ })
338
+ \`\`\`
339
+
340
+ At first glance, this seems like a good idea. It's easy to visualize the entire route hierarchy in one go. But this approach has a couple of big downsides that make it not ideal for large applications:
341
+
342
+ - **It's not very scalable**: As your application grows, the tree will grow and become harder to manage. And since it's all defined in one file, it can become very hard to maintain.
343
+ - **It's not great for code-splitting**: You'd have to manually code-split each component and then pass it into the \`component\` property of the route, further complicating the route configuration with an ever-growing route configuration file.
344
+
345
+ This only gets worse as you begin to use more features of the router, such as nested context, loaders, search param validation, etc.
346
+
347
+ > So, what's the best way to define my routes?
348
+
349
+ What we found to be the best way to define your routes is to abstract the definition of the route configuration outside of the route-tree. Then stitch together your route configurations into a single cohesive route-tree that is then passed into the \`createRouter\` function.
350
+
351
+ You can read more about [code-based routing](./routing/code-based-routing.md) to see how to define your routes in this way.
352
+
353
+ > [!TIP]
354
+ > Finding Code-based routing to be a bit too cumbersome? See why [file-based routing](#why-is-file-based-routing-the-preferred-way-to-define-routes) is the preferred way to define your routes.
355
+
356
+ ## Declaring the Router instance for type inference
357
+
358
+ > Why do I have to declare the \`Router\`?
359
+
360
+ > This declaration stuff is way too complicated for me...
361
+
362
+ Once you've constructed your routes into a tree and passed it into your Router instance (using \`createRouter\`) with all the generics working correctly, you then need to somehow pass this information to the rest of your application.
363
+
364
+ There were two approaches we considered for this:
365
+
366
+ 1. **Imports**: You could import the \`Router\` instance from the file where you created it and use it directly in your components.
367
+
368
+ \`\`\`tsx
369
+ import { router } from '@/src/app'
370
+ export const PostsIdLink = () => {
371
+ return (
372
+ <Link<typeof router> to="/posts/$postId" params={{ postId: '123' }}>
373
+ Go to post 123
374
+ </Link>
375
+ )
376
+ }
377
+ \`\`\`
378
+
379
+ A downside to this approach is that you'd have to import the entire \`Router\` instance into every file where you want to use it. This can lead to increased bundle sizes and can be cumbersome to manage, and only get worse as your application grows and you use more features of the router.
380
+
381
+ 2. **Module declaration**: You can use TypeScript's module declaration to declare the \`Router\` instance as a module that can be used for type inference anywhere in your application without having to import it.
382
+
383
+ You'll do this once in your application.
384
+
385
+ \`\`\`tsx
386
+ // src/app.tsx
387
+ declare module '@tanstack/react-router' {
388
+ interface Register {
389
+ router: typeof router
390
+ }
391
+ }
392
+ \`\`\`
393
+
394
+ And then you can benefit from its auto-complete anywhere in your app without having to import it.
395
+
396
+ \`\`\`tsx
397
+ export const PostsIdLink = () => {
398
+ return (
399
+ <Link
400
+ to="/posts/$postId"
401
+ // ^? TypeScript will auto-complete this for you
402
+ params={{ postId: '123' }} // and this too!
403
+ >
404
+ Go to post 123
405
+ </Link>
406
+ )
407
+ }
408
+ \`\`\`
409
+
410
+ We went with **module declaration**, as it is what we found to be the most scalable and maintainable approach with the least amount of overhead and boilerplate.
411
+
412
+ ## Why is file-based routing the preferred way to define routes?
413
+
414
+ > Why are the docs pushing for file-based routing?
415
+
416
+ > I'm used to defining my routes in a single file, why should I change?
417
+
418
+ Something you'll notice (quite soon) in the TanStack Router documentation is that we push for **file-based routing** as the preferred method for defining your routes. This is because we've found that file-based routing is the most scalable and maintainable way to define your routes.
419
+
420
+ > [!TIP]
421
+ > Before you continue, it's important you have a good understanding of [code-based routing](./routing/code-based-routing.md) and [file-based routing](./routing/file-based-routing.md).
422
+
423
+ As mentioned in the beginning, TanStack Router was designed for complex applications that require a high degree of type-safety and maintainability. And to achieve this, the configuration of the router has been done in a precise way that allows TypeScript to infer the types of your routes as much as possible.
424
+
425
+ A key difference in the set-up of a _basic_ application with TanStack Router, is that your route configurations require a function to be provided to \`getParentRoute\`, that returns the parent route of the current route.
426
+
427
+ \`\`\`tsx
428
+ import { createRoute } from '@tanstack/react-router'
429
+ import { postsRoute } from './postsRoute'
430
+
431
+ export const postsIndexRoute = createRoute({
432
+ getParentRoute: () => postsRoute,
433
+ path: '/',
434
+ })
435
+ \`\`\`
436
+
437
+ At this stage, this is done so the definition of \`postsIndexRoute\` can be aware of its location in the route tree and so that it can correctly infer the types of the \`context\`, \`path params\`, \`search params\` returned by the parent route. Incorrectly defining the \`getParentRoute\` function means that the properties of the parent route will not be correctly inferred by the child route.
438
+
439
+ As such, this is a critical part of the route configuration and a point of failure if not done correctly.
440
+
441
+ But this is only one part of setting up a basic application. TanStack Router requires all the routes (including the root route) to be stitched into a **_route-tree_** so that it may be passed into the \`createRouter\` function before declaring the \`Router\` instance on the module for type inference. This is another critical part of the route configuration and a point of failure if not done correctly.
442
+
443
+ > 🤯 If this route-tree were in its own file for an application with ~40-50 routes, it can easily grow up to 700+ lines.
444
+
445
+ \`\`\`tsx
446
+ const routeTree = rootRoute.addChildren([
447
+ postsRoute.addChildren([postsIndexRoute, postsIdRoute]),
448
+ ])
449
+ \`\`\`
450
+
451
+ This complexity only increases as you begin to use more features of the router, such as nested context, loaders, search param validation, etc. As such, it no longer becomes feasible to define your routes in a single file. And so, users end up building their own _semi consistent_ way of defining their routes across multiple files. This can lead to inconsistencies and errors in the route configuration.
452
+
453
+ Finally, comes the issue of code-splitting. As your application grows, you'll want to code-split your components to reduce the initial bundle size of your application. This can be a bit of a headache to manage when you're defining your routes in a single file or even across multiple files.
454
+
455
+ \`\`\`tsx
456
+ import { createRoute, lazyRouteComponent } from '@tanstack/react-router'
457
+ import { postsRoute } from './postsRoute'
458
+
459
+ export const postsIndexRoute = createRoute({
460
+ getParentRoute: () => postsRoute,
461
+ path: '/',
462
+ component: lazyRouteComponent(() => import('../page-components/posts/index')),
463
+ })
464
+ \`\`\`
465
+
466
+ All of this boilerplate, no matter how essential for providing a best-in-class type-inference experience, can be a bit overwhelming and can lead to inconsistencies and errors in the route configuration.
467
+
468
+ ... and this example configuration is just for rendering a single codes-split route. Imagine having to do this for 40-50 routes. Now remember that you still haven't touched the \`context\`, \`loaders\`, \`search param validation\`, and other features of the router 🤕.
469
+
470
+ > So, why's file-based routing the preferred way?
471
+
472
+ TanStack Router's file-based routing is designed to solve all of these issues. It allows you to define your routes in a predictable way that is easy to manage and maintain, and is scalable as your application grows.
473
+
474
+ The file-based routing approach is powered by the TanStack Router Bundler Plugin. It performs 3 essential tasks that solve the pain points in route configuration when using code-based routing:
475
+
476
+ 1. **Route configuration boilerplate**: It generates the boilerplate for your route configurations.
477
+ 2. **Route tree stitching**: It stitches together your route configurations into a single cohesive route-tree. Also in the background, it correctly updates the route configurations to define the \`getParentRoute\` function match the routes with their parent routes.
478
+ 3. **Code-splitting**: It automatically code-splits your route content components and updates the route configurations with the correct component. Additionally, at runtime, it ensures that the correct component is loaded when the route is visited.
479
+
480
+ Let's take a look at how the route configuration for the previous example would look like with file-based routing.
481
+
482
+ \`\`\`tsx
483
+ // src/routes/posts/index.ts
484
+ import { createFileRoute } from '@tanstack/react-router'
485
+
486
+ export const Route = createFileRoute('/posts/')({
487
+ component: () => 'Posts index component goes here!!!',
488
+ })
489
+ \`\`\`
490
+
491
+ That's it! No need to worry about defining the \`getParentRoute\` function, stitching together the route-tree, or code-splitting your components. The TanStack Router Bundler Plugin handles all of this for you.
492
+
493
+ At no point does the TanStack Router Bundler Plugin take away your control over your route configurations. It's designed to be as flexible as possible, allowing you to define your routes in a way that suits your application whilst reducing the boilerplate and complexity of the route configuration.
494
+
495
+ Check out the guides for [file-based routing](./routing/file-based-routing.md) and [code-splitting](./guide/code-splitting.md) for a more in-depth explanation of how they work in TanStack Router.
496
+
497
+ # Devtools
498
+
499
+ > Link, take this sword... I mean Devtools!... to help you on your way!
500
+
501
+ Wave your hands in the air and shout hooray because TanStack Router comes with dedicated devtools! 🥳
502
+
503
+ When you begin your TanStack Router journey, you'll want these devtools by your side. They help visualize all of the inner workings of TanStack Router and will likely save you hours of debugging if you find yourself in a pinch!
504
+
505
+ ## Installation
506
+
507
+ The devtools are a separate package that you need to install:
508
+
509
+ <!-- ::start:tabs variant="package-manager" -->
510
+
511
+ react: @tanstack/react-router-devtools
512
+ solid: @tanstack/solid-router-devtools
513
+
514
+ <!-- ::end:tabs -->
515
+
516
+ ## Import the Devtools
517
+
518
+ <!-- ::start:framework -->
519
+
520
+ # React
521
+
522
+ \`\`\`tsx
523
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
524
+ \`\`\`
525
+
526
+ # Solid
527
+
528
+ \`\`\`tsx
529
+ import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
530
+ \`\`\`
531
+
532
+ <!-- ::end:framework -->
533
+
534
+ ## Using Devtools in production
535
+
536
+ The Devtools, if imported as \`TanStackRouterDevtools\` will not be shown in production. If you want to have devtools in an environment with \`process.env.NODE_ENV === 'production'\`, use instead \`TanStackRouterDevtoolsInProd\`, which has all the same options:
537
+
538
+ <!-- ::start:framework -->
539
+
540
+ # React
541
+
542
+ \`\`\`tsx
543
+ import { TanStackRouterDevtoolsInProd } from '@tanstack/react-router-devtools'
544
+ \`\`\`
545
+
546
+ # Solid
547
+
548
+ \`\`\`tsx
549
+ import { TanStackRouterDevtoolsInProd } from '@tanstack/solid-router-devtools'
550
+ \`\`\`
551
+
552
+ <!-- ::end:framework -->
553
+
554
+ ## Using the Devtools in the root route
555
+
556
+ The easiest way for the devtools to work is to render them inside of your root route (or any other route). This will automatically connect the devtools to the router instance.
557
+
558
+ <!-- ::start:framework -->
559
+
560
+ # React
561
+
562
+ <!-- ::start:tabs variant="files" -->
563
+
564
+ \`\`\`tsx title="src/routes/__root.tsx"
565
+ import { createRootRoute, Outlet } from '@tanstack/react-router'
566
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
567
+
568
+ export const Route = createRootRoute({
569
+ component: () => (
570
+ <>
571
+ <Outlet />
572
+ <TanStackRouterDevtools />
573
+ </>
574
+ ),
575
+ })
576
+ \`\`\`
577
+
578
+ <!-- ::end:tabs -->
579
+
580
+ # Solid
581
+
582
+ <!-- ::start:tabs variant="files" -->
583
+
584
+ \`\`\`tsx title="src/routes/__root.tsx"
585
+ import { createRootRoute, Outlet } from '@tanstack/solid-router'
586
+ import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
587
+
588
+ export const Route = createRootRoute({
589
+ component: () => (
590
+ <>
591
+ <Outlet />
592
+ <TanStackRouterDevtools />
593
+ </>
594
+ ),
595
+ })
596
+ \`\`\`
597
+
598
+ <!-- ::end:tabs -->
599
+
600
+ <!-- ::end:framework -->
601
+
602
+ ## Manually passing the Router Instance
603
+
604
+ If rendering the devtools inside of the \`RouterProvider\` isn't your cup of tea, a \`router\` prop for the devtools accepts the same \`router\` instance you pass to the \`Router\` component. This makes it possible to place the devtools anywhere on the page, not just inside the provider:
605
+
606
+ <!-- ::start:framework -->
607
+
608
+ # React
609
+
610
+ \`\`\`tsx
611
+ function App() {
612
+ return (
613
+ <>
614
+ <RouterProvider router={router} />
615
+ <TanStackRouterDevtools router={router} />
616
+ </>
617
+ )
618
+ }
619
+ \`\`\`
620
+
621
+ # Solid
622
+
623
+ \`\`\`tsx
624
+ function App() {
625
+ return (
626
+ <>
627
+ <RouterProvider router={router} />
628
+ <TanStackRouterDevtools router={router} />
629
+ </>
630
+ )
631
+ }
632
+ \`\`\`
633
+
634
+ <!-- ::end:framework -->
635
+
636
+ ## Floating Mode
637
+
638
+ Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
639
+
640
+ Place the following code as high in your app as you can. The closer it is to the root of the page, the better it will work!
641
+
642
+ <!-- ::start:framework -->
643
+
644
+ # React
645
+
646
+ \`\`\`tsx
647
+ function App() {
648
+ return (
649
+ <>
650
+ <RouterProvider router={router} />
651
+ <TanStackRouterDevtools initialIsOpen={false} />
652
+ </>
653
+ )
654
+ }
655
+ \`\`\`
656
+
657
+ # Solid
658
+
659
+ \`\`\`tsx
660
+ function App() {
661
+ return (
662
+ <>
663
+ <RouterProvider router={router} />
664
+ <TanStackRouterDevtools initialIsOpen={false} />
665
+ </>
666
+ )
667
+ }
668
+ \`\`\`
669
+
670
+ <!-- ::end:framework -->
671
+
672
+ ### Devtools Options
673
+
674
+ - \`router: Router\`
675
+ - The router instance to connect to.
676
+ - \`initialIsOpen: Boolean\`
677
+ - Set this \`true\` if you want the devtools to default to being open.
678
+ - \`panelProps: PropsObject\`
679
+ - Use this to add props to the panel. For example, you can add \`className\`, \`style\` (merge and override default style), etc.
680
+ - \`closeButtonProps: PropsObject\`
681
+ - Use this to add props to the close button. For example, you can add \`className\`, \`style\` (merge and override default style), \`onClick\` (extend default handler), etc.
682
+ - \`toggleButtonProps: PropsObject\`
683
+ - Use this to add props to the toggle button. For example, you can add \`className\`, \`style\` (merge and override default style), \`onClick\` (extend default handler), etc.
684
+ - \`position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"\`
685
+ - Defaults to \`bottom-left\`.
686
+ - The position of the TanStack Router logo to open and close the devtools panel.
687
+ - \`shadowDOMTarget?: ShadowRoot\`
688
+ - Specifies a Shadow DOM target for the devtools.
689
+ - By default, devtool styles are applied to the \`<head>\` tag of the main document (light DOM). When a \`shadowDOMTarget\` is provided, styles will be applied within this Shadow DOM instead.
690
+ - \`containerElement?: string | any\`
691
+ - Use this to render the devtools inside a different type of container element for ally purposes.
692
+ - Any string which corresponds to a valid intrinsic JSX element is allowed.
693
+ - Defaults to 'footer'.
694
+
695
+ ## Fixed Mode
696
+
697
+ To control the position of the devtools, import the \`TanStackRouterDevtoolsPanel\`:
698
+
699
+ <!-- ::start:framework -->
700
+
701
+ # React
702
+
703
+ \`\`\`tsx
704
+ import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
705
+ \`\`\`
706
+
707
+ # Solid
708
+
709
+ \`\`\`tsx
710
+ import { TanStackRouterDevtoolsPanel } from '@tanstack/solid-router-devtools'
711
+ \`\`\`
712
+
713
+ <!-- ::end:framework -->
714
+
715
+ It can then be attached to provided shadow DOM target:
716
+
717
+ <!-- ::start:framework -->
718
+
719
+ # React
720
+
721
+ \`\`\`tsx
722
+ <TanStackRouterDevtoolsPanel
723
+ shadowDOMTarget={shadowContainer}
724
+ router={router}
725
+ />
726
+ \`\`\`
727
+
728
+ # Solid
729
+
730
+ \`\`\`tsx
731
+ <TanStackRouterDevtoolsPanel
732
+ shadowDOMTarget={shadowContainer}
733
+ router={router}
734
+ />
735
+ \`\`\`
736
+
737
+ <!-- ::end:framework -->
738
+
739
+ Click [here](https://tanstack.com/router/latest/docs/framework/react/examples/basic-devtools-panel) to see a live example of this in StackBlitz.
740
+
741
+ ## Embedded Mode
742
+
743
+ Embedded Mode will embed the devtools as a regular component in your application. You can style it however you'd like after that!
744
+
745
+ <!-- ::start:framework -->
746
+
747
+ # React
748
+
749
+ \`\`\`tsx
750
+ import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
751
+
752
+ function App() {
753
+ return (
754
+ <>
755
+ <RouterProvider router={router} />
756
+ <TanStackRouterDevtoolsPanel
757
+ router={router}
758
+ style={styles}
759
+ className={className}
760
+ />
761
+ </>
762
+ )
763
+ }
764
+ \`\`\`
765
+
766
+ # Solid
767
+
768
+ \`\`\`tsx
769
+ import { TanStackRouterDevtoolsPanel } from '@tanstack/solid-router-devtools'
770
+
771
+ function App() {
772
+ return (
773
+ <>
774
+ <RouterProvider router={router} />
775
+ <TanStackRouterDevtoolsPanel
776
+ router={router}
777
+ style={styles}
778
+ class={className}
779
+ />
780
+ </>
781
+ )
782
+ }
783
+ \`\`\`
784
+
785
+ <!-- ::end:framework -->
786
+
787
+ ### DevtoolsPanel Options
788
+
789
+ - \`router: Router\`
790
+ - The router instance to connect to.
791
+
792
+ <!-- ::start:framework -->
793
+
794
+ # React
795
+
796
+ - \`style?: StyleObject\`
797
+ - The standard React style object used to style a component with inline styles.
798
+ - \`className?: string\`
799
+ - The standard React className property used to style a component with classes.
800
+
801
+ # Solid
802
+
803
+ - \`style?: StyleObject\`
804
+ - The standard Solid style object used to style a component with inline styles.
805
+ - \`class?: string\`
806
+ - The standard Solid class property used to style a component with classes.
807
+
808
+ <!-- ::end:framework -->
809
+
810
+ - \`isOpen?: boolean\`
811
+ - A boolean variable indicating whether the panel is open or closed.
812
+ - \`setIsOpen?: (isOpen: boolean) => void\`
813
+ - A function that toggles the open and close state of the panel.
814
+ - \`handleDragStart?: (e: any) => void\`
815
+ - Handles the opening and closing the devtools panel.
816
+ - \`shadowDOMTarget?: ShadowRoot\`
817
+ - Specifies a Shadow DOM target for the devtools.
818
+ - By default, devtool styles are applied to the \`<head>\` tag of the main document (light DOM). When a \`shadowDOMTarget\` is provided, styles will be applied within this Shadow DOM instead.
819
+
820
+ # Frequently Asked Questions
821
+
822
+ Welcome to the TanStack Router FAQ! Here you'll find answers to common questions about the TanStack Router. If you have a question that isn't answered here, please feel free to ask in the [TanStack Discord](https://tlinz.com/discord).
823
+
824
+ ## Why should you choose TanStack Router over another router?
825
+
826
+ To answer this question, it's important to view the other options in the space. There are many alternatives to choose from, but only a couple that are widely adopted and actively maintained:
827
+
828
+ - **Next.js** - Widely regarded as the leading framework for starting new React projects. Its design focuses on performance, development workflows, and cutting-edge technology. The framework's APIs and abstractions, while powerful, can sometimes present as non-standard. Rapid growth and industry adoption have resulted in a feature-rich experience, sometimes leading to a steeper learning curve and increased overhead.
829
+ - **Remix / React Router** - Based on the historically successful React Router, Remix delivers a powerful developer and user experience. Its API and architectural vision are firmly rooted in web standards such as Request/Response, with an emphasis on adaptability across various JavaScript environments. Many of its APIs and abstractions are well-designed and have influenced more than a few of TanStack Router's APIs. However, its rigid design, the integration of type safety as an add-on, and sometimes strict adherence to platform APIs can present limitations for some developers.
830
+
831
+ These frameworks and routers have their strengths, but they also come with trade-offs that may not align with every project's needs. TanStack Router aims to strike a balance by offering routing APIs designed to improve the developer experience without sacrificing flexibility or performance.
832
+
833
+ ## Is TanStack Router a framework?
834
+
835
+ TanStack Router itself is not a "framework" in the traditional sense, since it doesn't address a few other common full-stack concerns. However, TanStack Router has been designed to be upgradable to a full-stack framework when used in conjunction with other tools that address bundling, deployments, and server-side-specific functionality. This is why we are currently developing [TanStack Start](https://tanstack.com/start), a full-stack framework that is built on top of TanStack Router and Vite.
836
+ For a deeper dive on the history of TanStack Router, feel free to read [TanStack Router's History](./decisions-on-dx.md#tanstack-routers-origin-story).
837
+
838
+ ## Should I commit my \`routeTree.gen.ts\` file into git?
839
+
840
+ Yes! Although the route tree file (i.e., \`routeTree.gen.ts\`) is generated by TanStack Router, it is essentially part of your application’s runtime, not a build artifact. The route tree file is a critical part of your application’s source code, and it is used by TanStack Router to build your application’s routes at runtime.
841
+
842
+ You should commit this file into git so that other developers can use it to build your application.
843
+
844
+ ## Can I conditionally render the Root Route component?
845
+
846
+ No, the root route is always rendered as it is the entry point of your application.
847
+ If you need to conditionally render a route's component, this usually means that the page content needs to be different based on some condition (e.g. user authentication). For this use case, you should use a [Layout Route](./routing/routing-concepts.md#layout-routes) or a [Pathless Layout Route](./routing/routing-concepts.md#pathless-layout-routes) to conditionally render the content.
848
+
849
+ You can restrict access to these routes using a conditional check in the \`beforeLoad\` function of the route.
850
+
851
+ <details>
852
+ <summary>What does this look like?</summary>
853
+
854
+ <!-- ::start:framework -->
855
+
856
+ # React
857
+
858
+ \`\`\`tsx
859
+ // src/routes/_pathless-layout.tsx
860
+ import { createFileRoute, Outlet } from '@tanstack/react-router'
861
+ import { isAuthenticated } from '../utils/auth'
862
+
863
+ export const Route = createFileRoute('/_pathless-layout', {
864
+ beforeLoad: async () => {
865
+ // Check if the user is authenticated
866
+ const authed = await isAuthenticated()
867
+ if (!authed) {
868
+ // Redirect the user to the login page
869
+ return '/login'
870
+ }
871
+ },
872
+ component: PathlessLayoutRouteComponent,
873
+ // ...
874
+ })
875
+
876
+ function PathlessLayoutRouteComponent() {
877
+ return (
878
+ <div>
879
+ <h1>You are authed</h1>
880
+ <Outlet />
881
+ </div>
882
+ )
883
+ }
884
+ \`\`\`
885
+
886
+ # Solid
887
+
888
+ \`\`\`tsx
889
+ // src/routes/_pathless-layout.tsx
890
+ import { createFileRoute, Outlet } from '@tanstack/solid-router'
891
+ import { isAuthenticated } from '../utils/auth'
892
+
893
+ export const Route = createFileRoute('/_pathless-layout', {
894
+ beforeLoad: async () => {
895
+ // Check if the user is authenticated
896
+ const authed = await isAuthenticated()
897
+ if (!authed) {
898
+ // Redirect the user to the login page
899
+ return '/login'
900
+ }
901
+ },
902
+ component: PathlessLayoutRouteComponent,
903
+ // ...
904
+ })
905
+
906
+ function PathlessLayoutRouteComponent() {
907
+ return (
908
+ <div>
909
+ <h1>You are authed</h1>
910
+ <Outlet />
911
+ </div>
912
+ )
913
+ }
914
+ \`\`\`
915
+
916
+ <!-- ::end:framework -->
917
+
918
+ </details>
919
+
920
+ `;