UNPKG

801 BPlain TextView Raw
1import { useActiveParams, useParams, usePathname } from './hooks'
2import type { OneRouter } from './interfaces/router'
3
4export function createRoute<Path>() {
5 type Route = OneRouter.Route<Path>
6 type Params = Route['Params']
7
8 return {
9 useParams: () => useParams<Params>(),
10 useActiveParams: () => useActiveParams<Params>(),
11 createLoader: (a: Route['Loader']) => a,
12 }
13}
14
15const defaults = createRoute()
16
17const getProxy = () =>
18 new Proxy(
19 {},
20 {
21 get(target, key) {
22 if (Reflect.has(defaults, key)) {
23 return Reflect.get(defaults, key)
24 }
25
26 return getProxy()
27 },
28 }
29 )
30
31const postIdRoute = createRoute<'/feed/[id]'>()
32
33export const route = getProxy() as {
34 feed: {
35 $id: typeof postIdRoute
36 }
37 notifications: {}
38 profile: {}
39}