@flight-framework/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/LICENSE +21 -0
- package/README.md +137 -144
- package/package.json +47 -47
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Flight Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,144 +1,137 @@
|
|
|
1
|
-
# @flight-framework/router
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## License
|
|
143
|
-
|
|
144
|
-
MIT
|
|
1
|
+
# @flight-framework/router
|
|
2
|
+
|
|
3
|
+
Client-side routing primitives for Flight Framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @flight-framework/router
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### With React
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { RouterProvider, Link, useRouter } from '@flight-framework/router';
|
|
17
|
+
|
|
18
|
+
// Wrap your app
|
|
19
|
+
function App() {
|
|
20
|
+
return (
|
|
21
|
+
<RouterProvider initialPath={url}>
|
|
22
|
+
<Navigation />
|
|
23
|
+
<Content />
|
|
24
|
+
</RouterProvider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Use Link for navigation
|
|
29
|
+
function Navigation() {
|
|
30
|
+
return (
|
|
31
|
+
<nav>
|
|
32
|
+
<Link href="/">Home</Link>
|
|
33
|
+
<Link href="/docs" prefetch>Docs</Link>
|
|
34
|
+
<Link href="/about">About</Link>
|
|
35
|
+
</nav>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Use hooks to access router state
|
|
40
|
+
function Content() {
|
|
41
|
+
const { path, navigate } = useRouter();
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<main>
|
|
45
|
+
<p>Current path: {path}</p>
|
|
46
|
+
<button onClick={() => navigate('/dashboard')}>
|
|
47
|
+
Go to Dashboard
|
|
48
|
+
</button>
|
|
49
|
+
</main>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Hooks
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// Get current path and navigation functions
|
|
58
|
+
const { path, searchParams, navigate, back, forward } = useRouter();
|
|
59
|
+
|
|
60
|
+
// Get route parameters (from dynamic routes like [slug])
|
|
61
|
+
const { slug } = useParams<{ slug: string }>();
|
|
62
|
+
|
|
63
|
+
// Get and set search params
|
|
64
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
65
|
+
|
|
66
|
+
// Get current pathname
|
|
67
|
+
const pathname = usePathname();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Programmatic Navigation
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { navigate, prefetch } from '@flight-framework/router';
|
|
74
|
+
|
|
75
|
+
// Navigate to a path
|
|
76
|
+
navigate('/docs');
|
|
77
|
+
|
|
78
|
+
// Replace history instead of push
|
|
79
|
+
navigate('/login', { replace: true });
|
|
80
|
+
|
|
81
|
+
// Navigate without scrolling to top
|
|
82
|
+
navigate('/next-page', { scroll: false });
|
|
83
|
+
|
|
84
|
+
// Pass state data
|
|
85
|
+
navigate('/dashboard', { state: { from: '/login' } });
|
|
86
|
+
|
|
87
|
+
// Prefetch a route
|
|
88
|
+
prefetch('/heavy-page');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Route Matching
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { matchRoute, parseParams, generatePath } from '@flight-framework/router';
|
|
95
|
+
|
|
96
|
+
// Check if a path matches a pattern
|
|
97
|
+
const { matched, params } = matchRoute('/docs/routing', '/docs/:slug');
|
|
98
|
+
// matched: true, params: { slug: 'routing' }
|
|
99
|
+
|
|
100
|
+
// Parse params from a path
|
|
101
|
+
const params = parseParams('/blog/2024/my-post', '/blog/:year/:slug');
|
|
102
|
+
// { year: '2024', slug: 'my-post' }
|
|
103
|
+
|
|
104
|
+
// Generate a path from pattern and params
|
|
105
|
+
const path = generatePath('/docs/:slug', { slug: 'api-routes' });
|
|
106
|
+
// '/docs/api-routes'
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Link Props
|
|
110
|
+
|
|
111
|
+
| Prop | Type | Default | Description |
|
|
112
|
+
|------|------|---------|-------------|
|
|
113
|
+
| `href` | `string` | required | Target URL path |
|
|
114
|
+
| `prefetch` | `boolean` | `false` | Prefetch target on hover |
|
|
115
|
+
| `replace` | `boolean` | `false` | Replace history entry |
|
|
116
|
+
| `scroll` | `boolean` | `true` | Scroll to top on navigate |
|
|
117
|
+
| `target` | `string` | - | Link target (_blank, etc) |
|
|
118
|
+
| `className` | `string` | - | CSS class |
|
|
119
|
+
|
|
120
|
+
## SSR Support
|
|
121
|
+
|
|
122
|
+
The router is SSR-safe. Pass the initial path from your server:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
// entry-server.tsx
|
|
126
|
+
export function render(url: string) {
|
|
127
|
+
return renderToString(
|
|
128
|
+
<RouterProvider initialPath={url}>
|
|
129
|
+
<App />
|
|
130
|
+
</RouterProvider>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@flight-framework/router",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Agnostic client-side routing primitives for Flight Framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"flight",
|
|
20
|
+
"router",
|
|
21
|
+
"spa",
|
|
22
|
+
"navigation",
|
|
23
|
+
"ssr"
|
|
24
|
+
],
|
|
25
|
+
"author": "Flight Framework",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/EliosLT/Flight-framework",
|
|
30
|
+
"directory": "packages/router"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.3.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"react": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
46
|
+
"dev": "tsup src/index.ts --format esm --dts --watch"
|
|
47
|
+
}
|
|
48
48
|
}
|