-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrouter.d.ts
More file actions
62 lines (50 loc) · 1.6 KB
/
router.d.ts
File metadata and controls
62 lines (50 loc) · 1.6 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
import { AnyComponent, ComponentChildren, Context, VNode } from 'preact';
export const LocationProvider: {
(props: { scope?: string | RegExp; children?: ComponentChildren; }): VNode;
ctx: Context<LocationHook>;
};
type NestedArray<T> = Array<T | NestedArray<T>>;
interface KnownProps {
path: string;
query: Record<string, string>;
params: Record<string, string>;
default?: boolean;
rest?: string;
component?: AnyComponent;
}
interface ArbitraryProps {
[prop: string]: any;
}
type MatchProps = KnownProps & ArbitraryProps;
/**
* Check if a URL path matches against a URL path pattern.
*
* Warning: This is largely an internal API, it may change in the 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?: MatchProps): MatchProps
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;
pathParams: Record<string, string>;
searchParams: Record<string, string>;
}
export const useLocation: () => LocationHook;
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 {}
}