@pyreon/router 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Vit Bokisch
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 ADDED
@@ -0,0 +1,90 @@
1
+ # @pyreon/router
2
+
3
+ Type-safe client-side router for Pyreon with hash and history modes, nested routes, guards, loaders, and scroll restoration.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @pyreon/router
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { createRouter, RouterProvider, RouterView, RouterLink } from "@pyreon/router"
15
+ import { h } from "@pyreon/core"
16
+
17
+ const router = createRouter({
18
+ routes: [
19
+ { path: "/", component: Home },
20
+ { path: "/user/:id", component: UserPage, name: "user" },
21
+ { path: "/admin", component: AdminLayout, children: [
22
+ { path: "users", component: AdminUsers },
23
+ ]},
24
+ { path: "/old-path", redirect: "/new-path" },
25
+ { path: "/dashboard", component: lazy(() => import("./Dashboard")) },
26
+ { path: "(.*)", component: NotFound },
27
+ ],
28
+ })
29
+
30
+ const App = () =>
31
+ h(RouterProvider, { router },
32
+ h(RouterView, null))
33
+ ```
34
+
35
+ ## Typed Params
36
+
37
+ Route parameters are inferred from path strings:
38
+
39
+ ```ts
40
+ const route = useRoute<"/user/:id">()
41
+ route().params.id // string
42
+ ```
43
+
44
+ ## Named Navigation
45
+
46
+ ```ts
47
+ const router = useRouter()
48
+ router.push({ name: "user", params: { id: "42" } })
49
+ ```
50
+
51
+ ## Data Loaders
52
+
53
+ ```ts
54
+ import { useLoaderData, prefetchLoaderData } from "@pyreon/router"
55
+
56
+ const data = useLoaderData<typeof loader>()
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### Router Creation
62
+
63
+ - `createRouter(options: RouterOptions)` -- create a router instance
64
+ - `lazy(loader)` -- define a lazily loaded route component
65
+
66
+ ### Hooks
67
+
68
+ - `useRouter()` -- access the router instance
69
+ - `useRoute<Path>()` -- access the current resolved route with typed params
70
+ - `useLoaderData<T>()` -- access data returned by a route loader
71
+
72
+ ### Components
73
+
74
+ - `RouterProvider` -- provides router context to the tree
75
+ - `RouterView` -- renders the matched route component
76
+ - `RouterLink` -- anchor element with client-side navigation
77
+
78
+ ### Utilities
79
+
80
+ - `resolveRoute(routes, path)` -- match a path against route definitions
81
+ - `parseQuery(search)` / `parseQueryMulti(search)` -- parse query strings
82
+ - `stringifyQuery(params)` -- serialize query parameters
83
+ - `buildPath(pattern, params)` -- build a path from a pattern and params
84
+ - `findRouteByName(routes, name)` -- look up a named route
85
+ - `prefetchLoaderData(router, path)` -- prefetch loader data for a path
86
+ - `serializeLoaderData(router)` / `hydrateLoaderData(router, data)` -- SSR serialization
87
+
88
+ ### Types
89
+
90
+ `ExtractParams`, `RouteMeta`, `ResolvedRoute`, `RouteRecord`, `RouterOptions`, `Router`, `NavigationGuard`, `AfterEachHook`, `ScrollBehaviorFn`, `LoaderContext`, `RouteLoaderFn`