-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathindex.d.ts
93 lines (77 loc) · 2.2 KB
/
index.d.ts
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
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
import * as preact from 'preact';
export function route(url: string, replace?: boolean): boolean;
export function route(options: { url: string; replace?: boolean }): boolean;
export function exec(url: string, route: string, opts: { default?: boolean }): false | Record<string, string | undefined>;
export function getCurrentUrl(): string;
export interface Location {
pathname: string;
search: string;
}
export interface CustomHistory {
listen(callback: (location: Location) => void): () => void;
location: Location;
push(path: string): void;
replace(path: string): void;
}
export interface RoutableProps {
path?: string;
default?: boolean | preact.JSX.SignalLike<boolean | undefined>;
}
export interface RouterOnChangeArgs<
RouteParams extends Record<string, string | undefined> | null = Record<
string,
string | undefined
> | null
> {
router: Router;
url: string;
previous?: string;
active: preact.VNode[];
current: preact.VNode;
path: string | null;
matches: RouteParams;
}
export interface RouterProps<
RouteParams extends Record<string, string | undefined> | null = Record<
string,
string | undefined
> | null
> extends RoutableProps {
history?: CustomHistory;
static?: boolean;
url?: string;
onChange?: (args: RouterOnChangeArgs<RouteParams>) => void;
}
export class Router extends preact.Component<RouterProps, {}> {
canRoute(url: string): boolean;
routeTo(url: string): boolean;
render(props: RouterProps, {}): preact.VNode;
}
type AnyComponent<Props> =
| preact.FunctionalComponent<Props>
| preact.ComponentConstructor<Props, any>;
export interface RouteProps<Props> extends RoutableProps {
component: AnyComponent<Props>;
}
export function Route<Props>(
props: RouteProps<Props> & Partial<Props>
): preact.VNode;
export function Link(
props: preact.JSX.HTMLAttributes<HTMLAnchorElement>
): preact.VNode;
export function useRouter<
RouteParams extends Record<string, string | undefined> | null = Record<
string,
string | undefined
> | null
>(): [
RouterOnChangeArgs<RouteParams>,
(
urlOrOptions: string | { url: string; replace?: boolean },
replace?: boolean
) => boolean
];
declare module 'preact' {
export interface Attributes extends RoutableProps {}
}
export default Router;