@rangojs/router 0.0.0-experimental.002d056c

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 (305) hide show
  1. package/AGENTS.md +9 -0
  2. package/README.md +899 -0
  3. package/dist/bin/rango.js +1606 -0
  4. package/dist/vite/index.js +5153 -0
  5. package/package.json +177 -0
  6. package/skills/breadcrumbs/SKILL.md +250 -0
  7. package/skills/cache-guide/SKILL.md +262 -0
  8. package/skills/caching/SKILL.md +253 -0
  9. package/skills/composability/SKILL.md +172 -0
  10. package/skills/debug-manifest/SKILL.md +112 -0
  11. package/skills/document-cache/SKILL.md +182 -0
  12. package/skills/fonts/SKILL.md +167 -0
  13. package/skills/hooks/SKILL.md +704 -0
  14. package/skills/host-router/SKILL.md +218 -0
  15. package/skills/intercept/SKILL.md +313 -0
  16. package/skills/layout/SKILL.md +310 -0
  17. package/skills/links/SKILL.md +239 -0
  18. package/skills/loader/SKILL.md +596 -0
  19. package/skills/middleware/SKILL.md +339 -0
  20. package/skills/mime-routes/SKILL.md +128 -0
  21. package/skills/parallel/SKILL.md +305 -0
  22. package/skills/prerender/SKILL.md +643 -0
  23. package/skills/rango/SKILL.md +118 -0
  24. package/skills/response-routes/SKILL.md +411 -0
  25. package/skills/route/SKILL.md +385 -0
  26. package/skills/router-setup/SKILL.md +439 -0
  27. package/skills/tailwind/SKILL.md +129 -0
  28. package/skills/theme/SKILL.md +79 -0
  29. package/skills/typesafety/SKILL.md +623 -0
  30. package/skills/use-cache/SKILL.md +324 -0
  31. package/src/__internal.ts +273 -0
  32. package/src/bin/rango.ts +321 -0
  33. package/src/browser/action-coordinator.ts +97 -0
  34. package/src/browser/action-response-classifier.ts +99 -0
  35. package/src/browser/event-controller.ts +899 -0
  36. package/src/browser/history-state.ts +80 -0
  37. package/src/browser/index.ts +18 -0
  38. package/src/browser/intercept-utils.ts +52 -0
  39. package/src/browser/link-interceptor.ts +141 -0
  40. package/src/browser/logging.ts +55 -0
  41. package/src/browser/merge-segment-loaders.ts +134 -0
  42. package/src/browser/navigation-bridge.ts +638 -0
  43. package/src/browser/navigation-client.ts +261 -0
  44. package/src/browser/navigation-store.ts +806 -0
  45. package/src/browser/navigation-transaction.ts +297 -0
  46. package/src/browser/network-error-handler.ts +61 -0
  47. package/src/browser/partial-update.ts +582 -0
  48. package/src/browser/prefetch/cache.ts +206 -0
  49. package/src/browser/prefetch/fetch.ts +145 -0
  50. package/src/browser/prefetch/observer.ts +65 -0
  51. package/src/browser/prefetch/policy.ts +48 -0
  52. package/src/browser/prefetch/queue.ts +128 -0
  53. package/src/browser/rango-state.ts +112 -0
  54. package/src/browser/react/Link.tsx +368 -0
  55. package/src/browser/react/NavigationProvider.tsx +413 -0
  56. package/src/browser/react/ScrollRestoration.tsx +94 -0
  57. package/src/browser/react/context.ts +59 -0
  58. package/src/browser/react/filter-segment-order.ts +11 -0
  59. package/src/browser/react/index.ts +52 -0
  60. package/src/browser/react/location-state-shared.ts +162 -0
  61. package/src/browser/react/location-state.ts +107 -0
  62. package/src/browser/react/mount-context.ts +37 -0
  63. package/src/browser/react/nonce-context.ts +23 -0
  64. package/src/browser/react/shallow-equal.ts +27 -0
  65. package/src/browser/react/use-action.ts +218 -0
  66. package/src/browser/react/use-client-cache.ts +58 -0
  67. package/src/browser/react/use-handle.ts +162 -0
  68. package/src/browser/react/use-href.tsx +40 -0
  69. package/src/browser/react/use-link-status.ts +135 -0
  70. package/src/browser/react/use-mount.ts +31 -0
  71. package/src/browser/react/use-navigation.ts +99 -0
  72. package/src/browser/react/use-params.ts +65 -0
  73. package/src/browser/react/use-pathname.ts +47 -0
  74. package/src/browser/react/use-router.ts +63 -0
  75. package/src/browser/react/use-search-params.ts +56 -0
  76. package/src/browser/react/use-segments.ts +171 -0
  77. package/src/browser/response-adapter.ts +73 -0
  78. package/src/browser/rsc-router.tsx +464 -0
  79. package/src/browser/scroll-restoration.ts +397 -0
  80. package/src/browser/segment-reconciler.ts +216 -0
  81. package/src/browser/segment-structure-assert.ts +83 -0
  82. package/src/browser/server-action-bridge.ts +667 -0
  83. package/src/browser/shallow.ts +40 -0
  84. package/src/browser/types.ts +547 -0
  85. package/src/browser/validate-redirect-origin.ts +29 -0
  86. package/src/build/generate-manifest.ts +438 -0
  87. package/src/build/generate-route-types.ts +36 -0
  88. package/src/build/index.ts +35 -0
  89. package/src/build/route-trie.ts +265 -0
  90. package/src/build/route-types/ast-helpers.ts +25 -0
  91. package/src/build/route-types/ast-route-extraction.ts +98 -0
  92. package/src/build/route-types/codegen.ts +102 -0
  93. package/src/build/route-types/include-resolution.ts +411 -0
  94. package/src/build/route-types/param-extraction.ts +48 -0
  95. package/src/build/route-types/per-module-writer.ts +128 -0
  96. package/src/build/route-types/router-processing.ts +479 -0
  97. package/src/build/route-types/scan-filter.ts +78 -0
  98. package/src/build/runtime-discovery.ts +231 -0
  99. package/src/cache/background-task.ts +34 -0
  100. package/src/cache/cache-key-utils.ts +44 -0
  101. package/src/cache/cache-policy.ts +125 -0
  102. package/src/cache/cache-runtime.ts +338 -0
  103. package/src/cache/cache-scope.ts +382 -0
  104. package/src/cache/cf/cf-cache-store.ts +982 -0
  105. package/src/cache/cf/index.ts +29 -0
  106. package/src/cache/document-cache.ts +369 -0
  107. package/src/cache/handle-capture.ts +81 -0
  108. package/src/cache/handle-snapshot.ts +41 -0
  109. package/src/cache/index.ts +44 -0
  110. package/src/cache/memory-segment-store.ts +328 -0
  111. package/src/cache/profile-registry.ts +73 -0
  112. package/src/cache/read-through-swr.ts +134 -0
  113. package/src/cache/segment-codec.ts +256 -0
  114. package/src/cache/taint.ts +98 -0
  115. package/src/cache/types.ts +342 -0
  116. package/src/client.rsc.tsx +85 -0
  117. package/src/client.tsx +601 -0
  118. package/src/component-utils.ts +76 -0
  119. package/src/components/DefaultDocument.tsx +27 -0
  120. package/src/context-var.ts +86 -0
  121. package/src/debug.ts +243 -0
  122. package/src/default-error-boundary.tsx +88 -0
  123. package/src/deps/browser.ts +8 -0
  124. package/src/deps/html-stream-client.ts +2 -0
  125. package/src/deps/html-stream-server.ts +2 -0
  126. package/src/deps/rsc.ts +10 -0
  127. package/src/deps/ssr.ts +2 -0
  128. package/src/errors.ts +365 -0
  129. package/src/handle.ts +135 -0
  130. package/src/handles/MetaTags.tsx +246 -0
  131. package/src/handles/breadcrumbs.ts +66 -0
  132. package/src/handles/index.ts +7 -0
  133. package/src/handles/meta.ts +264 -0
  134. package/src/host/cookie-handler.ts +165 -0
  135. package/src/host/errors.ts +97 -0
  136. package/src/host/index.ts +53 -0
  137. package/src/host/pattern-matcher.ts +214 -0
  138. package/src/host/router.ts +352 -0
  139. package/src/host/testing.ts +79 -0
  140. package/src/host/types.ts +146 -0
  141. package/src/host/utils.ts +25 -0
  142. package/src/href-client.ts +222 -0
  143. package/src/index.rsc.ts +233 -0
  144. package/src/index.ts +277 -0
  145. package/src/internal-debug.ts +11 -0
  146. package/src/loader.rsc.ts +89 -0
  147. package/src/loader.ts +64 -0
  148. package/src/network-error-thrower.tsx +23 -0
  149. package/src/outlet-context.ts +15 -0
  150. package/src/outlet-provider.tsx +45 -0
  151. package/src/prerender/param-hash.ts +37 -0
  152. package/src/prerender/store.ts +185 -0
  153. package/src/prerender.ts +463 -0
  154. package/src/reverse.ts +330 -0
  155. package/src/root-error-boundary.tsx +289 -0
  156. package/src/route-content-wrapper.tsx +196 -0
  157. package/src/route-definition/dsl-helpers.ts +934 -0
  158. package/src/route-definition/helper-factories.ts +200 -0
  159. package/src/route-definition/helpers-types.ts +430 -0
  160. package/src/route-definition/index.ts +52 -0
  161. package/src/route-definition/redirect.ts +93 -0
  162. package/src/route-definition.ts +1 -0
  163. package/src/route-map-builder.ts +281 -0
  164. package/src/route-name.ts +53 -0
  165. package/src/route-types.ts +259 -0
  166. package/src/router/content-negotiation.ts +116 -0
  167. package/src/router/debug-manifest.ts +72 -0
  168. package/src/router/error-handling.ts +287 -0
  169. package/src/router/find-match.ts +160 -0
  170. package/src/router/handler-context.ts +451 -0
  171. package/src/router/intercept-resolution.ts +397 -0
  172. package/src/router/lazy-includes.ts +236 -0
  173. package/src/router/loader-resolution.ts +420 -0
  174. package/src/router/logging.ts +251 -0
  175. package/src/router/manifest.ts +269 -0
  176. package/src/router/match-api.ts +620 -0
  177. package/src/router/match-context.ts +266 -0
  178. package/src/router/match-handlers.ts +440 -0
  179. package/src/router/match-middleware/background-revalidation.ts +223 -0
  180. package/src/router/match-middleware/cache-lookup.ts +634 -0
  181. package/src/router/match-middleware/cache-store.ts +295 -0
  182. package/src/router/match-middleware/index.ts +81 -0
  183. package/src/router/match-middleware/intercept-resolution.ts +306 -0
  184. package/src/router/match-middleware/segment-resolution.ts +193 -0
  185. package/src/router/match-pipelines.ts +179 -0
  186. package/src/router/match-result.ts +219 -0
  187. package/src/router/metrics.ts +282 -0
  188. package/src/router/middleware-cookies.ts +55 -0
  189. package/src/router/middleware-types.ts +222 -0
  190. package/src/router/middleware.ts +749 -0
  191. package/src/router/pattern-matching.ts +563 -0
  192. package/src/router/prerender-match.ts +402 -0
  193. package/src/router/preview-match.ts +170 -0
  194. package/src/router/revalidation.ts +289 -0
  195. package/src/router/router-context.ts +320 -0
  196. package/src/router/router-interfaces.ts +452 -0
  197. package/src/router/router-options.ts +592 -0
  198. package/src/router/router-registry.ts +24 -0
  199. package/src/router/segment-resolution/fresh.ts +570 -0
  200. package/src/router/segment-resolution/helpers.ts +263 -0
  201. package/src/router/segment-resolution/loader-cache.ts +198 -0
  202. package/src/router/segment-resolution/revalidation.ts +1242 -0
  203. package/src/router/segment-resolution/static-store.ts +67 -0
  204. package/src/router/segment-resolution.ts +21 -0
  205. package/src/router/segment-wrappers.ts +291 -0
  206. package/src/router/telemetry-otel.ts +299 -0
  207. package/src/router/telemetry.ts +300 -0
  208. package/src/router/timeout.ts +148 -0
  209. package/src/router/trie-matching.ts +239 -0
  210. package/src/router/types.ts +170 -0
  211. package/src/router.ts +1006 -0
  212. package/src/rsc/handler-context.ts +45 -0
  213. package/src/rsc/handler.ts +1089 -0
  214. package/src/rsc/helpers.ts +198 -0
  215. package/src/rsc/index.ts +36 -0
  216. package/src/rsc/loader-fetch.ts +209 -0
  217. package/src/rsc/manifest-init.ts +86 -0
  218. package/src/rsc/nonce.ts +32 -0
  219. package/src/rsc/origin-guard.ts +141 -0
  220. package/src/rsc/progressive-enhancement.ts +379 -0
  221. package/src/rsc/response-error.ts +37 -0
  222. package/src/rsc/response-route-handler.ts +347 -0
  223. package/src/rsc/rsc-rendering.ts +237 -0
  224. package/src/rsc/runtime-warnings.ts +42 -0
  225. package/src/rsc/server-action.ts +348 -0
  226. package/src/rsc/ssr-setup.ts +128 -0
  227. package/src/rsc/types.ts +263 -0
  228. package/src/search-params.ts +230 -0
  229. package/src/segment-system.tsx +454 -0
  230. package/src/server/context.ts +591 -0
  231. package/src/server/cookie-store.ts +190 -0
  232. package/src/server/fetchable-loader-store.ts +37 -0
  233. package/src/server/handle-store.ts +308 -0
  234. package/src/server/loader-registry.ts +133 -0
  235. package/src/server/request-context.ts +920 -0
  236. package/src/server/root-layout.tsx +10 -0
  237. package/src/server/tsconfig.json +14 -0
  238. package/src/server.ts +51 -0
  239. package/src/ssr/index.tsx +365 -0
  240. package/src/static-handler.ts +114 -0
  241. package/src/theme/ThemeProvider.tsx +297 -0
  242. package/src/theme/ThemeScript.tsx +61 -0
  243. package/src/theme/constants.ts +62 -0
  244. package/src/theme/index.ts +48 -0
  245. package/src/theme/theme-context.ts +44 -0
  246. package/src/theme/theme-script.ts +155 -0
  247. package/src/theme/types.ts +182 -0
  248. package/src/theme/use-theme.ts +44 -0
  249. package/src/types/boundaries.ts +158 -0
  250. package/src/types/cache-types.ts +198 -0
  251. package/src/types/error-types.ts +192 -0
  252. package/src/types/global-namespace.ts +100 -0
  253. package/src/types/handler-context.ts +687 -0
  254. package/src/types/index.ts +88 -0
  255. package/src/types/loader-types.ts +183 -0
  256. package/src/types/route-config.ts +170 -0
  257. package/src/types/route-entry.ts +109 -0
  258. package/src/types/segments.ts +148 -0
  259. package/src/types.ts +1 -0
  260. package/src/urls/include-helper.ts +197 -0
  261. package/src/urls/index.ts +53 -0
  262. package/src/urls/path-helper-types.ts +339 -0
  263. package/src/urls/path-helper.ts +329 -0
  264. package/src/urls/pattern-types.ts +95 -0
  265. package/src/urls/response-types.ts +106 -0
  266. package/src/urls/type-extraction.ts +372 -0
  267. package/src/urls/urls-function.ts +98 -0
  268. package/src/urls.ts +1 -0
  269. package/src/use-loader.tsx +354 -0
  270. package/src/vite/discovery/bundle-postprocess.ts +184 -0
  271. package/src/vite/discovery/discover-routers.ts +344 -0
  272. package/src/vite/discovery/prerender-collection.ts +385 -0
  273. package/src/vite/discovery/route-types-writer.ts +258 -0
  274. package/src/vite/discovery/self-gen-tracking.ts +47 -0
  275. package/src/vite/discovery/state.ts +108 -0
  276. package/src/vite/discovery/virtual-module-codegen.ts +203 -0
  277. package/src/vite/index.ts +16 -0
  278. package/src/vite/plugin-types.ts +48 -0
  279. package/src/vite/plugins/cjs-to-esm.ts +93 -0
  280. package/src/vite/plugins/client-ref-dedup.ts +115 -0
  281. package/src/vite/plugins/client-ref-hashing.ts +105 -0
  282. package/src/vite/plugins/expose-action-id.ts +363 -0
  283. package/src/vite/plugins/expose-id-utils.ts +287 -0
  284. package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
  285. package/src/vite/plugins/expose-ids/handler-transform.ts +179 -0
  286. package/src/vite/plugins/expose-ids/loader-transform.ts +74 -0
  287. package/src/vite/plugins/expose-ids/router-transform.ts +110 -0
  288. package/src/vite/plugins/expose-ids/types.ts +45 -0
  289. package/src/vite/plugins/expose-internal-ids.ts +569 -0
  290. package/src/vite/plugins/refresh-cmd.ts +65 -0
  291. package/src/vite/plugins/use-cache-transform.ts +323 -0
  292. package/src/vite/plugins/version-injector.ts +83 -0
  293. package/src/vite/plugins/version-plugin.ts +266 -0
  294. package/src/vite/plugins/version.d.ts +12 -0
  295. package/src/vite/plugins/virtual-entries.ts +123 -0
  296. package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
  297. package/src/vite/rango.ts +445 -0
  298. package/src/vite/router-discovery.ts +777 -0
  299. package/src/vite/utils/ast-handler-extract.ts +517 -0
  300. package/src/vite/utils/banner.ts +36 -0
  301. package/src/vite/utils/bundle-analysis.ts +137 -0
  302. package/src/vite/utils/manifest-utils.ts +70 -0
  303. package/src/vite/utils/package-resolution.ts +121 -0
  304. package/src/vite/utils/prerender-utils.ts +189 -0
  305. package/src/vite/utils/shared-utils.ts +169 -0
package/README.md ADDED
@@ -0,0 +1,899 @@
1
+ # @rangojs/router
2
+
3
+ Named-route RSC router with structural composability and type-safe partial rendering for Vite.
4
+
5
+ > **Experimental:** This package is under active development. APIs may change between releases. Install with `@experimental` tag.
6
+
7
+ ## Features
8
+
9
+ - **Named routes** — `reverse("blogPost", { slug })` for type-safe URL generation (Django-style)
10
+ - **Structural composability** — Attach routes, loaders, middleware, handles, caching, prerendering, and static generation without hiding the route tree
11
+ - **Composable URL patterns** — Django-style `urls()` DSL with `path`, `layout`, `include`
12
+ - **Data loaders** — `createLoader()` with automatic streaming and Suspense integration
13
+ - **Live data layer** — Pre-render or cache the UI shell while loaders stay live by default at request time
14
+ - **Layouts & nesting** — Nested layouts with `<Outlet />` and parallel routes
15
+ - **Segment-level caching** — `cache()` DSL with TTL/SWR and pluggable cache stores
16
+ - **Middleware** — Route-level middleware with cookie and header access
17
+ - **Pre-rendering** — `Prerender()` and `Static()` handlers for build-time rendering
18
+ - **Theme support** — Light/dark mode with FOUC prevention and system detection
19
+ - **Host routing** — Multi-app routing by domain/subdomain via `@rangojs/router/host`
20
+ - **Response routes** — `path.json()`, `path.text()`, `path.xml()` for API endpoints
21
+ - **Trailing slash control** — Per-route canonical URLs with `"never"`, `"always"`, or `"ignore"`
22
+ - **CLI codegen** — `rango generate` for route type generation
23
+
24
+ ## Design Docs
25
+
26
+ - [Execution model](./docs/internal/execution-model.md)
27
+ - [Semantic change checklist](./docs/internal/semantic-change-checklist.md)
28
+ - [Stability roadmap](./docs/internal/stability-roadmap.md)
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install @rangojs/router@experimental
34
+ ```
35
+
36
+ Peer dependencies:
37
+
38
+ ```bash
39
+ npm install react @vitejs/plugin-rsc
40
+ ```
41
+
42
+ For Cloudflare Workers:
43
+
44
+ ```bash
45
+ npm install @cloudflare/vite-plugin
46
+ ```
47
+
48
+ ## Import Paths
49
+
50
+ Use these import paths consistently:
51
+
52
+ - `@rangojs/router` — server/RSC router APIs, route DSL, `createRouter`, `urls`, `redirect`, `Prerender`, `Static`, shared types
53
+ - `@rangojs/router/client` — hooks and components such as `Link`, `Outlet`, `href`, `useNavigation`, `useLoader`, `useAction`, `useLocationState`
54
+ - `@rangojs/router/cache` — public cache APIs such as `CFCacheStore`, `MemorySegmentCacheStore`, `createDocumentCacheMiddleware`
55
+ - `@rangojs/router/host`, `@rangojs/router/theme`, `@rangojs/router/vite` — specialized public subpaths
56
+ - `@rangojs/router/rsc`, `@rangojs/router/ssr` — advanced server-only integration subpaths for custom request/HTML pipelines
57
+
58
+ Use only subpaths that are explicitly exported from the package. Avoid deep imports such as `@rangojs/router/cache/cf`.
59
+
60
+ `@rangojs/router` is conditionally resolved. Server-only root APIs such as
61
+ `createRouter()`, `urls()`, `redirect()`, `Prerender()`, and `cookies()` rely on
62
+ the `react-server` export condition and are meant to run in router definitions,
63
+ handlers, and other RSC/server modules. Outside that environment the root entry
64
+ falls back to stub implementations that throw guidance errors.
65
+
66
+ If you hit a root-entrypoint stub error:
67
+
68
+ - hooks and components like `Link`, `Outlet`, `useLoader`, `useNavigation`, and `MetaTags` belong in `@rangojs/router/client`
69
+ - cache APIs like `CFCacheStore` and `createDocumentCacheMiddleware` belong in `@rangojs/router/cache`
70
+ - host-router APIs belong in `@rangojs/router/host`
71
+
72
+ ## Quick Start
73
+
74
+ ### Vite Config
75
+
76
+ ```ts
77
+ // vite.config.ts
78
+ import react from "@vitejs/plugin-react";
79
+ import { defineConfig } from "vite";
80
+ import { rango } from "@rangojs/router/vite";
81
+
82
+ export default defineConfig({
83
+ plugins: [react(), rango({ preset: "cloudflare" })],
84
+ });
85
+ ```
86
+
87
+ ### Router
88
+
89
+ This file is a server/RSC module and should import router construction APIs from
90
+ `@rangojs/router`.
91
+
92
+ ```tsx
93
+ // src/router.tsx
94
+ import { createRouter, urls } from "@rangojs/router";
95
+ import { Document } from "./document";
96
+
97
+ const blogPatterns = urls(({ path }) => [
98
+ path("/", BlogIndexPage, { name: "index" }),
99
+ path("/:slug", BlogPostPage, { name: "post" }),
100
+ ]);
101
+
102
+ const urlpatterns = urls(({ path, include }) => [
103
+ path("/", HomePage, { name: "home" }),
104
+ include("/blog", blogPatterns, { name: "blog" }),
105
+ ]);
106
+
107
+ export const router = createRouter({ document: Document }).routes(urlpatterns);
108
+
109
+ // Export typed reverse function for URL generation by route name
110
+ export const reverse = router.reverse;
111
+
112
+ // reverse("blog.post", { slug: "hello-world" }) -> "/blog/hello-world"
113
+ ```
114
+
115
+ ### Document
116
+
117
+ ```tsx
118
+ // src/document.tsx
119
+ "use client";
120
+
121
+ import type { ReactNode } from "react";
122
+ import { MetaTags } from "@rangojs/router/client";
123
+
124
+ export function Document({ children }: { children: ReactNode }) {
125
+ return (
126
+ <html lang="en">
127
+ <head>
128
+ <MetaTags />
129
+ </head>
130
+ <body>{children}</body>
131
+ </html>
132
+ );
133
+ }
134
+ ```
135
+
136
+ ## Defining Routes
137
+
138
+ Rango is a named-route router first.
139
+
140
+ Paths define where a route lives. Names define how the app refers to it.
141
+
142
+ It is also structurally composable.
143
+
144
+ As an app grows, routes can pull in external handlers, loaders, middleware, handles, cache policy, intercepts, prerendering, and static generation while keeping the route tree visible at the composition site.
145
+
146
+ ### Named Routes
147
+
148
+ ```tsx
149
+ import { urls } from "@rangojs/router";
150
+
151
+ const urlpatterns = urls(({ path }) => [
152
+ path("/", HomePage, { name: "home" }),
153
+ path("/product/:slug", ProductPage, { name: "product" }),
154
+ path("/search/:query?", SearchPage, { name: "search" }),
155
+ path("/files/*", FilesPage, { name: "files" }),
156
+ ]);
157
+ ```
158
+
159
+ Use `reverse()` as the default way to link to routes:
160
+
161
+ ```tsx
162
+ router.reverse("product", { slug: "widget" }); // "/product/widget"
163
+ router.reverse("search", undefined, { q: "rsc" }); // "/search?q=rsc"
164
+ ```
165
+
166
+ ### Composable URL Modules
167
+
168
+ Local route names compose cleanly with `include(..., { name })`:
169
+
170
+ ```tsx
171
+ import { urls } from "@rangojs/router";
172
+
173
+ export const blogPatterns = urls(({ path }) => [
174
+ path("/", BlogIndexPage, { name: "index" }),
175
+ path("/:slug", BlogPostPage, { name: "post" }),
176
+ ]);
177
+
178
+ export const urlpatterns = urls(({ path, include }) => [
179
+ path("/", HomePage, { name: "home" }),
180
+ include("/blog", blogPatterns, { name: "blog" }),
181
+ ]);
182
+
183
+ router.reverse("blog.index"); // "/blog"
184
+ router.reverse("blog.post", { slug: "hello-world" }); // "/blog/hello-world"
185
+ ```
186
+
187
+ This is the core composition model:
188
+
189
+ - Paths stay local to the module that defines them
190
+ - Names become stable references across the app
191
+ - `include()` scales those names without forcing raw path-string coupling
192
+
193
+ ### Structural Composability
194
+
195
+ Rango avoids the usual tradeoff between modularity and visibility.
196
+
197
+ You can extract route behavior into separate files or packages and still keep one readable route definition that shows the structure of the app.
198
+
199
+ ```tsx
200
+ import { urls } from "@rangojs/router";
201
+ import { ProductPage } from "./routes/product";
202
+ import { ProductLoader } from "./loaders/product";
203
+ import { productMiddleware } from "./middleware/product";
204
+ import { productRevalidate } from "./revalidation/product";
205
+
206
+ const shopPatterns = urls(({ path, loader, middleware, revalidate, cache }) => [
207
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
208
+ middleware(productMiddleware),
209
+ loader(ProductLoader),
210
+ revalidate(productRevalidate),
211
+ cache({ ttl: 300 }),
212
+ ]),
213
+ ]);
214
+ ```
215
+
216
+ The route tree stays explicit even when behavior is modular.
217
+
218
+ This applies to:
219
+
220
+ - external route modules mounted with `include()`
221
+ - imported loaders, middleware, and handles attached at the route site
222
+ - prerendering and static generation attached without turning the route tree opaque
223
+
224
+ ### Loaders As the Live Data Layer
225
+
226
+ Rango separates app structure from app data.
227
+
228
+ Routes, layouts, and pre-rendered segments can be static or cached, while
229
+ loaders stay live by default and re-resolve at request time.
230
+
231
+ This means you can pre-render or cache the shell of a page without freezing its
232
+ data.
233
+
234
+ - `cache()` caches route structure and rendered UI segments
235
+ - `Prerender()` skips loaders at build time
236
+ - `loader()` provides fresh request-time data
237
+ - individual loaders can opt into caching explicitly when needed
238
+
239
+ ```tsx
240
+ import { urls, Prerender } from "@rangojs/router";
241
+ import { ArticleLoader } from "./loaders/article";
242
+
243
+ const docsPatterns = urls(({ path, loader }) => [
244
+ path("/docs/:slug", Prerender(DocsArticle), { name: "docs.article" }, () => [
245
+ loader(ArticleLoader), // fresh by default
246
+ ]),
247
+ ]);
248
+ ```
249
+
250
+ Pre-render the page, keep the data live.
251
+
252
+ ### Typed Handlers
253
+
254
+ Route handlers receive a typed context with params, search params, and `reverse()`:
255
+
256
+ ```tsx
257
+ import type { Handler } from "@rangojs/router";
258
+
259
+ export const ProductPage: Handler<"product"> = (ctx) => {
260
+ const { slug } = ctx.params; // typed from pattern
261
+ const homeUrl = ctx.reverse("home"); // type-safe URL by route name
262
+ return <h1>Product: {slug}</h1>;
263
+ };
264
+ ```
265
+
266
+ ### Choosing a Handler Style
267
+
268
+ All handler typing styles are supported, but they solve different problems:
269
+
270
+ - `Handler<"product">` — default for named app routes
271
+ - `Handler<".post", ScopedRouteMap<"blog">>` — best for reusable included modules
272
+ - `Handler<"/blog/:slug">` — good for unnamed or local-only extracted handlers
273
+ - `Handler<{ slug: string }>` — escape hatch for advanced or decoupled cases
274
+
275
+ Example of a scoped local name inside a mounted module:
276
+
277
+ ```tsx
278
+ import type { Handler } from "@rangojs/router";
279
+ import type { ScopedRouteMap } from "@rangojs/router/__internal";
280
+
281
+ type BlogRoutes = ScopedRouteMap<"blog">;
282
+
283
+ export const BlogPostPage: Handler<".post", BlogRoutes> = (ctx) => {
284
+ return <a href={ctx.reverse(".index")}>Back to blog</a>;
285
+ };
286
+ ```
287
+
288
+ See [`../../docs/named-routes.md`](../../docs/named-routes.md) for the recommended mental model.
289
+
290
+ ### Search Params
291
+
292
+ Define a search schema on the route for type-safe search parameters:
293
+
294
+ ```tsx
295
+ const urlpatterns = urls(({ path }) => [
296
+ path("/search", SearchPage, {
297
+ name: "search",
298
+ search: { q: "string", page: "number?", sort: "string?" },
299
+ }),
300
+ ]);
301
+
302
+ // Handler receives typed search params via ctx.search
303
+ const SearchPage: Handler<"search"> = (ctx) => {
304
+ const { q, page, sort } = ctx.search;
305
+ // q: string, page: number | undefined, sort: string | undefined
306
+ };
307
+ ```
308
+
309
+ ### Trailing Slash Handling
310
+
311
+ Trailing slash behavior is a current `path()` feature.
312
+
313
+ Set it per route with `trailingSlash`:
314
+
315
+ ```tsx
316
+ const urlpatterns = urls(({ path }) => [
317
+ path("/about", AboutPage, {
318
+ name: "about",
319
+ trailingSlash: "never",
320
+ }),
321
+ path("/docs/", DocsPage, {
322
+ name: "docs",
323
+ trailingSlash: "always",
324
+ }),
325
+ path("/webhook", WebhookHandler, {
326
+ name: "webhook",
327
+ trailingSlash: "ignore",
328
+ }),
329
+ ]);
330
+ ```
331
+
332
+ Modes:
333
+
334
+ - `"never"` — canonical URL has no trailing slash, redirects `/about/` to `/about`
335
+ - `"always"` — canonical URL has a trailing slash, redirects `/docs` to `/docs/`
336
+ - `"ignore"` — matches both forms without redirect
337
+
338
+ Default behavior when `trailingSlash` is omitted:
339
+
340
+ - There is no separate global default mode
341
+ - If the pattern is defined without a trailing slash, the canonical URL is the no-slash form
342
+ - If the pattern is defined with a trailing slash, the canonical URL is the slash form
343
+ - The router redirects to the canonical form based on the pattern you defined
344
+
345
+ The recommended public API is the per-route `path(..., { trailingSlash })` option. Use `"ignore"` sparingly, especially on content pages, because `/x` and `/x/` are distinct URLs.
346
+
347
+ ### Response Routes
348
+
349
+ Define API endpoints that bypass the RSC pipeline:
350
+
351
+ ```tsx
352
+ const urlpatterns = urls(({ path }) => [
353
+ path.json("/api/health", () => ({ status: "ok" }), { name: "health" }),
354
+ path.text("/robots.txt", () => "User-agent: *\nAllow: /", { name: "robots" }),
355
+ path.xml("/feed.xml", () => "<rss>...</rss>", { name: "feed" }),
356
+ ]);
357
+ ```
358
+
359
+ Response types available: `path.json()`, `path.text()`, `path.html()`, `path.xml()`, `path.image()`, `path.stream()`, `path.any()`.
360
+
361
+ ## Layouts & Nesting
362
+
363
+ ### Layouts with Outlet
364
+
365
+ ```tsx
366
+ import { urls } from "@rangojs/router";
367
+
368
+ const urlpatterns = urls(({ path, layout }) => [
369
+ layout(<MainLayout />, () => [
370
+ path("/", HomePage, { name: "home" }),
371
+ path("/about", AboutPage, { name: "about" }),
372
+ ]),
373
+ ]);
374
+ ```
375
+
376
+ ```tsx
377
+ "use client";
378
+ import { Outlet } from "@rangojs/router/client";
379
+
380
+ function MainLayout() {
381
+ return (
382
+ <div>
383
+ <nav>...</nav>
384
+ <Outlet />
385
+ </div>
386
+ );
387
+ }
388
+ ```
389
+
390
+ ### Loading Skeletons
391
+
392
+ ```tsx
393
+ const urlpatterns = urls(({ path, loading }) => [
394
+ path("/product/:slug", ProductPage, { name: "product" }, () => [
395
+ loading(<ProductSkeleton />),
396
+ ]),
397
+ ]);
398
+ ```
399
+
400
+ ### Parallel Routes
401
+
402
+ ```tsx
403
+ const urlpatterns = urls(({ path, layout, parallel, loader, loading }) => [
404
+ layout(BlogLayout, () => [
405
+ parallel({ "@sidebar": BlogSidebarHandler }, () => [
406
+ loader(BlogSidebarLoader),
407
+ loading(<SidebarSkeleton />),
408
+ ]),
409
+ path("/blog", BlogIndexPage, { name: "blog" }),
410
+ path("/blog/:slug", BlogPostPage, { name: "blogPost" }),
411
+ ]),
412
+ ]);
413
+ ```
414
+
415
+ ## Data Loaders
416
+
417
+ ### Creating a Loader
418
+
419
+ ```tsx
420
+ import { createLoader } from "@rangojs/router";
421
+
422
+ export const BlogSidebarLoader = createLoader(async (ctx) => {
423
+ const posts = await db.getRecentPosts();
424
+ return { posts, loadedAt: new Date().toISOString() };
425
+ });
426
+ ```
427
+
428
+ ### Using in Server Components (Handlers)
429
+
430
+ ```tsx
431
+ import type { HandlerContext } from "@rangojs/router";
432
+ import { BlogSidebarLoader } from "./loaders/blog";
433
+
434
+ async function BlogSidebarHandler(ctx: HandlerContext) {
435
+ const { posts } = await ctx.use(BlogSidebarLoader);
436
+ return (
437
+ <ul>
438
+ {posts.map((p) => (
439
+ <li key={p.slug}>{p.title}</li>
440
+ ))}
441
+ </ul>
442
+ );
443
+ }
444
+ ```
445
+
446
+ ### Using in Client Components
447
+
448
+ ```tsx
449
+ "use client";
450
+ import { useLoader } from "@rangojs/router/client";
451
+ import { BlogSidebarLoader } from "./loaders/blog";
452
+
453
+ function BlogSidebar() {
454
+ const { data } = useLoader(BlogSidebarLoader);
455
+ return (
456
+ <ul>
457
+ {data.posts.map((p) => (
458
+ <li key={p.slug}>{p.title}</li>
459
+ ))}
460
+ </ul>
461
+ );
462
+ }
463
+ ```
464
+
465
+ ### Attaching Loaders to Routes
466
+
467
+ ```tsx
468
+ const urlpatterns = urls(({ path, loader }) => [
469
+ path("/blog", BlogIndexPage, { name: "blog" }, () => [
470
+ loader(BlogSidebarLoader),
471
+ ]),
472
+ ]);
473
+ ```
474
+
475
+ ## Navigation & Links
476
+
477
+ ### Named Routes with `reverse()` (Server Components)
478
+
479
+ In server components, use `reverse()` to generate URLs by route name:
480
+
481
+ ```tsx
482
+ import { Link } from "@rangojs/router/client";
483
+ import { reverse } from "./router";
484
+
485
+ function BlogIndex() {
486
+ return (
487
+ <nav>
488
+ <Link to={reverse("home")}>Home</Link>
489
+ <Link to={reverse("blogPost", { slug: "my-post" })}>My Post</Link>
490
+ <Link to={reverse("about")}>About</Link>
491
+ </nav>
492
+ );
493
+ }
494
+ ```
495
+
496
+ `reverse()` is type-safe — route names and required params are checked at compile time. Included routes use dotted names: `reverse("api.health")`.
497
+
498
+ Handlers also have `ctx.reverse()` directly on the context:
499
+
500
+ ```tsx
501
+ const BlogPostPage: Handler<"blogPost"> = (ctx) => {
502
+ const backUrl = ctx.reverse("blog");
503
+ return <Link to={backUrl}>Back to blog</Link>;
504
+ };
505
+ ```
506
+
507
+ ### `href()` for Path Validation (Client Components)
508
+
509
+ In client components, use `href()` for compile-time path validation:
510
+
511
+ ```tsx
512
+ "use client";
513
+ import { Link, href } from "@rangojs/router/client";
514
+
515
+ function Nav() {
516
+ return (
517
+ <nav>
518
+ <Link to={href("/")}>Home</Link>
519
+ <Link to={href("/blog")} prefetch="adaptive">
520
+ Blog
521
+ </Link>
522
+ <Link to={href("/about")}>About</Link>
523
+ </nav>
524
+ );
525
+ }
526
+ ```
527
+
528
+ `href()` validates that the path matches a registered route pattern at compile time (e.g. `/blog/my-post` matches `/blog/:slug`).
529
+
530
+ ### Navigation Hooks
531
+
532
+ ```tsx
533
+ "use client";
534
+ import { useNavigation, useRouter } from "@rangojs/router/client";
535
+
536
+ function SearchForm() {
537
+ const router = useRouter();
538
+ const nav = useNavigation();
539
+
540
+ function handleSubmit(query: string) {
541
+ router.push(`/search?q=${encodeURIComponent(query)}`);
542
+ }
543
+
544
+ return <form onSubmit={...}>{nav.state !== "idle" && <Spinner />}</form>;
545
+ }
546
+ ```
547
+
548
+ ### Scroll Restoration
549
+
550
+ ```tsx
551
+ "use client";
552
+ import { ScrollRestoration } from "@rangojs/router/client";
553
+
554
+ function Document({ children }) {
555
+ return (
556
+ <html>
557
+ <body>
558
+ {children}
559
+ <ScrollRestoration />
560
+ </body>
561
+ </html>
562
+ );
563
+ }
564
+ ```
565
+
566
+ ## Includes (Composable Modules)
567
+
568
+ Split URL patterns into composable modules with `include()`:
569
+
570
+ ```tsx
571
+ // src/api/urls.tsx
572
+ import { urls } from "@rangojs/router";
573
+
574
+ export const apiPatterns = urls(({ path }) => [
575
+ path.json("/health", () => ({ status: "ok" }), { name: "health" }),
576
+ path.json("/products", getProducts, { name: "products" }),
577
+ ]);
578
+
579
+ // src/urls.tsx
580
+ import { urls } from "@rangojs/router";
581
+ import { apiPatterns } from "./api/urls";
582
+
583
+ export const urlpatterns = urls(({ path, include }) => [
584
+ path("/", HomePage, { name: "home" }),
585
+ include("/api", apiPatterns, { name: "api" }),
586
+ // Mounts apiPatterns under /api: /api/health, /api/products
587
+ ]);
588
+ ```
589
+
590
+ Included route names are prefixed with the include name: `reverse("api.health")`, `reverse("api.products")`.
591
+
592
+ ### Include name scoping
593
+
594
+ The `name` option controls how child route names appear globally:
595
+
596
+ | Form | Child names | Generated types | Reverse resolution |
597
+ | ---------------------------------- | ------------------- | ---------------------- | -------------------------------------------------------------------- |
598
+ | `include("/x", p, { name: "ns" })` | `ns.child` | Exported as `ns.child` | `reverse("ns.child")` globally, `reverse(".child")` inside |
599
+ | `include("/x", p, { name: "" })` | `child` (flattened) | Exported as-is | `reverse("child")` globally, `reverse(".child")` inside (root-scope) |
600
+ | `include("/x", p)` | Private scope | Not exported | `reverse(".child")` inside only |
601
+
602
+ Without a `name`, included routes are local to the mounted module. They still match requests and render normally, but their names are hidden from the generated route map and cannot be reversed globally. Use `{ name: "" }` to merge children into the parent namespace without adding a prefix.
603
+
604
+ **`{ name: "" }` is flattening, not isolation.** Flattened routes behave as if defined inline at the include site — dot-local reverse (`.name`) can reach any sibling route at root scope, including routes from other `{ name: "" }` mounts. If you need module-level isolation, omit the `name` option or use a namespace.
605
+
606
+ ## Middleware
607
+
608
+ ```tsx
609
+ const urlpatterns = urls(({ path, middleware }) => [
610
+ middleware(
611
+ async (ctx, next) => {
612
+ const start = Date.now();
613
+ const response = await next();
614
+ console.log(
615
+ `${ctx.request.method} ${ctx.url.pathname} ${Date.now() - start}ms`,
616
+ );
617
+ return response;
618
+ },
619
+ () => [path("/dashboard", DashboardPage, { name: "dashboard" })],
620
+ ),
621
+ ]);
622
+ ```
623
+
624
+ ## Caching
625
+
626
+ ### Route-Level Caching
627
+
628
+ ```tsx
629
+ const urlpatterns = urls(({ path, cache }) => [
630
+ cache({ ttl: 60, swr: 300 }, () => [
631
+ path("/blog", BlogIndexPage, { name: "blog" }),
632
+ path("/blog/:slug", BlogPostPage, { name: "blogPost" }),
633
+ ]),
634
+ ]);
635
+ ```
636
+
637
+ ### Cache Store Configuration
638
+
639
+ ```tsx
640
+ import { createRouter } from "@rangojs/router";
641
+ import {
642
+ CFCacheStore,
643
+ createDocumentCacheMiddleware,
644
+ } from "@rangojs/router/cache";
645
+
646
+ export const router = createRouter({
647
+ document: Document,
648
+ cache: (env) => ({
649
+ store: new CFCacheStore({
650
+ defaults: { ttl: 60, swr: 300 },
651
+ ctx: env.ctx,
652
+ }),
653
+ }),
654
+ })
655
+ .use(createDocumentCacheMiddleware())
656
+ .routes(urlpatterns);
657
+ ```
658
+
659
+ Available cache stores:
660
+
661
+ - `CFCacheStore` — Cloudflare edge cache (production)
662
+ - `MemorySegmentCacheStore` — In-memory cache (development/testing)
663
+
664
+ ## Pre-rendering
665
+
666
+ Pre-rendering generates route segments at build time. The worker handles all requests — there are no static files served from assets.
667
+
668
+ ### Static Segments
669
+
670
+ Use `Static()` for segments rendered once at build time (no params). Works on `path()`, `layout()`, and `parallel()`:
671
+
672
+ ```tsx
673
+ import { Static } from "@rangojs/router";
674
+
675
+ export const AboutPage = Static(async () => {
676
+ return <article>...</article>;
677
+ });
678
+
679
+ export const DocsNav = Static(async () => {
680
+ const items = await readDocsNavItems();
681
+ return (
682
+ <nav>
683
+ {items.map((i) => (
684
+ <a key={i.slug} href={i.slug}>
685
+ {i.title}
686
+ </a>
687
+ ))}
688
+ </nav>
689
+ );
690
+ });
691
+ ```
692
+
693
+ ### Dynamic Routes with Prerender
694
+
695
+ Use `Prerender()` for route-scoped pre-rendering. With params, provide `getParams` first, handler second:
696
+
697
+ ```tsx
698
+ import { Prerender } from "@rangojs/router";
699
+
700
+ export const BlogPost = Prerender(
701
+ async () => {
702
+ const slugs = await getAllBlogSlugs();
703
+ return slugs.map((slug) => ({ slug }));
704
+ },
705
+ async (ctx) => {
706
+ const post = await getPost(ctx.params.slug);
707
+ return <article>{post.content}</article>;
708
+ },
709
+ );
710
+ ```
711
+
712
+ ### Passthrough for Unknown Params
713
+
714
+ ```tsx
715
+ import { Prerender } from "@rangojs/router";
716
+
717
+ export const ProductPage = Prerender(
718
+ async () => {
719
+ const featured = await db.getFeaturedProducts();
720
+ return featured.map((p) => ({ id: p.id }));
721
+ },
722
+ async (ctx) => {
723
+ const product = await db.getProduct(ctx.params.id);
724
+ return <Product data={product} />;
725
+ },
726
+ { passthrough: true },
727
+ );
728
+ ```
729
+
730
+ With `passthrough: true`, known params are served from the build-time cache and unknown params fall through to live rendering.
731
+
732
+ Handlers can also skip individual param sets with `ctx.passthrough()`, deferring them to the live handler at runtime:
733
+
734
+ ```tsx
735
+ export const ProductPage = Prerender(
736
+ async () => {
737
+ const all = await db.getAllProducts();
738
+ return all.map((p) => ({ id: p.id }));
739
+ },
740
+ async (ctx) => {
741
+ const product = await db.getProduct(ctx.params.id);
742
+ if (!product.published) return ctx.passthrough();
743
+ return <Product data={product} />;
744
+ },
745
+ { passthrough: true },
746
+ );
747
+ ```
748
+
749
+ ## Theme
750
+
751
+ ### Router Configuration
752
+
753
+ ```tsx
754
+ export const router = createRouter({
755
+ document: Document,
756
+ theme: {
757
+ defaultTheme: "light",
758
+ themes: ["light", "dark", "system"],
759
+ attribute: "class",
760
+ enableSystem: true,
761
+ },
762
+ }).routes(urlpatterns);
763
+ ```
764
+
765
+ ### Theme Toggle
766
+
767
+ ```tsx
768
+ "use client";
769
+ import { useTheme } from "@rangojs/router/theme";
770
+
771
+ function ThemeToggle() {
772
+ const { theme, setTheme, themes } = useTheme();
773
+ return (
774
+ <select value={theme} onChange={(e) => setTheme(e.target.value)}>
775
+ {themes.map((t) => (
776
+ <option key={t}>{t}</option>
777
+ ))}
778
+ </select>
779
+ );
780
+ }
781
+ ```
782
+
783
+ ## Host Routing
784
+
785
+ Route requests to different apps based on domain/subdomain patterns using `@rangojs/router/host`:
786
+
787
+ ```tsx
788
+ // worker.rsc.tsx
789
+ import { createHostRouter } from "@rangojs/router/host";
790
+
791
+ const hostRouter = createHostRouter();
792
+
793
+ hostRouter.host(["*.localhost"]).map(() => import("./apps/admin/handler.js"));
794
+ hostRouter.host(["localhost"]).map(() => import("./apps/site/handler.js"));
795
+ hostRouter.fallback().map(() => import("./apps/site/handler.js"));
796
+
797
+ export default {
798
+ async fetch(request, env, ctx) {
799
+ return hostRouter.match(request, { env, ctx });
800
+ },
801
+ };
802
+ ```
803
+
804
+ Each sub-app has its own `createRouter()` and `urls()`. The host router lazily imports the matched app's handler. Patterns are matched in registration order — register more specific patterns (subdomains) before catch-alls.
805
+
806
+ ## Meta Tags
807
+
808
+ Accumulate meta tags across route segments using the built-in `Meta` handle:
809
+
810
+ ```tsx
811
+ import { Meta } from "@rangojs/router";
812
+ import type { HandlerContext } from "@rangojs/router";
813
+
814
+ export function BlogPostPage(ctx: HandlerContext) {
815
+ const meta = ctx.use(Meta);
816
+ meta({ title: "My Blog Post" });
817
+ meta({ name: "description", content: "A great blog post" });
818
+ meta({ property: "og:title", content: "My Blog Post" });
819
+
820
+ return <article>...</article>;
821
+ }
822
+ ```
823
+
824
+ Render collected tags in the document with `<MetaTags />` from `@rangojs/router/client`.
825
+
826
+ ## CLI: `rango generate`
827
+
828
+ Route types are generated automatically by the Vite plugin. The CLI is a manual fallback for generating types outside the dev server (e.g. in CI or for IDE support before first `pnpm dev`):
829
+
830
+ ```bash
831
+ npx rango generate src/router.tsx
832
+ npx rango generate src/ # recursive scan
833
+ npx rango generate src/urls.tsx src/api/ # mix files and directories
834
+ ```
835
+
836
+ Auto-detects file type:
837
+
838
+ - Files with `createRouter` → `*.named-routes.gen.ts` with global route map
839
+ - Files with `urls()` → `*.gen.ts` with per-module route names, params, and search types
840
+
841
+ ## Type Safety
842
+
843
+ The Vite plugin automatically generates a `router.named-routes.gen.ts` file that globally registers route names, patterns, and search schemas via `RSCRouter.GeneratedRouteMap`. This powers server-side named-route typing such as `Handler<"name">`, `ctx.reverse()`, `getRequestContext().reverse()`, and `RouteParams<"name">` without any manual route registration. The gen file is updated on dev server startup, HMR, and production builds.
844
+
845
+ Use the generated map by default. Augment `RSCRouter.RegisteredRoutes` only when you need the richer `typeof router.routeMap` shape globally, especially for response-aware and path-based utilities.
846
+
847
+ ```typescript
848
+ // router.tsx
849
+ const router = createRouter<AppBindings>({}).routes(urlpatterns);
850
+
851
+ declare global {
852
+ namespace RSCRouter {
853
+ interface Env extends AppEnv {}
854
+ interface Vars extends AppVars {}
855
+ interface RegisteredRoutes extends typeof router.routeMap {}
856
+ }
857
+ }
858
+ ```
859
+
860
+ Quick rule of thumb:
861
+
862
+ - `GeneratedRouteMap` (auto-generated) — use for server-side named-route typing: `Handler<"name">`, `ctx.reverse()`, `Prerender<"name">`
863
+ - `typeof router.routeMap` — use when you need route entries with response metadata
864
+ - `RegisteredRoutes` (manual augmentation) — use to expose `typeof router.routeMap` globally for `href()`, `PathResponse`, `ValidPaths`, and other path/response-aware utilities
865
+
866
+ For extracted reusable loaders or middleware, prefer global dotted names on
867
+ `ctx.reverse()` by default. If you want type-safe local names for a specific
868
+ module, use `scopedReverse<typeof localPatterns>(ctx.reverse)` or
869
+ `scopedReverse<routes>(ctx.reverse)` with a generated local route type.
870
+
871
+ ## Subpath Exports
872
+
873
+ | Export | Description |
874
+ | ------------------------ | -------------------------------------------------------------------------------------------------------- |
875
+ | `@rangojs/router` | Server/RSC core and shared types: `createRouter`, `urls`, `createLoader`, `Handler`, `Prerender`, `Meta` |
876
+ | `@rangojs/router/client` | Client: `Link`, `Outlet`, `href`, `useNavigation`, `useLoader`, `MetaTags` |
877
+ | `@rangojs/router/cache` | Cache: `CFCacheStore`, `MemorySegmentCacheStore`, `createDocumentCacheMiddleware` |
878
+ | `@rangojs/router/theme` | Theme: `useTheme`, `ThemeProvider`, `ThemeScript` |
879
+ | `@rangojs/router/host` | Host routing: `createHostRouter`, `defineHosts` |
880
+ | `@rangojs/router/vite` | Vite plugin: `rango()` |
881
+ | `@rangojs/router/rsc` | Advanced server pipeline APIs: `createRSCHandler`, request-context access |
882
+ | `@rangojs/router/ssr` | Advanced SSR bridge APIs: `createSSRHandler` |
883
+ | `@rangojs/router/server` | Internal build/runtime utilities for advanced integrations |
884
+ | `@rangojs/router/build` | Build utilities |
885
+
886
+ The root entrypoint is not a generic client/runtime barrel. If you need hooks
887
+ or components, import from `@rangojs/router/client`; if you need cache or host
888
+ APIs, use their dedicated subpaths.
889
+
890
+ ## Examples
891
+
892
+ See the `examples/` directory for full working applications:
893
+
894
+ - [`cloudflare-basic`](../../examples/cloudflare-basic) — Cloudflare Workers with caching, loaders, theme, and pre-rendering
895
+ - [`cloudflare-multi-router`](../../examples/cloudflare-multi-router) — Multi-app host routing
896
+
897
+ ## License
898
+
899
+ MIT