@llui/router 0.0.1 → 0.0.2
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 +53 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,13 +1,63 @@
|
|
|
1
1
|
# @llui/router
|
|
2
2
|
|
|
3
|
-
Router for [LLui](https://github.com/fponticelli/llui).
|
|
4
|
-
|
|
5
|
-
Structured path matching, history/hash mode, `routing.link()` helper, `routing.listener()` for popstate, and `createHandler()` for mergeHandlers integration.
|
|
3
|
+
Router for [LLui](https://github.com/fponticelli/llui). Structured path matching with history and hash mode support.
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
6
|
pnpm add @llui/router
|
|
9
7
|
```
|
|
10
8
|
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { route, param, rest, createRouter, connectRouter } from '@llui/router'
|
|
13
|
+
import { div, a } from '@llui/dom'
|
|
14
|
+
|
|
15
|
+
// Define routes
|
|
16
|
+
const home = route([])
|
|
17
|
+
const search = route(['search'], (b) => b, ['q', 'page'])
|
|
18
|
+
const detail = route(['item', param('id')])
|
|
19
|
+
const docs = route(['docs', rest('path')])
|
|
20
|
+
|
|
21
|
+
// Create router
|
|
22
|
+
const router = createRouter(
|
|
23
|
+
{ home, search, detail, docs },
|
|
24
|
+
{ mode: 'history' },
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
// Connect to effects system
|
|
28
|
+
const routing = connectRouter(router)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
### Route Definition
|
|
34
|
+
|
|
35
|
+
| Function | Description |
|
|
36
|
+
| --------------------------------- | -------------------------------------------- |
|
|
37
|
+
| `route(segments, builder?, queryKeys?)` | Define a route with path segments and optional query keys |
|
|
38
|
+
| `param(name)` | Named path parameter (e.g. `/item/:id`) |
|
|
39
|
+
| `rest(name)` | Rest parameter capturing remaining path |
|
|
40
|
+
|
|
41
|
+
### Router
|
|
42
|
+
|
|
43
|
+
| Function | Description |
|
|
44
|
+
| --------------------------------- | -------------------------------------------- |
|
|
45
|
+
| `createRouter(routes, config)` | Create router instance (`history` or `hash` mode) |
|
|
46
|
+
| `connectRouter(router)` | Connect router to LLui effects, returns routing helpers |
|
|
47
|
+
|
|
48
|
+
### Routing Helpers (from connectRouter)
|
|
49
|
+
|
|
50
|
+
| Method / Effect | Description |
|
|
51
|
+
| --------------------------------- | -------------------------------------------- |
|
|
52
|
+
| `.link(send, route, attrs, children)` | Render a navigation link with client-side routing |
|
|
53
|
+
| `.listener(send)` | Popstate listener -- call in `view()` to react to URL changes |
|
|
54
|
+
| `.handleEffect` | Effect handler plugin for navigate/push/replace effects |
|
|
55
|
+
| `.push(route)` | Push navigation effect |
|
|
56
|
+
| `.replace(route)` | Replace navigation effect |
|
|
57
|
+
| `.back()` | Navigate back effect |
|
|
58
|
+
| `.forward()` | Navigate forward effect |
|
|
59
|
+
| `.scroll()` | Scroll restoration effect |
|
|
60
|
+
|
|
11
61
|
## License
|
|
12
62
|
|
|
13
63
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llui/router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "vitest run"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@llui/dom": "^0.0.
|
|
24
|
+
"@llui/dom": "^0.0.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@llui/dom": "workspace:*",
|