@rangojs/router 0.0.0-experimental.135c6902 → 0.0.0-experimental.136

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 (404) hide show
  1. package/AGENTS.md +8 -0
  2. package/README.md +245 -49
  3. package/dist/bin/rango.js +440 -133
  4. package/dist/testing/vitest.js +82 -0
  5. package/dist/vite/index.js +3386 -1111
  6. package/dist/vite/index.js.bak +5448 -0
  7. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  8. package/package.json +78 -25
  9. package/skills/api-client/SKILL.md +211 -0
  10. package/skills/breadcrumbs/SKILL.md +64 -2
  11. package/skills/bundle-analysis/SKILL.md +159 -0
  12. package/skills/cache-guide/SKILL.md +247 -23
  13. package/skills/caching/SKILL.md +281 -11
  14. package/skills/composability/SKILL.md +27 -3
  15. package/skills/css/SKILL.md +76 -0
  16. package/skills/debug-manifest/SKILL.md +4 -2
  17. package/skills/document-cache/SKILL.md +78 -55
  18. package/skills/handler-use/SKILL.md +364 -0
  19. package/skills/hooks/SKILL.md +250 -30
  20. package/skills/host-router/SKILL.md +83 -23
  21. package/skills/i18n/SKILL.md +276 -0
  22. package/skills/intercept/SKILL.md +87 -18
  23. package/skills/layout/SKILL.md +35 -9
  24. package/skills/links/SKILL.md +249 -17
  25. package/skills/loader/SKILL.md +289 -53
  26. package/skills/middleware/SKILL.md +52 -13
  27. package/skills/migrate-nextjs/SKILL.md +584 -0
  28. package/skills/migrate-react-router/SKILL.md +914 -0
  29. package/skills/mime-routes/SKILL.md +28 -1
  30. package/skills/observability/SKILL.md +172 -0
  31. package/skills/parallel/SKILL.md +144 -7
  32. package/skills/prerender/SKILL.md +172 -125
  33. package/skills/rango/SKILL.md +251 -22
  34. package/skills/react-compiler/SKILL.md +168 -0
  35. package/skills/response-routes/SKILL.md +123 -48
  36. package/skills/route/SKILL.md +101 -5
  37. package/skills/router-setup/SKILL.md +117 -10
  38. package/skills/scripts/SKILL.md +179 -0
  39. package/skills/server-actions/SKILL.md +775 -0
  40. package/skills/streams-and-websockets/SKILL.md +283 -0
  41. package/skills/tailwind/SKILL.md +27 -3
  42. package/skills/testing/SKILL.md +130 -0
  43. package/skills/testing/bindings.md +103 -0
  44. package/skills/testing/cache-prerender.md +127 -0
  45. package/skills/testing/client-components.md +124 -0
  46. package/skills/testing/e2e-parity.md +125 -0
  47. package/skills/testing/flight.md +91 -0
  48. package/skills/testing/handles.md +129 -0
  49. package/skills/testing/loader.md +128 -0
  50. package/skills/testing/middleware.md +99 -0
  51. package/skills/testing/render-handler.md +122 -0
  52. package/skills/testing/response-routes.md +95 -0
  53. package/skills/testing/reverse-and-types.md +84 -0
  54. package/skills/testing/server-actions.md +107 -0
  55. package/skills/testing/server-tree.md +128 -0
  56. package/skills/testing/setup.md +123 -0
  57. package/skills/typesafety/SKILL.md +332 -29
  58. package/skills/use-cache/SKILL.md +57 -14
  59. package/skills/view-transitions/SKILL.md +337 -0
  60. package/src/__augment-tests__/augment.ts +81 -0
  61. package/src/__augment-tests__/augmented.check.ts +116 -0
  62. package/src/__internal.ts +1 -66
  63. package/src/browser/action-coordinator.ts +53 -36
  64. package/src/browser/action-fence.ts +47 -0
  65. package/src/browser/app-shell.ts +39 -0
  66. package/src/browser/app-version.ts +14 -0
  67. package/src/browser/connection-warmup.ts +134 -0
  68. package/src/browser/cookie-name.ts +140 -0
  69. package/src/browser/event-controller.ts +192 -150
  70. package/src/browser/history-state.ts +21 -0
  71. package/src/browser/index.ts +3 -3
  72. package/src/browser/invalidate-client-cache.ts +52 -0
  73. package/src/browser/navigation-bridge.ts +131 -30
  74. package/src/browser/navigation-client.ts +199 -86
  75. package/src/browser/navigation-store-handle.ts +38 -0
  76. package/src/browser/navigation-store.ts +157 -74
  77. package/src/browser/navigation-transaction.ts +9 -59
  78. package/src/browser/network-error-handler.ts +34 -7
  79. package/src/browser/partial-update.ts +174 -109
  80. package/src/browser/prefetch/cache.ts +222 -69
  81. package/src/browser/prefetch/fetch.ts +347 -39
  82. package/src/browser/prefetch/queue.ts +113 -32
  83. package/src/browser/prefetch/resource-ready.ts +77 -0
  84. package/src/browser/rango-state.ts +158 -76
  85. package/src/browser/react/Link.tsx +102 -15
  86. package/src/browser/react/NavigationProvider.tsx +300 -122
  87. package/src/browser/react/ScrollRestoration.tsx +10 -6
  88. package/src/browser/react/context.ts +7 -2
  89. package/src/browser/react/deferred-handle-resolution.ts +75 -0
  90. package/src/browser/react/filter-segment-order.ts +66 -7
  91. package/src/browser/react/index.ts +0 -48
  92. package/src/browser/react/location-state-shared.ts +178 -8
  93. package/src/browser/react/location-state.ts +39 -14
  94. package/src/browser/react/use-action.ts +6 -15
  95. package/src/browser/react/use-handle.ts +23 -69
  96. package/src/browser/react/use-href.tsx +8 -1
  97. package/src/browser/react/use-link-status.ts +33 -8
  98. package/src/browser/react/use-navigation.ts +32 -7
  99. package/src/browser/react/use-params.ts +20 -10
  100. package/src/browser/react/use-reverse.ts +106 -0
  101. package/src/browser/react/use-router.ts +46 -11
  102. package/src/browser/react/use-search-params.ts +0 -5
  103. package/src/browser/react/use-segments.ts +11 -21
  104. package/src/browser/response-adapter.ts +99 -8
  105. package/src/browser/rsc-router.tsx +125 -28
  106. package/src/browser/scroll-restoration.ts +37 -22
  107. package/src/browser/segment-reconciler.ts +36 -14
  108. package/src/browser/segment-structure-assert.ts +2 -2
  109. package/src/browser/server-action-bridge.ts +222 -61
  110. package/src/browser/types.ts +115 -12
  111. package/src/browser/validate-redirect-origin.ts +43 -16
  112. package/src/build/collect-fallback-refs.ts +107 -0
  113. package/src/build/generate-manifest.ts +65 -40
  114. package/src/build/generate-route-types.ts +5 -1
  115. package/src/build/index.ts +8 -2
  116. package/src/build/prefix-tree-utils.ts +123 -0
  117. package/src/build/route-trie.ts +165 -36
  118. package/src/build/route-types/ast-route-extraction.ts +15 -8
  119. package/src/build/route-types/codegen.ts +16 -5
  120. package/src/build/route-types/include-resolution.ts +125 -24
  121. package/src/build/route-types/param-extraction.ts +6 -3
  122. package/src/build/route-types/per-module-writer.ts +22 -6
  123. package/src/build/route-types/router-processing.ts +260 -94
  124. package/src/build/route-types/scan-filter.ts +9 -2
  125. package/src/build/route-types/source-scan.ts +216 -0
  126. package/src/build/runtime-discovery.ts +9 -20
  127. package/src/cache/cache-error.ts +104 -0
  128. package/src/cache/cache-key-utils.ts +29 -13
  129. package/src/cache/cache-policy.ts +108 -34
  130. package/src/cache/cache-runtime.ts +239 -52
  131. package/src/cache/cache-scope.ts +234 -87
  132. package/src/cache/cache-tag.ts +103 -0
  133. package/src/cache/cf/cf-base64.ts +33 -0
  134. package/src/cache/cf/cf-cache-constants.ts +127 -0
  135. package/src/cache/cf/cf-cache-store.ts +1989 -378
  136. package/src/cache/cf/cf-cache-types.ts +349 -0
  137. package/src/cache/cf/cf-kv-utils.ts +46 -0
  138. package/src/cache/cf/cf-tag-marker-memo.ts +105 -0
  139. package/src/cache/cf/index.ts +6 -16
  140. package/src/cache/document-cache.ts +89 -21
  141. package/src/cache/handle-snapshot.ts +70 -0
  142. package/src/cache/index.ts +10 -20
  143. package/src/cache/memory-segment-store.ts +136 -37
  144. package/src/cache/profile-registry.ts +46 -31
  145. package/src/cache/read-through-swr.ts +56 -12
  146. package/src/cache/segment-codec.ts +9 -17
  147. package/src/cache/tag-invalidation.ts +230 -0
  148. package/src/cache/taint.ts +55 -0
  149. package/src/cache/types.ts +37 -100
  150. package/src/client.rsc.tsx +44 -21
  151. package/src/client.tsx +119 -290
  152. package/src/cloudflare/index.ts +11 -0
  153. package/src/cloudflare/tracing.ts +109 -0
  154. package/src/component-utils.ts +19 -0
  155. package/src/components/DefaultDocument.tsx +8 -2
  156. package/src/context-var.ts +84 -2
  157. package/src/decode-loader-results.ts +52 -0
  158. package/src/defer.ts +196 -0
  159. package/src/deps/ssr.ts +0 -1
  160. package/src/encode-kv.ts +49 -0
  161. package/src/errors.ts +30 -4
  162. package/src/escape-script.ts +52 -0
  163. package/src/handle.ts +70 -22
  164. package/src/handles/MetaTags.tsx +62 -19
  165. package/src/handles/Scripts.tsx +183 -0
  166. package/src/handles/breadcrumbs.ts +37 -8
  167. package/src/handles/is-thenable.ts +19 -0
  168. package/src/handles/meta.ts +51 -40
  169. package/src/handles/script.ts +244 -0
  170. package/src/host/cookie-handler.ts +9 -60
  171. package/src/host/errors.ts +0 -24
  172. package/src/host/index.ts +8 -2
  173. package/src/host/pattern-matcher.ts +23 -52
  174. package/src/host/router.ts +107 -99
  175. package/src/host/testing.ts +40 -27
  176. package/src/host/types.ts +37 -4
  177. package/src/host/utils.ts +1 -1
  178. package/src/href-client.ts +137 -22
  179. package/src/index.rsc.ts +99 -13
  180. package/src/index.ts +139 -19
  181. package/src/internal-debug.ts +11 -10
  182. package/src/loader-store.ts +500 -0
  183. package/src/loader.rsc.ts +20 -13
  184. package/src/loader.ts +12 -11
  185. package/src/missing-id-error.ts +68 -0
  186. package/src/outlet-context.ts +1 -1
  187. package/src/outlet-provider.tsx +1 -5
  188. package/src/prerender/param-hash.ts +16 -16
  189. package/src/prerender/store.ts +37 -41
  190. package/src/prerender.ts +198 -82
  191. package/src/redirect-origin.ts +100 -0
  192. package/src/regex-escape.ts +8 -0
  193. package/src/render-error-thrower.tsx +20 -0
  194. package/src/response-utils.ts +62 -0
  195. package/src/reverse.ts +65 -15
  196. package/src/root-error-boundary.tsx +1 -19
  197. package/src/route-content-wrapper.tsx +19 -77
  198. package/src/route-definition/dsl-helpers.ts +461 -304
  199. package/src/route-definition/helper-factories.ts +28 -140
  200. package/src/route-definition/helpers-types.ts +149 -74
  201. package/src/route-definition/index.ts +4 -2
  202. package/src/route-definition/redirect.ts +51 -10
  203. package/src/route-definition/resolve-handler-use.ts +160 -0
  204. package/src/route-definition/use-item-types.ts +29 -0
  205. package/src/route-map-builder.ts +0 -16
  206. package/src/route-types.ts +37 -46
  207. package/src/router/basename.ts +14 -0
  208. package/src/router/content-negotiation.ts +164 -17
  209. package/src/router/error-handling.ts +45 -18
  210. package/src/router/find-match.ts +44 -23
  211. package/src/router/handler-context.ts +83 -39
  212. package/src/router/instrument.ts +350 -0
  213. package/src/router/intercept-resolution.ts +48 -24
  214. package/src/router/lazy-includes.ts +15 -52
  215. package/src/router/loader-resolution.ts +274 -56
  216. package/src/router/logging.ts +0 -6
  217. package/src/router/manifest.ts +40 -42
  218. package/src/router/match-api.ts +124 -204
  219. package/src/router/match-context.ts +0 -22
  220. package/src/router/match-handlers.ts +58 -58
  221. package/src/router/match-middleware/background-revalidation.ts +54 -25
  222. package/src/router/match-middleware/cache-lookup.ts +205 -271
  223. package/src/router/match-middleware/cache-store.ts +81 -50
  224. package/src/router/match-middleware/intercept-resolution.ts +0 -22
  225. package/src/router/match-middleware/segment-resolution.ts +45 -14
  226. package/src/router/match-pipelines.ts +1 -42
  227. package/src/router/match-result.ts +93 -39
  228. package/src/router/metrics.ts +5 -34
  229. package/src/router/middleware-types.ts +13 -142
  230. package/src/router/middleware.ts +268 -171
  231. package/src/router/navigation-snapshot.ts +131 -0
  232. package/src/router/params-util.ts +23 -0
  233. package/src/router/pattern-matching.ts +132 -90
  234. package/src/router/prefetch-cache-ttl.ts +51 -0
  235. package/src/router/prefetch-limits.ts +37 -0
  236. package/src/router/prerender-match.ts +195 -56
  237. package/src/router/preview-match.ts +32 -102
  238. package/src/router/request-classification.ts +276 -0
  239. package/src/router/revalidation.ts +123 -73
  240. package/src/router/route-snapshot.ts +244 -0
  241. package/src/router/router-context.ts +3 -27
  242. package/src/router/router-interfaces.ts +129 -35
  243. package/src/router/router-options.ts +202 -15
  244. package/src/router/router-registry.ts +2 -5
  245. package/src/router/segment-resolution/fresh.ts +197 -92
  246. package/src/router/segment-resolution/helpers.ts +115 -30
  247. package/src/router/segment-resolution/loader-cache.ts +76 -39
  248. package/src/router/segment-resolution/revalidation.ts +392 -338
  249. package/src/router/segment-resolution/static-store.ts +19 -5
  250. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  251. package/src/router/segment-resolution/view-transition-default.ts +56 -0
  252. package/src/router/segment-resolution.ts +5 -1
  253. package/src/router/segment-wrappers.ts +6 -5
  254. package/src/router/state-cookie-name.ts +33 -0
  255. package/src/router/substitute-pattern-params.ts +56 -0
  256. package/src/router/telemetry-otel.ts +161 -199
  257. package/src/router/telemetry.ts +96 -19
  258. package/src/router/timeout.ts +0 -20
  259. package/src/router/tracing.ts +206 -0
  260. package/src/router/trie-matching.ts +163 -59
  261. package/src/router/types.ts +10 -63
  262. package/src/router/url-params.ts +44 -0
  263. package/src/router.ts +174 -54
  264. package/src/rsc/handler-context.ts +3 -2
  265. package/src/rsc/handler.ts +660 -518
  266. package/src/rsc/helpers.ts +168 -46
  267. package/src/rsc/index.ts +2 -5
  268. package/src/rsc/json-route-result.ts +38 -0
  269. package/src/rsc/loader-fetch.ts +127 -31
  270. package/src/rsc/manifest-init.ts +33 -42
  271. package/src/rsc/origin-guard.ts +39 -25
  272. package/src/rsc/progressive-enhancement.ts +133 -13
  273. package/src/rsc/redirect-guard.ts +99 -0
  274. package/src/rsc/response-cache-serve.ts +238 -0
  275. package/src/rsc/response-error.ts +79 -12
  276. package/src/rsc/response-route-handler.ts +99 -189
  277. package/src/rsc/rsc-rendering.ts +115 -73
  278. package/src/rsc/runtime-warnings.ts +23 -10
  279. package/src/rsc/server-action.ts +287 -113
  280. package/src/rsc/ssr-setup.ts +18 -2
  281. package/src/rsc/transition-gate.ts +89 -0
  282. package/src/rsc/types.ts +36 -6
  283. package/src/runtime-env.ts +18 -0
  284. package/src/search-params.ts +35 -30
  285. package/src/segment-content-promise.ts +67 -0
  286. package/src/segment-loader-promise.ts +149 -0
  287. package/src/segment-system.tsx +269 -202
  288. package/src/serialize.ts +243 -0
  289. package/src/server/context.ts +235 -51
  290. package/src/server/cookie-parse.ts +32 -0
  291. package/src/server/cookie-store.ts +80 -5
  292. package/src/server/handle-store.ts +40 -38
  293. package/src/server/loader-registry.ts +38 -46
  294. package/src/server/request-context.ts +442 -173
  295. package/src/ssr/index.tsx +24 -16
  296. package/src/static-handler.ts +27 -18
  297. package/src/testing/cache-status.ts +162 -0
  298. package/src/testing/collect-handle.ts +40 -0
  299. package/src/testing/dispatch.ts +701 -0
  300. package/src/testing/dom.entry.ts +22 -0
  301. package/src/testing/e2e/fixture.ts +188 -0
  302. package/src/testing/e2e/index.ts +128 -0
  303. package/src/testing/e2e/matchers.ts +35 -0
  304. package/src/testing/e2e/page-helpers.ts +272 -0
  305. package/src/testing/e2e/parity.ts +387 -0
  306. package/src/testing/e2e/server.ts +195 -0
  307. package/src/testing/flight-matchers.ts +97 -0
  308. package/src/testing/flight-normalize.ts +11 -0
  309. package/src/testing/flight-runtime.d.ts +57 -0
  310. package/src/testing/flight-tree.ts +682 -0
  311. package/src/testing/flight.entry.ts +52 -0
  312. package/src/testing/flight.ts +257 -0
  313. package/src/testing/generated-routes.ts +183 -0
  314. package/src/testing/index.ts +105 -0
  315. package/src/testing/internal/context.ts +371 -0
  316. package/src/testing/internal/flight-client-globals.ts +30 -0
  317. package/src/testing/internal/seed-vars.ts +54 -0
  318. package/src/testing/render-handler.ts +357 -0
  319. package/src/testing/render-route.tsx +581 -0
  320. package/src/testing/run-loader.ts +385 -0
  321. package/src/testing/run-middleware.ts +205 -0
  322. package/src/testing/run-transition-when.ts +164 -0
  323. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  324. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  325. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  326. package/src/testing/vitest-stubs/version.ts +5 -0
  327. package/src/testing/vitest.ts +305 -0
  328. package/src/theme/ThemeProvider.tsx +20 -58
  329. package/src/theme/ThemeScript.tsx +7 -9
  330. package/src/theme/constants.ts +52 -13
  331. package/src/theme/index.ts +0 -7
  332. package/src/theme/theme-context.ts +1 -5
  333. package/src/theme/theme-script.ts +22 -21
  334. package/src/theme/use-theme.ts +0 -3
  335. package/src/types/boundaries.ts +0 -35
  336. package/src/types/cache-types.ts +17 -8
  337. package/src/types/error-types.ts +30 -90
  338. package/src/types/global-namespace.ts +54 -41
  339. package/src/types/handler-context.ts +234 -82
  340. package/src/types/index.ts +3 -10
  341. package/src/types/loader-types.ts +44 -15
  342. package/src/types/request-scope.ts +112 -0
  343. package/src/types/route-config.ts +6 -50
  344. package/src/types/route-entry.ts +12 -7
  345. package/src/types/segments.ts +136 -15
  346. package/src/urls/include-helper.ts +33 -70
  347. package/src/urls/index.ts +1 -11
  348. package/src/urls/path-helper-types.ts +68 -18
  349. package/src/urls/path-helper.ts +57 -111
  350. package/src/urls/pattern-types.ts +48 -19
  351. package/src/urls/response-types.ts +25 -22
  352. package/src/urls/type-extraction.ts +58 -139
  353. package/src/urls/urls-function.ts +1 -19
  354. package/src/use-loader.tsx +346 -89
  355. package/src/vite/debug.ts +185 -0
  356. package/src/vite/discovery/bundle-postprocess.ts +36 -38
  357. package/src/vite/discovery/discover-routers.ts +130 -85
  358. package/src/vite/discovery/discovery-errors.ts +194 -0
  359. package/src/vite/discovery/gate-state.ts +171 -0
  360. package/src/vite/discovery/prerender-collection.ts +214 -132
  361. package/src/vite/discovery/route-types-writer.ts +40 -84
  362. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  363. package/src/vite/discovery/state.ts +57 -4
  364. package/src/vite/discovery/virtual-module-codegen.ts +14 -34
  365. package/src/vite/index.ts +6 -0
  366. package/src/vite/inject-client-debug.ts +36 -0
  367. package/src/vite/plugin-types.ts +178 -5
  368. package/src/vite/plugins/cjs-to-esm.ts +16 -19
  369. package/src/vite/plugins/client-ref-dedup.ts +16 -11
  370. package/src/vite/plugins/client-ref-hashing.ts +28 -15
  371. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  372. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  373. package/src/vite/plugins/cloudflare-protocol-stub.ts +194 -0
  374. package/src/vite/plugins/expose-action-id.ts +48 -95
  375. package/src/vite/plugins/expose-id-utils.ts +96 -51
  376. package/src/vite/plugins/expose-ids/export-analysis.ts +101 -34
  377. package/src/vite/plugins/expose-ids/handler-transform.ts +15 -64
  378. package/src/vite/plugins/expose-ids/loader-transform.ts +14 -24
  379. package/src/vite/plugins/expose-ids/router-transform.ts +118 -29
  380. package/src/vite/plugins/expose-internal-ids.ts +553 -317
  381. package/src/vite/plugins/performance-tracks.ts +89 -0
  382. package/src/vite/plugins/refresh-cmd.ts +89 -27
  383. package/src/vite/plugins/use-cache-transform.ts +73 -83
  384. package/src/vite/plugins/version-injector.ts +40 -29
  385. package/src/vite/plugins/version-plugin.ts +37 -40
  386. package/src/vite/plugins/virtual-entries.ts +39 -25
  387. package/src/vite/rango.ts +119 -111
  388. package/src/vite/router-discovery.ts +941 -142
  389. package/src/vite/utils/ast-handler-extract.ts +26 -35
  390. package/src/vite/utils/banner.ts +1 -1
  391. package/src/vite/utils/bundle-analysis.ts +10 -15
  392. package/src/vite/utils/client-chunks.ts +184 -0
  393. package/src/vite/utils/directive-prologue.ts +40 -0
  394. package/src/vite/utils/forward-user-plugins.ts +171 -0
  395. package/src/vite/utils/manifest-utils.ts +4 -59
  396. package/src/vite/utils/package-resolution.ts +20 -52
  397. package/src/vite/utils/prerender-utils.ts +81 -34
  398. package/src/vite/utils/shared-utils.ts +92 -42
  399. package/src/browser/action-response-classifier.ts +0 -99
  400. package/src/browser/react/use-client-cache.ts +0 -58
  401. package/src/browser/shallow.ts +0 -40
  402. package/src/handles/index.ts +0 -7
  403. package/src/network-error-thrower.tsx +0 -23
  404. package/src/router/middleware-cookies.ts +0 -55
@@ -0,0 +1,914 @@
1
+ ---
2
+ name: migrate-react-router
3
+ description: Migrate a React Router v7/v6 project to @rangojs/router. Use when the user asks to "migrate from React Router", "convert React Router to Rango", "replace React Router", "move from Remix to Rango", or has a React Router / Remix app they want to port.
4
+ argument-hint: path-to-react-router-app
5
+ ---
6
+
7
+ # Migrate from React Router to @rangojs/router
8
+
9
+ Covers React Router v7 (framework mode and library mode), v6, and Remix v2.
10
+
11
+ ## Why Rango
12
+
13
+ Common reasons to migrate:
14
+
15
+ - **Server components by default** — move from client-first route rendering to
16
+ server-first UI and data fetching.
17
+ See: `/router-setup`, `/route`
18
+ - **Django-style route definition** — `urls()`, `path()`, and `layout()` make
19
+ the route tree explicit instead of splitting behavior across route modules or
20
+ router config objects.
21
+ See: `/route`, `/layout`
22
+ - **Named routes** — reverse URLs by route name instead of repeating path
23
+ strings in links, redirects, and navigation logic.
24
+ See: `/links`, `/typesafety`
25
+ - **Clear execution model** — request scope, render scope, segment boundaries,
26
+ and shared `ctx` behavior are explicit instead of being inferred from route
27
+ module conventions.
28
+ See: `/middleware`, `/loader`
29
+ - **Live data layer** — `createLoader()` and `loader()` keep data fresh
30
+ independently of cached UI. A route can serve cached segments while loaders
31
+ still resolve live on every request.
32
+ See: `/loader`, `/caching`, `/cache-guide`
33
+ - **Explicit caching model** — `cache()` DSL, `revalidate()`, `use cache`, and
34
+ custom cache stores make data and render caching a first-class part of the router.
35
+ See: `/caching`, `/cache-guide`, `/use-cache`
36
+ - **Build-time rendering** — `Static()` and `Prerender()` provide explicit
37
+ build-time rendering for routes that benefit from it.
38
+ See: `/prerender`
39
+ - **Composable route tree** — layouts, includes, middleware, parallels, and
40
+ intercepts compose directly in the route definition.
41
+ See: `/composability`, `/parallel`, `/intercept`
42
+ - **Multi-router flexibility** — support multiple routers, domain routing, and
43
+ more advanced host-routing setups than a single client router tree.
44
+ See: `/host-router`
45
+
46
+ ## Identify the mode first
47
+
48
+ React Router v7 has two modes that require different migration paths:
49
+
50
+ - **Framework mode** (`@react-router/dev` plugin, file-based routing, route module
51
+ API with `loader`/`action`/`meta`/`headers`/`shouldRevalidate` exports) — this is
52
+ the Remix successor. Migration involves replacing the route module convention with
53
+ Rango's `urls()` DSL and server component handlers.
54
+
55
+ - **Library mode** (`createBrowserRouter` or `<BrowserRouter>`, client-side only) —
56
+ migration involves moving from client-side routing to server-rendered RSC with the
57
+ `urls()` DSL.
58
+
59
+ React Router v6 and Remix v2 follow the same patterns as v7 library mode and
60
+ framework mode respectively.
61
+
62
+ ## Migration Strategy
63
+
64
+ Work route-by-route, bottom-up. Start with leaf routes, then layouts, then
65
+ loaders/actions. Verify each route works before moving to the next.
66
+
67
+ ## 1. Project Setup
68
+
69
+ Replace React Router tooling with Vite + Rango:
70
+
71
+ ```bash
72
+ # Framework mode:
73
+ npm remove react-router @react-router/dev @react-router/node @react-router/serve
74
+ # Library mode:
75
+ npm remove react-router react-router-dom
76
+
77
+ npm install @rangojs/router
78
+ ```
79
+
80
+ Replace the `@react-router/dev` Vite plugin with `rango()`:
81
+
82
+ ```typescript
83
+ // vite.config.ts
84
+ // Before: import { reactRouter } from "@react-router/dev/vite";
85
+ import { defineConfig } from "vite";
86
+ import { rango } from "@rangojs/router/vite";
87
+
88
+ export default defineConfig({
89
+ plugins: [rango()],
90
+ });
91
+ ```
92
+
93
+ Delete `react-router.config.ts` — route configuration moves to the `urls()` DSL.
94
+
95
+ ```typescript
96
+ // src/router.tsx
97
+ import { createRouter } from "@rangojs/router";
98
+ import { Document } from "./document";
99
+ import { urlpatterns } from "./urls";
100
+
101
+ export default createRouter({
102
+ document: Document,
103
+ }).routes(urlpatterns);
104
+ ```
105
+
106
+ ## 2. Route Mapping
107
+
108
+ ### RR7 framework mode: route modules → urls() DSL
109
+
110
+ In framework mode, each route is a file with conventional exports (`loader`,
111
+ `action`, `default`, `meta`, `headers`, `shouldRevalidate`, `handle`,
112
+ `ErrorBoundary`, `HydrateFallback`). In Rango, all of these become part of the
113
+ `urls()` DSL or move into the server component handler:
114
+
115
+ ```text
116
+ RR7 route module export → Rango equivalent
117
+ ─────────────────────────────────────────────────────
118
+ default (Component) → handler in path()
119
+ loader → fetch in handler, or createLoader()
120
+ action → "use server" function
121
+ meta → ctx.use(Meta) in handler
122
+ headers → ctx.header() in handler or middleware
123
+ shouldRevalidate → revalidate() DSL
124
+ ErrorBoundary → errorBoundary() DSL
125
+ HydrateFallback → loading() DSL
126
+ handle → createHandle() for cross-segment data (breadcrumbs, etc.)
127
+ clientLoader / clientAction → "use client" component with React hooks
128
+ ```
129
+
130
+ #### Example: full route module migration
131
+
132
+ ```typescript
133
+ // RR7 framework mode: app/routes/product.$slug.tsx
134
+ import type { Route } from "./+types/product.$slug";
135
+
136
+ export async function loader({ params }: Route.LoaderArgs) {
137
+ const product = await getProduct(params.slug);
138
+ if (!product) throw new Response("Not Found", { status: 404 });
139
+ return { product };
140
+ }
141
+
142
+ export async function action({ request }: Route.ActionArgs) {
143
+ const formData = await request.formData();
144
+ await addToCart(formData.get("productId") as string);
145
+ return { ok: true };
146
+ }
147
+
148
+ export function meta({ data }: Route.MetaArgs) {
149
+ return [{ title: data.product.name }];
150
+ }
151
+
152
+ export function headers() {
153
+ return { "Cache-Control": "max-age=300" };
154
+ }
155
+
156
+ export function shouldRevalidate({ actionResult }) {
157
+ return !!actionResult;
158
+ }
159
+
160
+ export default function ProductPage({ loaderData }: Route.ComponentProps) {
161
+ return <div>{loaderData.product.name}</div>;
162
+ }
163
+
164
+ export function ErrorBoundary() {
165
+ return <div>Product error</div>;
166
+ }
167
+ ```
168
+
169
+ ```typescript
170
+ // Rango: urls.tsx + handler
171
+ import { notFound } from "@rangojs/router";
172
+
173
+ const ProductPage: Handler<"product"> = async (ctx) => {
174
+ const product = await getProduct(ctx.params.slug);
175
+ if (!product) notFound("Product not found");
176
+
177
+ const meta = ctx.use(Meta);
178
+ meta({ title: product.name });
179
+ ctx.header("Cache-Control", "max-age=300");
180
+
181
+ return <div>{product.name}</div>;
182
+ };
183
+
184
+ // In urls.tsx:
185
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
186
+ revalidate(({ actionId }) => !!actionId),
187
+ errorBoundary(() => <div>Product error</div>),
188
+ loading(<ProductSkeleton />),
189
+ ])
190
+ ```
191
+
192
+ Key shift: the route module's scattered exports consolidate into the handler
193
+ (data fetching, meta, headers) and the DSL (revalidation, error boundary, loading).
194
+
195
+ ### RR7 file routing → urls() DSL
196
+
197
+ | RR7 file path | Rango |
198
+ | ---------------------------------------- | ------------------------------------------------------------- |
199
+ | `app/routes/_index.tsx` | `path("/", HomePage, { name: "home" })` |
200
+ | `app/routes/about.tsx` | `path("/about", AboutPage, { name: "about" })` |
201
+ | `app/routes/blog.$slug.tsx` | `path("/blog/:slug", BlogPost, { name: "blogPost" })` |
202
+ | `app/routes/files.$.tsx` (splat) | `path("/files/:path+", FileBrowser, { name: "files" })` |
203
+ | `app/routes/dashboard.tsx` (layout) | `layout(<DashboardLayout />, () => [...])` |
204
+ | `app/routes/dashboard._index.tsx` | `path("/dashboard", DashboardIndex, { name: "dashboard" })` |
205
+ | `app/routes/dashboard.settings.tsx` | `path("/dashboard/settings", Settings, { name: "settings" })` |
206
+ | `app/routes/_auth.tsx` (pathless layout) | `layout(<AuthLayout />, () => [...])` |
207
+ | `app/routes/_auth.login.tsx` | `path("/login", LoginPage, { name: "login" })` |
208
+
209
+ ### Library mode: config routes → urls() DSL
210
+
211
+ | React Router | Rango |
212
+ | -------------------------------------- | ------------------------------------------------------- |
213
+ | `path: "/"` | `path("/", HomePage, { name: "home" })` |
214
+ | `path: "about"` | `path("/about", AboutPage, { name: "about" })` |
215
+ | `path: "blog/:slug"` | `path("/blog/:slug", BlogPost, { name: "blogPost" })` |
216
+ | `path: "files/*"` (splat) | `path("/files/:path+", FileBrowser, { name: "files" })` |
217
+ | `path: "docs/:lang?"` (optional param) | `path("/docs/:lang?", Docs, { name: "docs" })` |
218
+
219
+ ### Layouts
220
+
221
+ React Router layouts use `<Outlet />` — same concept in Rango:
222
+
223
+ ```typescript
224
+ // React Router:
225
+ function DashboardLayout() {
226
+ return (
227
+ <div className="dashboard">
228
+ <Outlet />
229
+ </div>
230
+ );
231
+ }
232
+
233
+ // route config:
234
+ { path: "dashboard", element: <DashboardLayout />, children: [...] }
235
+
236
+ // Rango: same <Outlet />, from @rangojs/router/client
237
+ import { Outlet } from "@rangojs/router/client";
238
+
239
+ layout(<DashboardLayout />, () => [
240
+ path("/dashboard", DashboardIndex, { name: "dashboard" }),
241
+ path("/dashboard/settings", Settings, { name: "settings" }),
242
+ ])
243
+ ```
244
+
245
+ ### Dynamic layouts (with data)
246
+
247
+ ```typescript
248
+ // React Router: useLoaderData() in layout component
249
+ function DashboardLayout() {
250
+ const { user } = useLoaderData();
251
+ return <Shell user={user}><Outlet /></Shell>;
252
+ }
253
+
254
+ // Rango: handler function layout (server component)
255
+ layout(async (ctx) => {
256
+ const user = ctx.get("user");
257
+ return (
258
+ <Shell user={user}>
259
+ <Outlet />
260
+ </Shell>
261
+ );
262
+ }, () => [
263
+ path("/dashboard", DashboardIndex, { name: "dashboard" }),
264
+ ])
265
+ ```
266
+
267
+ ### Nested routes
268
+
269
+ React Router's nested route tree maps directly to Rango's `layout()` nesting:
270
+
271
+ ```typescript
272
+ // React Router:
273
+ createBrowserRouter([{
274
+ path: "/",
275
+ element: <RootLayout />,
276
+ children: [
277
+ { path: "dashboard",
278
+ element: <DashboardLayout />,
279
+ children: [
280
+ { index: true, element: <DashboardIndex /> },
281
+ { path: "settings", element: <Settings /> },
282
+ ]
283
+ },
284
+ ]
285
+ }])
286
+
287
+ // Rango:
288
+ urls(({ path, layout }) => [
289
+ layout(<RootLayout />, () => [
290
+ layout(<DashboardLayout />, () => [
291
+ path("/dashboard", DashboardIndex, { name: "dashboard" }),
292
+ path("/dashboard/settings", Settings, { name: "settings" }),
293
+ ]),
294
+ ]),
295
+ ])
296
+ ```
297
+
298
+ ### Route groups / pathless layouts
299
+
300
+ React Router's pathless routes (layout routes without a path) are Rango's
301
+ layouts without a URL prefix:
302
+
303
+ ```typescript
304
+ // React Router: { element: <AuthLayout />, children: [...] }
305
+
306
+ // Rango: layout with no URL segment
307
+ layout(<AuthLayout />, () => [
308
+ path("/login", LoginPage, { name: "login" }),
309
+ path("/register", RegisterPage, { name: "register" }),
310
+ ])
311
+ ```
312
+
313
+ ### Index routes
314
+
315
+ ```typescript
316
+ // React Router: { index: true, element: <Home /> }
317
+
318
+ // Rango: path with "/" inside a layout
319
+ layout(<RootLayout />, () => [
320
+ path("/", HomePage, { name: "home" }),
321
+ ])
322
+ ```
323
+
324
+ ## 3. Data Fetching
325
+
326
+ ### Loaders → handler (the default migration)
327
+
328
+ In React Router, loaders and components are separate: the loader fetches data,
329
+ the component renders it via `useLoaderData()`. In Rango, server component
330
+ handlers do both — combine the loader and component into a single handler:
331
+
332
+ ```typescript
333
+ // React Router: separate loader + component
334
+ export async function loader({ params }) {
335
+ const product = await getProduct(params.slug);
336
+ return { product };
337
+ }
338
+ function ProductPage() {
339
+ const { product } = useLoaderData();
340
+ return <div>{product.name}</div>;
341
+ }
342
+
343
+ // Rango: handler fetches and renders directly
344
+ const ProductPage: Handler<"product"> = async (ctx) => {
345
+ const product = await getProduct(ctx.params.slug);
346
+ return <div>{product.name}</div>;
347
+ };
348
+ ```
349
+
350
+ This is the standard migration path. The handler IS the loader — it fetches
351
+ data, then returns JSX. No separate data-fetching layer needed.
352
+
353
+ ### When to use createLoader()
354
+
355
+ Rango's `createLoader()` is a live data layer, not a loader migration target.
356
+ Use it only when you need capabilities beyond what the handler provides:
357
+
358
+ - **Client-side reactive data** — `useLoader()` in client components for data
359
+ that updates without a full page navigation
360
+ - **Shared data across segments** — a loader registered on a layout is available
361
+ to all child routes via `ctx.use(Loader)` or `useLoader(Loader)`
362
+ - **Independent revalidation** — `revalidate()` on a specific loader after actions
363
+ - **Per-loader caching** — `loader(L, () => [cache({ ttl: 60 })])`
364
+
365
+ If the React Router loader just fetches data for its page component, merge it
366
+ into the handler. See `/loader` for when the live data layer is useful.
367
+
368
+ ### Actions
369
+
370
+ React Router form actions map to Rango server actions:
371
+
372
+ ```typescript
373
+ // React Router:
374
+ export async function action({ request }) {
375
+ const formData = await request.formData();
376
+ await updateUser(formData.get("name"));
377
+ return redirect("/profile");
378
+ }
379
+ function EditProfile() {
380
+ return (
381
+ <Form method="post">
382
+ <input name="name" />
383
+ <button type="submit">Save</button>
384
+ </Form>
385
+ );
386
+ }
387
+
388
+ // Rango: "use server" action + native form or useActionState
389
+ "use server";
390
+ import { redirect } from "@rangojs/router";
391
+
392
+ export async function updateProfile(formData: FormData): Promise<void> {
393
+ await updateUser(formData.get("name") as string);
394
+ throw redirect("/profile");
395
+ }
396
+
397
+ // Client component:
398
+ function EditProfile() {
399
+ return (
400
+ <form action={updateProfile}>
401
+ <input name="name" />
402
+ <button type="submit">Save</button>
403
+ </form>
404
+ );
405
+ }
406
+ ```
407
+
408
+ Key difference: React Router actions are route-scoped (declared per route).
409
+ Rango actions are function-scoped (`"use server"` on any exported async function).
410
+
411
+ ### useLoaderData
412
+
413
+ There is no `useLoaderData()` in Rango. For most cases, the handler fetches
414
+ and renders directly (see above). When a client component needs live reactive
415
+ data, use `createLoader()` + `useLoader()`:
416
+
417
+ ```typescript
418
+ // React Router: useLoaderData() in client component
419
+ function ProductPrice() {
420
+ const { price } = useLoaderData();
421
+ return <span>{price}</span>;
422
+ }
423
+
424
+ // Rango: useLoader() reads from a registered loader (live data layer)
425
+ "use client";
426
+ import { useLoader } from "@rangojs/router/client";
427
+ import { PriceLoader } from "../loaders";
428
+
429
+ function ProductPrice() {
430
+ const { data } = useLoader(PriceLoader);
431
+ return <span>{data.price}</span>;
432
+ }
433
+ ```
434
+
435
+ `useLoader()` provides live data that stays fresh — it re-fetches on navigation
436
+ and after actions (controlled by `revalidate()`). This is different from
437
+ `useLoaderData()` which just reads a snapshot.
438
+
439
+ ### useActionData
440
+
441
+ React Router's `useActionData()` reads the return value of a route-scoped
442
+ `action()`. In Rango, actions are standard React server actions (`"use server"`),
443
+ so all React patterns apply directly:
444
+
445
+ ```typescript
446
+ // React Router:
447
+ export async function action({ request }) {
448
+ const form = await request.formData();
449
+ const errors = validate(form);
450
+ if (errors) return { errors };
451
+ await save(form);
452
+ return { ok: true };
453
+ }
454
+ function EditForm() {
455
+ const data = useActionData();
456
+ return (
457
+ <Form method="post">
458
+ {data?.errors && <p>{data.errors}</p>}
459
+ <input name="title" />
460
+ <button>Save</button>
461
+ </Form>
462
+ );
463
+ }
464
+
465
+ // Rango: useActionState (standard React hook)
466
+ "use client";
467
+ import { useActionState } from "react";
468
+ import { saveForm } from "../actions"; // "use server" function
469
+
470
+ function EditForm() {
471
+ const [state, action, pending] = useActionState(saveForm, null);
472
+ return (
473
+ <form action={action}>
474
+ {state?.errors && <p>{state.errors}</p>}
475
+ <input name="title" />
476
+ <button disabled={pending}>Save</button>
477
+ </form>
478
+ );
479
+ }
480
+ ```
481
+
482
+ Since Rango uses RSC server actions, all React action patterns work:
483
+ `useActionState`, `useOptimistic`, `useTransition`, `startTransition`,
484
+ and plain `<form action={serverAction}>`. No framework-specific hook needed.
485
+
486
+ For the full guide — defining actions, validation with Zod, error handling,
487
+ revalidation rules, file uploads, and progressive enhancement — see
488
+ `/server-actions`.
489
+
490
+ ### clientLoader / clientAction (framework mode)
491
+
492
+ RR7 framework mode's `clientLoader` and `clientAction` run in the browser.
493
+ Rango does not have a framework-level client loader/action concept — these
494
+ migrate to standard React client-side code:
495
+
496
+ ```typescript
497
+ // RR7: clientLoader fetching from a third-party API
498
+ export async function clientLoader() {
499
+ const res = await fetch("https://api.weather.com/current?city=london");
500
+ return res.json();
501
+ }
502
+
503
+ // Rango: "use client" component with hooks
504
+ "use client";
505
+ import { useState, useEffect } from "react";
506
+
507
+ function WeatherWidget() {
508
+ const [weather, setWeather] = useState(null);
509
+ useEffect(() => {
510
+ fetch("https://api.weather.com/current?city=london")
511
+ .then((r) => r.json())
512
+ .then(setWeather);
513
+ }, []);
514
+ if (!weather) return <span>Loading...</span>;
515
+ return <span>{weather.temp}°C</span>;
516
+ }
517
+ ```
518
+
519
+ The general rule: anything that ran in `clientLoader`/`clientAction` moves into
520
+ React hooks (`useState`, `useEffect`, `useActionState`, `useOptimistic`) inside
521
+ a `"use client"` component. There is no framework wrapper — it's just React.
522
+
523
+ ### shouldRevalidate (framework mode)
524
+
525
+ RR7's `shouldRevalidate` export maps directly to Rango's `revalidate()` DSL:
526
+
527
+ ```typescript
528
+ // RR7:
529
+ export function shouldRevalidate({ actionResult, currentParams, nextParams }) {
530
+ if (actionResult) return true;
531
+ return currentParams.slug !== nextParams.slug;
532
+ }
533
+
534
+ // Rango:
535
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
536
+ revalidate(({ actionId, currentParams, nextParams }) => {
537
+ if (actionId) return true;
538
+ return currentParams.slug !== nextParams.slug;
539
+ }),
540
+ ]);
541
+ ```
542
+
543
+ Note: RR7's `shouldRevalidate` controls client-side loader re-fetching. Rango's
544
+ `revalidate()` controls which segments re-run during partial rendering after
545
+ navigation or actions. The intent is the same — skip unnecessary work — but
546
+ the mechanism is segment-level rather than loader-level.
547
+
548
+ ## 4. Middleware / Route Protection
549
+
550
+ React Router doesn't have built-in middleware. Protection is typically done in loaders:
551
+
552
+ ```typescript
553
+ // React Router: auth check in loader
554
+ export async function loader({ request }) {
555
+ const user = await getUser(request);
556
+ if (!user) throw redirect("/login");
557
+ return { user };
558
+ }
559
+
560
+ // Rango: router.use() for request-level auth
561
+ const router = createRouter({})
562
+ .use(authInit) // all routes — resolves session
563
+ .use("/dashboard/*", requireAuth) // scoped guard
564
+ .routes(urlpatterns);
565
+ ```
566
+
567
+ Use `router.use()` for auth guards (wraps entire request including actions).
568
+ Use DSL `middleware()` for render-level concerns (context shaping, headers).
569
+ See `/middleware`.
570
+
571
+ ## 5. Loading & Error States
572
+
573
+ ### Loading / Suspense
574
+
575
+ ```typescript
576
+ // React Router: defer() + Suspense, or HydrateFallback
577
+ export async function loader() {
578
+ return defer({ data: fetchData() });
579
+ }
580
+
581
+ // Rango: loading() DSL for automatic Suspense boundaries
582
+ path("/dashboard", DashboardPage, { name: "dashboard" }, () => [
583
+ loading(<DashboardSkeleton />),
584
+ ])
585
+ ```
586
+
587
+ ### Error boundaries
588
+
589
+ ```typescript
590
+ // React Router:
591
+ { path: "dashboard", element: <Dashboard />, errorElement: <ErrorPage /> }
592
+
593
+ // or with ErrorBoundary component:
594
+ function ErrorBoundary() {
595
+ const error = useRouteError();
596
+ return <div>Error: {error.message}</div>;
597
+ }
598
+
599
+ // Rango: errorBoundary() wrapping a group of routes
600
+ // Server-side error boundaries only receive `error` (no `reset` — server render
601
+ // cannot be retried; users can navigate away or refresh).
602
+ layout(<DashboardLayout />, () => [
603
+ errorBoundary(({ error }) => (
604
+ <div>
605
+ <h2>Something went wrong</h2>
606
+ <p>{error.message}</p>
607
+ </div>
608
+ )),
609
+ path("/dashboard", DashboardIndex, { name: "dashboard" }),
610
+ path("/dashboard/settings", Settings, { name: "settings" }),
611
+ ])
612
+ ```
613
+
614
+ ### Not found
615
+
616
+ ```typescript
617
+ // React Router: { path: "*", element: <NotFound /> }
618
+
619
+ // Rango (app-level):
620
+ createRouter({
621
+ notFound: ({ pathname }) => <NotFoundPage pathname={pathname} />,
622
+ })
623
+
624
+ // Rango (route-level — catches notFound() thrown in handlers/loaders):
625
+ layout(<ShopLayout />, () => [
626
+ notFoundBoundary(<ProductNotFound />),
627
+ path("/product/:slug", ProductPage, { name: "product" }),
628
+ ])
629
+ ```
630
+
631
+ ## 6. Navigation
632
+
633
+ | React Router | Rango |
634
+ | ----------------------------------------- | -------------------------------------------------------------------------------- |
635
+ | `import { Link } from "react-router-dom"` | `import { Link } from "@rangojs/router/client"` |
636
+ | `<Link to="/about">` | `<Link to="/about">` |
637
+ | `useNavigate()` | `useRouter()` from `@rangojs/router/client` |
638
+ | `navigate("/about")` | `useRouter().push("/about")` |
639
+ | `navigate("/about", { replace: true })` | `useRouter().replace("/about")` |
640
+ | `navigate(-1)` | `useRouter().back()` |
641
+ | `useLocation().pathname` | `usePathname()` from `@rangojs/router/client` |
642
+ | `useSearchParams()` | `useSearchParams()` from `@rangojs/router/client` |
643
+ | `useParams()` | `useParams()` from `@rangojs/router/client` (or `ctx.params` in server handlers) |
644
+ | `useParams<T>()` | `useParams<T>()` — same generic annotation pattern |
645
+ | `<NavLink>` | `<Link>` with `usePathname()` for active state |
646
+
647
+ ### useNavigate → useRouter
648
+
649
+ ```typescript
650
+ // React Router:
651
+ const navigate = useNavigate();
652
+ navigate("/dashboard");
653
+ navigate(-1);
654
+
655
+ // Rango:
656
+ const router = useRouter();
657
+ router.push("/dashboard");
658
+ router.back();
659
+ ```
660
+
661
+ ## 7. Metadata / Head
662
+
663
+ ```typescript
664
+ // React Router: meta function export (framework mode)
665
+ export function meta() {
666
+ return [{ title: "Home" }, { name: "description", content: "Welcome" }];
667
+ }
668
+
669
+ // Rango: Meta handle in server handlers
670
+ import { Meta } from "@rangojs/router";
671
+
672
+ const HomePage: Handler<"home"> = (ctx) => {
673
+ const meta = ctx.use(Meta);
674
+ meta({ title: "Home" });
675
+ meta({ name: "description", content: "Welcome" });
676
+ return <div>Home page</div>;
677
+ };
678
+ ```
679
+
680
+ Add `<MetaTags />` in the Document component's `<head>`:
681
+
682
+ ```typescript
683
+ import { MetaTags } from "@rangojs/router/client";
684
+
685
+ function Document({ children }: { children: ReactNode }) {
686
+ return (
687
+ <html>
688
+ <head>
689
+ <MetaTags />
690
+ </head>
691
+ <body>{children}</body>
692
+ </html>
693
+ );
694
+ }
695
+ ```
696
+
697
+ ## 8. API / Resource Routes
698
+
699
+ ```typescript
700
+ // React Router (framework mode):
701
+ // app/routes/api.users.ts
702
+ export async function loader() {
703
+ return Response.json(await getUsers());
704
+ }
705
+
706
+ // Rango: response routes
707
+ path.json(
708
+ "/api/users",
709
+ async () => {
710
+ return await getUsers();
711
+ },
712
+ { name: "apiUsers" },
713
+ );
714
+ ```
715
+
716
+ See `/response-routes` for `path.json()`, `path.text()`, `path.html()`, etc.
717
+
718
+ ## 9. Theme / Dark Mode
719
+
720
+ Rango has a built-in theme system with FOUC prevention. If the React Router app
721
+ uses a custom theme provider or `next-themes`, replace it with Rango's theme API:
722
+
723
+ ```typescript
724
+ const router = createRouter({
725
+ theme: true, // or { defaultTheme: "system", attribute: "class" }
726
+ });
727
+ ```
728
+
729
+ Client components use `useTheme()` to read and toggle:
730
+
731
+ ```typescript
732
+ "use client";
733
+ import { useTheme } from "@rangojs/router/theme";
734
+
735
+ function ThemeToggle() {
736
+ const { theme, setTheme } = useTheme();
737
+ return <button onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>{theme}</button>;
738
+ }
739
+ ```
740
+
741
+ See `/theme` for full API including system detection and cookie persistence.
742
+
743
+ ## 10. Cloudflare Workers: streaming, dev tooling, and deploy
744
+
745
+ This is the part of an RR7-on-Cloudflare migration that the API tables above do
746
+ **not** cover, and it produces symptoms that look like router bugs but aren't.
747
+ RR7 serves a fully-rendered HTML/Turbo-Stream response; Rango serves a **streamed**
748
+ RSC/SSR response. Anything in the request path that was harmless for RR7 but
749
+ **buffers the response** silently kills that stream — the `loading()` /
750
+ `<Suspense>` fallback never shows and the page appears "awaited" (old content
751
+ held until everything resolves).
752
+
753
+ ### 10a. Never buffer the Rango response in a custom worker entry
754
+
755
+ RR7 Cloudflare entries commonly **rewrite the response body** — `await
756
+ response.text()` / `await response.arrayBuffer()`, `HTMLRewriter`, cookie/URL
757
+ rewriting, hybrid-proxy bridging. That is fine for RR7's complete HTML, but if it
758
+ runs on the **Rango** path it consumes the stream and you lose streaming
759
+ entirely.
760
+
761
+ Rule: in the worker entry, the Rango response must pass through as a **stream**.
762
+ Buffer only on non-Rango branches (a legacy/SFRA proxy, an error page).
763
+
764
+ ```typescript
765
+ // BAD — buffers the whole RSC stream before returning (no streaming, no fallback)
766
+ const response = await router.fetch(request, { env, ctx });
767
+ const body = await response.text(); // <- drains the stream
768
+ return new Response(rewrite(body), response);
769
+
770
+ // GOOD — pass the body through as a stream (re-wrap headers only)
771
+ const response = await router.fetch(request, { env, ctx });
772
+ return new Response(response.body, response); // <- streams; safe to add headers
773
+ ```
774
+
775
+ If you keep a legacy proxy (e.g. an SFRA/host fallback) that legitimately buffers
776
+ to rewrite HTML, gate it so it only runs for proxied paths — never for the
777
+ `router.fetch()` result.
778
+
779
+ Keep the custom entry itself (host/site resolution, sessions, proxy fallback) —
780
+ that's real product logic, not a deviation. Just don't let it touch the stream.
781
+
782
+ ### 10b. Use `vite dev` / `vite preview`, not `wrangler dev`, for local work
783
+
784
+ The `@cloudflare/vite-plugin` runs **your worker entry** inside miniflare for both
785
+ `vite dev` and `vite preview`, with bindings + `.dev.vars`, and it **streams**.
786
+ `wrangler dev` does **not** stream RSC locally: it gzip-compresses the response by
787
+ buffering the entire body before sending. Measured on a bare streaming Worker
788
+ under `wrangler dev`: `Accept-Encoding: gzip` → first byte at the full delay
789
+ (buffered); `Accept-Encoding: identity` → first byte at ~3ms (streams). The
790
+ deployed Cloudflare edge does **streaming** compression, so this is a
791
+ **local-`wrangler dev`-only artifact** — do not mistake it for a production
792
+ streaming bug (verify the deployed edge with `curl` and watch chunk timing /
793
+ `transfer-encoding: chunked`).
794
+
795
+ ```jsonc
796
+ // package.json — the standard rango-on-Workers shape
797
+ "dev": "vite", // streams, bindings, .dev.vars live
798
+ "build": "vite build",
799
+ "preview": "vite preview", // runs the built worker in workerd; also streams
800
+ // wrangler is only for: wrangler deploy / wrangler secret
801
+ ```
802
+
803
+ If a workflow truly requires `wrangler dev`, declare `Content-Encoding: identity`
804
+ on streamed responses, gated to local hostnames (so the edge still compresses):
805
+
806
+ ```typescript
807
+ if (
808
+ isLocalHostname(url.hostname) &&
809
+ response.body &&
810
+ !response.headers.has("content-encoding")
811
+ ) {
812
+ const ct = (response.headers.get("content-type") ?? "").toLowerCase();
813
+ if (ct.includes("text/html") || ct.includes("text/x-component")) {
814
+ const headers = new Headers(response.headers);
815
+ headers.set("content-encoding", "identity"); // wrangler skips gzip -> streams
816
+ return new Response(response.body, {
817
+ status: response.status,
818
+ statusText: response.statusText,
819
+ headers,
820
+ });
821
+ }
822
+ }
823
+ ```
824
+
825
+ ### 10c. `.dev.vars` loads differently per tool
826
+
827
+ A frequent "my env vars vanished after migration" symptom — it's the tool, not
828
+ the file:
829
+
830
+ | Command | How `.dev.vars` is loaded |
831
+ | -------------- | ------------------------------------------------------------------------------------ |
832
+ | `wrangler dev` | Loaded natively at runtime (RR7's path — why it "worked before") |
833
+ | `vite dev` | Loaded **live** by the plugin (+ `.dev.vars.<CLOUDFLARE_ENV>` if a named env is set) |
834
+ | `vite preview` | Read from the **build output** `dist/<env>/.dev.vars`, written at `vite build` time |
835
+
836
+ So `vite preview` only sees vars that were present when you built — re-run
837
+ `vite build` after editing `.dev.vars`. (`vite dev` is the simplest: live vars +
838
+ streaming, no rebuild.)
839
+
840
+ ### 10d. Build output moves from `build/` to `dist/`
841
+
842
+ RR7's `react-router build` writes to `build/`; Rango's `vite build` writes to
843
+ `dist/` (`dist/client`, `dist/rsc`, …). The leftover `build/` paths in
844
+ `wrangler.toml` and cleanup scripts must move, or you deploy stale/empty assets:
845
+
846
+ ```toml
847
+ # wrangler.toml — was RR7's react-router build output
848
+ - assets = { directory = "./build/client/", binding = "ASSETS" }
849
+ + assets = { directory = "./dist/client/", binding = "ASSETS" }
850
+ ```
851
+
852
+ ```jsonc
853
+ // package.json — clean the real output dir
854
+ - "cleanup": "rimraf ./build ./public/build"
855
+ + "cleanup": "rimraf ./dist ./build ./public/build"
856
+ ```
857
+
858
+ ### 10e. Deploy the built worker, not the source entry
859
+
860
+ `vite build` emits the **deployable** Worker config at `dist/<env>/wrangler.json`
861
+ with `main: "index.js"` (the bundled worker), `no_bundle: true`, and
862
+ `assets: "../client"`. A plain `wrangler deploy` run from the repo root uses the
863
+ **root** `wrangler.toml`, where `main` points at your **source** entry
864
+ (`app/.../worker.ts`) — and wrangler's bundler cannot resolve Rango's
865
+ `virtual:rsc-router/*` modules, so deploying the source entry fails or ships a
866
+ broken worker. Deploy the build output instead (e.g.
867
+ `wrangler deploy -c dist/<env>/wrangler.json`) or use the plugin's deploy flow.
868
+ RR7's `wrangler deploy` from root worked only because its worker was already
869
+ fully bundled by `react-router build`.
870
+
871
+ ## 11. Key Conceptual Differences
872
+
873
+ | Concept | React Router | Rango |
874
+ | ------------------- | ----------------------------------- | -------------------------------------- |
875
+ | Rendering | Client-side by default, SSR opt-in | Server components by default (RSC) |
876
+ | Data loading | `loader()` + `useLoaderData()` | Direct fetch in server components |
877
+ | Form actions | Route-scoped `action()` | Function-scoped `"use server"` |
878
+ | Route definition | File-based or `createBrowserRouter` | `urls()` DSL with `path()`, `layout()` |
879
+ | Middleware | Not built-in (use loaders) | `router.use()` + DSL `middleware()` |
880
+ | Parallel routes | Not built-in | `parallel()` DSL |
881
+ | Intercepting routes | Not built-in | `intercept()` DSL |
882
+ | Caching | Not built-in | `cache()` DSL, `"use cache"` |
883
+ | Type-safe routes | Partial (v7 framework mode) | Full: params, names, href, reverse |
884
+
885
+ ## Migration Checklist
886
+
887
+ 1. [ ] Set up Vite config with `rango()` plugin
888
+ 2. [ ] Create Document component with `<MetaTags />` in head
889
+ 3. [ ] Create `router.tsx` with `createRouter()`
890
+ 4. [ ] Convert route config / file routes to `urls()` DSL
891
+ 5. [ ] Migrate layouts — keep `<Outlet />` (import from `@rangojs/router/client`)
892
+ 6. [ ] Merge loaders + components into handler functions (fetch + render in one place)
893
+ 7. [ ] Convert React Router actions to `"use server"` functions
894
+ 8. [ ] Migrate auth guards from loaders to `router.use()`
895
+ 9. [ ] Replace `react-router-dom` Link/navigation with `@rangojs/router/client`
896
+ 10. [ ] Convert error boundaries to `errorBoundary()` DSL
897
+ 11. [ ] Update metadata to use `Meta` handle + `<MetaTags />`
898
+ 12. [ ] Replace custom theme provider with `theme: true` in createRouter (see `/theme`)
899
+ 13. [ ] Run `npx rango generate src/` to generate route types
900
+
901
+ **Cloudflare Workers (if migrating an RR7-on-Workers app):**
902
+
903
+ 14. [ ] Audit the custom worker entry — the `router.fetch()` response must pass
904
+ through as a **stream** (`new Response(response.body, response)`); remove
905
+ any `.text()`/`.arrayBuffer()`/`HTMLRewriter` buffering from the Rango
906
+ path (keep it only on legacy/proxy branches). See §10a.
907
+ 15. [ ] Switch local dev to `vite dev` / `vite preview` (they stream + load
908
+ `.dev.vars` + provide bindings); stop using `wrangler dev` for local
909
+ verification — it gzip-buffers and kills streaming. See §10b.
910
+ 16. [ ] Move build output paths from RR7's `build/` to vite's `dist/` in
911
+ `wrangler.toml` (`assets` → `./dist/client/`) and cleanup scripts. See §10d.
912
+ 17. [ ] Fix deploy to use the built config `dist/<env>/wrangler.json`
913
+ (`no_bundle: true`), not a root `wrangler deploy` against the source
914
+ worker entry (which can't bundle Rango's virtual modules). See §10e.