@rangojs/router 0.0.0-experimental.ede38110 → 0.0.0-experimental.f2d1a2f1
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.
- package/README.md +50 -20
- package/dist/vite/index.js +353 -49
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +5 -3
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/hooks/SKILL.md +28 -20
- package/skills/links/SKILL.md +88 -16
- package/skills/loader/SKILL.md +35 -2
- package/skills/migrate-react-router/SKILL.md +1 -0
- package/skills/response-routes/SKILL.md +8 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/typesafety/SKILL.md +3 -1
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/navigation-bridge.ts +51 -2
- package/src/browser/navigation-client.ts +33 -10
- package/src/browser/navigation-store.ts +25 -1
- package/src/browser/partial-update.ts +20 -1
- package/src/browser/prefetch/cache.ts +124 -26
- package/src/browser/prefetch/fetch.ts +114 -38
- package/src/browser/prefetch/queue.ts +36 -5
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +18 -13
- package/src/browser/react/NavigationProvider.tsx +50 -11
- package/src/browser/react/use-navigation.ts +30 -11
- package/src/browser/react/use-params.ts +11 -1
- package/src/browser/react/use-router.ts +8 -1
- package/src/browser/rsc-router.tsx +34 -6
- package/src/browser/types.ts +13 -0
- package/src/cache/cf/cf-cache-store.ts +5 -7
- package/src/index.rsc.ts +3 -0
- package/src/index.ts +3 -0
- package/src/outlet-context.ts +1 -1
- package/src/response-utils.ts +28 -0
- package/src/reverse.ts +3 -2
- package/src/route-definition/dsl-helpers.ts +16 -3
- package/src/route-definition/resolve-handler-use.ts +6 -0
- package/src/router/handler-context.ts +20 -3
- package/src/router/lazy-includes.ts +1 -1
- package/src/router/loader-resolution.ts +3 -0
- package/src/router/match-api.ts +3 -3
- package/src/router/middleware-types.ts +2 -22
- package/src/router/middleware.ts +32 -4
- package/src/router/pattern-matching.ts +60 -9
- package/src/router/trie-matching.ts +10 -4
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +1 -2
- package/src/rsc/handler.ts +8 -4
- package/src/rsc/helpers.ts +69 -41
- package/src/rsc/progressive-enhancement.ts +2 -0
- package/src/rsc/response-route-handler.ts +14 -1
- package/src/rsc/rsc-rendering.ts +7 -0
- package/src/rsc/server-action.ts +2 -0
- package/src/server/request-context.ts +10 -42
- package/src/types/handler-context.ts +2 -34
- package/src/types/loader-types.ts +5 -6
- package/src/types/request-scope.ts +126 -0
- package/src/urls/response-types.ts +2 -10
- package/src/vite/debug.ts +86 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/performance-tracks.ts +4 -6
- package/src/vite/rango.ts +49 -14
- package/src/vite/router-discovery.ts +161 -23
- package/src/vite/utils/banner.ts +1 -1
- package/src/vite/utils/package-resolution.ts +41 -1
package/README.md
CHANGED
|
@@ -161,13 +161,18 @@ const urlpatterns = urls(({ path }) => [
|
|
|
161
161
|
]);
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
Use `reverse()` as the default way to link to routes:
|
|
164
|
+
Use `ctx.reverse()` from handler context as the default way to link to routes from server code:
|
|
165
165
|
|
|
166
166
|
```tsx
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
const ProductPage: Handler<"product"> = (ctx) => {
|
|
168
|
+
const url = ctx.reverse("product", { slug: "widget" }); // "/product/widget"
|
|
169
|
+
const searchUrl = ctx.reverse("search", undefined, { q: "rsc" }); // "/search?q=rsc"
|
|
170
|
+
return <Link to={url}>Widget</Link>;
|
|
171
|
+
};
|
|
169
172
|
```
|
|
170
173
|
|
|
174
|
+
`router.reverse()` (exported from the router module) is the same function without a handler context, useful in scripts or tests. In request code, prefer `ctx.reverse()` — it auto-fills mount params from the current match.
|
|
175
|
+
|
|
171
176
|
### Composable URL Modules
|
|
172
177
|
|
|
173
178
|
Local route names compose cleanly with `include(..., { name })`:
|
|
@@ -479,39 +484,64 @@ const urlpatterns = urls(({ path, loader }) => [
|
|
|
479
484
|
|
|
480
485
|
## Navigation & Links
|
|
481
486
|
|
|
482
|
-
### Named Routes with `reverse()` (Server
|
|
487
|
+
### Named Routes with `ctx.reverse()` (Server)
|
|
483
488
|
|
|
484
|
-
In server components, use `reverse()` to generate URLs by route name:
|
|
489
|
+
In server components and handlers, use `ctx.reverse()` to generate URLs by route name. This is the default — it is typed, auto-fills mount params from the current match, and resolves both local (`.name`) and absolute (`name.sub`) names:
|
|
485
490
|
|
|
486
491
|
```tsx
|
|
487
492
|
import { Link } from "@rangojs/router/client";
|
|
493
|
+
import type { Handler } from "@rangojs/router";
|
|
494
|
+
|
|
495
|
+
const BlogPostPage: Handler<"blogPost"> = (ctx) => {
|
|
496
|
+
const backUrl = ctx.reverse("blog");
|
|
497
|
+
return <Link to={backUrl}>Back to blog</Link>;
|
|
498
|
+
};
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
`reverse()` is type-safe — route names and required params are checked at compile time. Included routes use dotted names: `ctx.reverse("api.health")`.
|
|
502
|
+
|
|
503
|
+
For scripts, tests, or other code without a handler context, import the router-level `reverse`:
|
|
504
|
+
|
|
505
|
+
```tsx
|
|
488
506
|
import { reverse } from "./router";
|
|
507
|
+
reverse("blogPost", { slug: "my-post" });
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Client Components
|
|
511
|
+
|
|
512
|
+
**`reverse()` is server-only.** It depends on the route manifest and handler context — neither is available in the browser bundle. Client components receive URLs as props, loader data, or server-action return values:
|
|
513
|
+
|
|
514
|
+
```tsx
|
|
515
|
+
// server
|
|
516
|
+
function BlogIndex(ctx: HandlerContext) {
|
|
517
|
+
return (
|
|
518
|
+
<Nav
|
|
519
|
+
home={ctx.reverse("home")}
|
|
520
|
+
post={ctx.reverse("blogPost", { slug: "my-post" })}
|
|
521
|
+
/>
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
```tsx
|
|
527
|
+
"use client";
|
|
528
|
+
import { Link } from "@rangojs/router/client";
|
|
489
529
|
|
|
490
|
-
function
|
|
530
|
+
export function Nav({ home, post }: { home: string; post: string }) {
|
|
491
531
|
return (
|
|
492
532
|
<nav>
|
|
493
|
-
<Link to={
|
|
494
|
-
<Link to={
|
|
495
|
-
<Link to={reverse("about")}>About</Link>
|
|
533
|
+
<Link to={home}>Home</Link>
|
|
534
|
+
<Link to={post}>My Post</Link>
|
|
496
535
|
</nav>
|
|
497
536
|
);
|
|
498
537
|
}
|
|
499
538
|
```
|
|
500
539
|
|
|
501
|
-
`
|
|
502
|
-
|
|
503
|
-
Handlers also have `ctx.reverse()` directly on the context:
|
|
504
|
-
|
|
505
|
-
```tsx
|
|
506
|
-
const BlogPostPage: Handler<"blogPost"> = (ctx) => {
|
|
507
|
-
const backUrl = ctx.reverse("blog");
|
|
508
|
-
return <Link to={backUrl}>Back to blog</Link>;
|
|
509
|
-
};
|
|
510
|
-
```
|
|
540
|
+
For client-side navigation to static paths (no named-route lookup), use `href()` — see below. For URLs tied to named routes, always generate on the server and pass the string in.
|
|
511
541
|
|
|
512
542
|
### `href()` for Path Validation (Client Components)
|
|
513
543
|
|
|
514
|
-
In client components, use `href()` for compile-time path validation:
|
|
544
|
+
In client components, use `href()` for compile-time path validation on static path strings:
|
|
515
545
|
|
|
516
546
|
```tsx
|
|
517
547
|
"use client";
|