@intent-framework/router 0.1.0-alpha.2 → 0.1.0-alpha.5

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 (2) hide show
  1. package/README.md +51 -25
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -5,55 +5,81 @@ Typed route definitions and navigation for Intent.
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- pnpm add @intent-framework/core@0.1.0-alpha.1 @intent-framework/router@0.1.0-alpha.1
8
+ pnpm add @intent-framework/core @intent-framework/router
9
9
  ```
10
10
 
11
11
  ```sh
12
- npm install @intent-framework/core@0.1.0-alpha.1 @intent-framework/router@0.1.0-alpha.1
12
+ npm install @intent-framework/core @intent-framework/router
13
13
  ```
14
14
 
15
- ## What it provides
15
+ ## Quick reference
16
16
 
17
- - `createRouter()` — typed, immutable route builder
18
- - `.route(name, path, screen)` — register a route with typed params
19
- - `.match(pathname)` — match a pathname to a route + screen
20
- - `.path(name, params)` — generate a typed path string
21
- - `RouterServices` — typed navigation service for screens and actions
22
- - `renderRouter()` integration lives in `@intent-framework/dom`
23
-
24
- ## Minimal example
17
+ ### `createRouter()`
25
18
 
26
19
  ```ts
27
20
  import { createRouter } from "@intent-framework/router"
28
21
 
29
- type AppServices = {
30
- navigate: (name: string) => void
31
- }
32
-
33
- const router = createRouter<AppServices>()
22
+ const router = createRouter()
34
23
  .route("home", "/", HomeScreen)
35
- .route("team", "/team/:teamId", TeamScreen)
36
- .route("invite", "/team/:teamId/invite", InviteScreen)
24
+ .route("team", "/teams/:teamId", TeamScreen)
25
+ ```
26
+
27
+ | Method | Description |
28
+ |--------|-------------|
29
+ | `.route(name, path, screen)` | Register a route with typed params |
30
+ | `.match(pathname)` | Match a pathname → `{ found, name, params, screen }` |
31
+ | `.path(name, params?)` | Generate a typed path string |
32
+ | `.routes()` | List all registered route definitions |
33
+
34
+ ### Typed navigation
35
+
36
+ ```ts
37
+ import type { RouterServices, RoutesFromPaths, RouterNavigate, RouteContext } from "@intent-framework/router"
38
+
39
+ const appPaths = { home: "/", team: "/teams/:teamId" } as const
40
+ type AppRoutes = RoutesFromPaths<typeof appPaths>
37
41
 
38
- const match = router.match("/team/abc123")
39
- if (match.found) {
40
- console.log(match.name, match.params) // "team", { teamId: "abc123" }
41
- }
42
+ // Typed navigate function
43
+ type Navigate = RouterNavigate<AppRoutes>
44
+ // (name: "home") => void
45
+ // (name: "team", params: { teamId: string }) => void
42
46
 
43
- const path = router.path("team", { teamId: "abc123" })
44
- console.log(path) // "/team/abc123"
47
+ // Full services with navigate + extras
48
+ type AppServices = RouterServices<AppRoutes, {
49
+ route: RouteContext<AppRoutes>
50
+ analytics: { track(event: string): void }
51
+ }>
45
52
  ```
46
53
 
54
+ ### DOM rendering
55
+
56
+ ```ts
57
+ import { renderRouter } from "@intent-framework/dom"
58
+
59
+ renderRouter(router, {
60
+ target: document.getElementById("root")!,
61
+ notFound: NotFoundScreen,
62
+ services: { /* custom services */ },
63
+ })
64
+ ```
65
+
66
+ `renderRouter()` injects `navigate` (and `route` when matched) into screen services, listens for `popstate` to handle back/forward, and cleans up on `dispose()`.
67
+
68
+ ## Guide
69
+
70
+ See [docs/Router.md](../../docs/Router.md) for the full router guide covering typed navigation, route params, services, popstate behavior, renderRouter options, and current non-goals.
71
+
47
72
  ## Where this fits
48
73
 
49
74
  Router provides typed route definitions and navigation for Intent screens. Use `@intent-framework/dom`'s `renderRouter()` to materialize navigation into the DOM. The router does not own the product model — it maps paths to screens.
50
75
 
51
76
  ## Learn more
52
77
 
78
+ - [Router guide](../../docs/Router.md) — comprehensive guide
53
79
  - [Root README](../../README.md) — project overview and philosophy
54
80
  - [MVP Checkpoint](../../docs/MVP-Checkpoint.md) — current implementation boundaries
55
81
  - [Web basic example](../../examples/web-basic) — full demo with routing, resources, and diagnostics
56
82
 
57
83
  ## Status
58
84
 
59
- Experimental alpha. Version `0.1.0-alpha.1`. APIs may change. Not recommended for production use.
85
+ Experimental alpha. APIs may change. Not recommended for production use.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.0-alpha.2",
6
+ "version": "0.1.0-alpha.5",
7
7
  "description": "Typed route definitions and navigation for Intent",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@intent-framework/core": "0.1.0-alpha.2"
29
+ "@intent-framework/core": "^0.1.0-alpha.5"
30
30
  },
31
31
  "devDependencies": {
32
32
  "tsdown": "^0.3.0",