@geometra/router 1.0.1 → 1.1.0

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 +44 -4
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Routing primitives for Geometra.
4
4
 
5
- Current scope (foundation): route matching and nested branch composition utilities.
5
+ The package now covers matching, history adapters, router lifecycle, loaders/actions, redirects, blockers, restoration policy, and a declarative `link` primitive.
6
6
 
7
7
  ## Install
8
8
 
@@ -40,8 +40,48 @@ npm install @geometra/router
40
40
  ## Usage
41
41
 
42
42
  ```ts
43
- import { matchPath } from '@geometra/router'
43
+ import { createMemoryHistory, createRouter, redirect } from '@geometra/router'
44
44
 
45
- const match = matchPath('/users/:id?', '/users/42')
46
- // { params: { id: '42' } }
45
+ const router = createRouter({
46
+ history: createMemoryHistory({ initialEntries: ['/'] }),
47
+ routes: [
48
+ {
49
+ id: 'home',
50
+ path: '/',
51
+ loader: async () => ({ ok: true }),
52
+ },
53
+ {
54
+ id: 'users.show',
55
+ path: '/users/:id',
56
+ loader: async ({ params }) => ({ userId: params.id }),
57
+ action: async ({ submission }) => {
58
+ return { saved: true, payload: submission.data }
59
+ },
60
+ },
61
+ {
62
+ id: 'legacy',
63
+ path: '/old-home',
64
+ loader: async () => redirect('/'),
65
+ },
66
+ ],
67
+ })
68
+
69
+ router.start()
70
+ await router.navigate('/users/42')
71
+
72
+ router.getState().location.pathname
73
+ router.getState().loaderData['users.show']
74
+ await router.submitAction('users.show', { method: 'POST', data: { theme: 'dark' } })
47
75
  ```
76
+
77
+ ## Notes
78
+
79
+ - The router is renderer-agnostic. It manages navigation state and data flow; rendering matched content is still your app’s job.
80
+ - `loader` and `action` contexts include route params, parsed query, optional request context, and an abort `signal`.
81
+ - `router.addBlocker()` is the escape hatch for unsaved-changes flows and transition confirmation.
82
+ - `router.isActive()` and `router.isPending()` are intended for link styling and transition-aware UI.
83
+
84
+ ## Links
85
+
86
+ - [Delivery report](https://github.com/razroo/geometra/blob/main/ROUTER_DELIVERY_REPORT.md)
87
+ - [RFC](https://github.com/razroo/geometra/blob/main/RFC_ROUTER.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geometra/router",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Routing primitives for Geometra",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,6 +34,6 @@
34
34
  "check": "tsc --noEmit"
35
35
  },
36
36
  "dependencies": {
37
- "@geometra/core": "^1.0.1"
37
+ "@geometra/core": "^1.1.0"
38
38
  }
39
39
  }