@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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +137 -144
  3. 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
- Agnostic client-side routing primitives for Flight Framework.
4
-
5
- ## Philosophy
6
-
7
- - Zero external runtime dependencies
8
- - Works with React, Vue, Svelte, or vanilla JS
9
- - SSR-safe (works on server and client)
10
- - No vendor lock-in
11
-
12
- ## Installation
13
-
14
- ```bash
15
- npm install @flight-framework/router
16
- ```
17
-
18
- ## Usage
19
-
20
- ### With React
21
-
22
- ```tsx
23
- import { RouterProvider, Link, useRouter } from '@flight-framework/router';
24
-
25
- // Wrap your app
26
- function App() {
27
- return (
28
- <RouterProvider initialPath={url}>
29
- <Navigation />
30
- <Content />
31
- </RouterProvider>
32
- );
33
- }
34
-
35
- // Use Link for navigation
36
- function Navigation() {
37
- return (
38
- <nav>
39
- <Link href="/">Home</Link>
40
- <Link href="/docs" prefetch>Docs</Link>
41
- <Link href="/about">About</Link>
42
- </nav>
43
- );
44
- }
45
-
46
- // Use hooks to access router state
47
- function Content() {
48
- const { path, navigate } = useRouter();
49
-
50
- return (
51
- <main>
52
- <p>Current path: {path}</p>
53
- <button onClick={() => navigate('/dashboard')}>
54
- Go to Dashboard
55
- </button>
56
- </main>
57
- );
58
- }
59
- ```
60
-
61
- ### Hooks
62
-
63
- ```tsx
64
- // Get current path and navigation functions
65
- const { path, searchParams, navigate, back, forward } = useRouter();
66
-
67
- // Get route parameters (from dynamic routes like [slug])
68
- const { slug } = useParams<{ slug: string }>();
69
-
70
- // Get and set search params
71
- const [searchParams, setSearchParams] = useSearchParams();
72
-
73
- // Get current pathname
74
- const pathname = usePathname();
75
- ```
76
-
77
- ### Programmatic Navigation
78
-
79
- ```ts
80
- import { navigate, prefetch } from '@flight-framework/router';
81
-
82
- // Navigate to a path
83
- navigate('/docs');
84
-
85
- // Replace history instead of push
86
- navigate('/login', { replace: true });
87
-
88
- // Navigate without scrolling to top
89
- navigate('/next-page', { scroll: false });
90
-
91
- // Pass state data
92
- navigate('/dashboard', { state: { from: '/login' } });
93
-
94
- // Prefetch a route
95
- prefetch('/heavy-page');
96
- ```
97
-
98
- ### Route Matching
99
-
100
- ```ts
101
- import { matchRoute, parseParams, generatePath } from '@flight-framework/router';
102
-
103
- // Check if a path matches a pattern
104
- const { matched, params } = matchRoute('/docs/routing', '/docs/:slug');
105
- // matched: true, params: { slug: 'routing' }
106
-
107
- // Parse params from a path
108
- const params = parseParams('/blog/2024/my-post', '/blog/:year/:slug');
109
- // { year: '2024', slug: 'my-post' }
110
-
111
- // Generate a path from pattern and params
112
- const path = generatePath('/docs/:slug', { slug: 'api-routes' });
113
- // '/docs/api-routes'
114
- ```
115
-
116
- ### Link Props
117
-
118
- | Prop | Type | Default | Description |
119
- |------|------|---------|-------------|
120
- | `href` | `string` | required | Target URL path |
121
- | `prefetch` | `boolean` | `false` | Prefetch target on hover |
122
- | `replace` | `boolean` | `false` | Replace history entry |
123
- | `scroll` | `boolean` | `true` | Scroll to top on navigate |
124
- | `target` | `string` | - | Link target (_blank, etc) |
125
- | `className` | `string` | - | CSS class |
126
-
127
- ## SSR Support
128
-
129
- The router is SSR-safe. Pass the initial path from your server:
130
-
131
- ```tsx
132
- // entry-server.tsx
133
- export function render(url: string) {
134
- return renderToString(
135
- <RouterProvider initialPath={url}>
136
- <App />
137
- </RouterProvider>
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
- "name": "@flight-framework/router",
3
- "version": "0.0.1",
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
- "scripts": {
19
- "build": "tsup src/index.ts --format esm --dts --clean",
20
- "dev": "tsup src/index.ts --format esm --dts --watch"
21
- },
22
- "keywords": [
23
- "flight",
24
- "router",
25
- "spa",
26
- "navigation",
27
- "ssr"
28
- ],
29
- "author": "Flight Framework",
30
- "license": "MIT",
31
- "repository": {
32
- "type": "git",
33
- "url": "https://github.com/EliosLT/Flight-framework",
34
- "directory": "packages/router"
35
- },
36
- "devDependencies": {
37
- "tsup": "^8.0.0",
38
- "typescript": "^5.3.0"
39
- },
40
- "peerDependencies": {
41
- "react": ">=18.0.0"
42
- },
43
- "peerDependenciesMeta": {
44
- "react": {
45
- "optional": true
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
  }