1 | import { useActiveParams, useParams, usePathname } from './hooks'
|
2 | import type { OneRouter } from './interfaces/router'
|
3 |
|
4 | export 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 |
|
15 | const defaults = createRoute()
|
16 |
|
17 | const 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 |
|
31 | const postIdRoute = createRoute<'/feed/[id]'>()
|
32 |
|
33 | export const route = getProxy() as {
|
34 | feed: {
|
35 | $id: typeof postIdRoute
|
36 | }
|
37 | notifications: {}
|
38 | profile: {}
|
39 | }
|