kt.js 0.1.2 → 0.2.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 +29 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -69,14 +69,12 @@ h('div', { class: className }, 'Styled text');
69
69
 
70
70
  ## Router
71
71
 
72
- KT.js includes a lightweight client-side router:
72
+ KT.js includes a lightweight client-side router (hash-based):
73
73
 
74
74
  ```ts
75
75
  import { createRouter, div, h1 } from 'kt.js';
76
76
 
77
77
  const router = createRouter({
78
- mode: 'hash', // or 'history'
79
- container: document.getElementById('app'),
80
78
  routes: [
81
79
  {
82
80
  path: '/',
@@ -87,19 +85,41 @@ const router = createRouter({
87
85
  handler: (ctx) => div({}, [h1({}, `User ${ctx.params.id}`)]),
88
86
  },
89
87
  ],
88
+ container: document.getElementById('app'),
89
+ beforeEach: async (to, from) => {
90
+ // Navigation guard - return false to block navigation
91
+ console.log('navigating to:', to.path);
92
+ return true;
93
+ },
94
+ afterEach: (to) => {
95
+ // Called after successful navigation
96
+ document.title = to.path;
97
+ },
98
+ onError: (error) => {
99
+ console.error('Router error:', error);
100
+ },
90
101
  });
91
102
 
92
103
  router.start();
104
+
105
+ // Navigate programmatically
106
+ router.push('/user/123');
107
+ router.push('/user/456?page=2');
108
+
109
+ // Get current route
110
+ const current = router.current();
111
+ console.log(current?.path, current?.params, current?.query);
93
112
  ```
94
113
 
95
114
  **Features:**
96
115
 
97
- - Hash and History API routing
98
- - Dynamic route parameters
99
- - Query string parsing
100
- - Navigation guards
101
- - Lazy loading support
102
- - No dependencies
116
+ - Hash-based routing (`#/path`)
117
+ - Dynamic route parameters (`/user/:id`)
118
+ - Query string parsing (`?key=value`)
119
+ - Async navigation guards (`beforeEach`)
120
+ - Lifecycle hooks (`afterEach`)
121
+ - Error handling (`onError`)
122
+ - Minimal footprint
103
123
 
104
124
  ## Notes
105
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kt.js",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"