@intent-framework/router 0.1.0-alpha.0 → 0.1.0-alpha.10
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 +85 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @intent-framework/router
|
|
2
|
+
|
|
3
|
+
Typed route definitions and navigation for Intent.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @intent-framework/core @intent-framework/router
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @intent-framework/core @intent-framework/router
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick reference
|
|
16
|
+
|
|
17
|
+
### `createRouter()`
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createRouter } from "@intent-framework/router"
|
|
21
|
+
|
|
22
|
+
const router = createRouter()
|
|
23
|
+
.route("home", "/", HomeScreen)
|
|
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>
|
|
41
|
+
|
|
42
|
+
// Typed navigate function
|
|
43
|
+
type Navigate = RouterNavigate<AppRoutes>
|
|
44
|
+
// (name: "home") => void
|
|
45
|
+
// (name: "team", params: { teamId: string }) => void
|
|
46
|
+
|
|
47
|
+
// Full services with navigate + extras
|
|
48
|
+
type AppServices = RouterServices<AppRoutes, {
|
|
49
|
+
route: RouteContext<AppRoutes>
|
|
50
|
+
analytics: { track(event: string): void }
|
|
51
|
+
}>
|
|
52
|
+
```
|
|
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
|
+
|
|
72
|
+
## Where this fits
|
|
73
|
+
|
|
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.
|
|
75
|
+
|
|
76
|
+
## Learn more
|
|
77
|
+
|
|
78
|
+
- [Router guide](../../docs/Router.md) — comprehensive guide
|
|
79
|
+
- [Root README](../../README.md) — project overview and philosophy
|
|
80
|
+
- [MVP Checkpoint](../../docs/MVP-Checkpoint.md) — current implementation boundaries
|
|
81
|
+
- [Web basic example](../../examples/web-basic) — full demo with routing, resources, and diagnostics
|
|
82
|
+
|
|
83
|
+
## Status
|
|
84
|
+
|
|
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.
|
|
6
|
+
"version": "0.1.0-alpha.10",
|
|
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.
|
|
29
|
+
"@intent-framework/core": "^0.1.0-alpha.10"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"tsdown": "^0.3.0",
|