-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrouter.d.ts
More file actions
66 lines (56 loc) · 1.65 KB
/
router.d.ts
File metadata and controls
66 lines (56 loc) · 1.65 KB
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
import { AnyComponent, ComponentChildren, FunctionComponent, VNode } from 'preact';
export function LocationProvider(props: {
scope?: string | RegExp;
children?: ComponentChildren;
}): VNode;
type NestedArray<T> = Array<T | NestedArray<T>>;
/**
* Check if a URL path matches against a URL path pattern.
*
* Warning: This is an internal API exported only for testing purpose. API could change in future.
* @param url - URL path (e.g. /user/12345)
* @param route - URL pattern (e.g. /user/:id)
*/
export function exec(url: string, route: string, matches: {
params: {
[param: string]: string;
};
rest?: string;
[props: string]: string;
}): {
params: {
[param: string]: string;
},
rest?: string;
[propsOrParam: string]: string;
}
export function Router(props: {
onRouteChange?: (url: string) => void;
onLoadEnd?: (url: string) => void;
onLoadStart?: (url: string) => void;
children?: NestedArray<VNode>;
}): VNode;
interface LocationHook {
url: string;
path: string;
query: Record<string, string>;
route: (url: string, replace?: boolean) => void;
}
export const useLocation: () => LocationHook;
interface RouteHook {
path: string;
query: Record<string, string>;
params: Record<string, string>;
}
export const useRoute: () => RouteHook;
type RoutableProps =
| { path: string; default?: false; }
| { path?: never; default: true; }
export type RouteProps<Props> = RoutableProps & { component: AnyComponent<Props> };
export function Route<Props>(props: RouteProps<Props> & Partial<Props>): VNode;
declare module 'preact' {
namespace JSX {
interface IntrinsicAttributes extends RoutableProps {}
}
interface Attributes extends RoutableProps {}
}