forked from reach/router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
148 lines (114 loc) · 3.71 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Type definitions for @reach/router 1.0
// Project: https://github.com/reach/router
// Definitions by: Kingdaro <https://github.com/kingdaro>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
import { Location as HLocation } from "history";
export type WindowLocation = Window["location"] & HLocation;
export interface History {
readonly location: string;
readonly transitioning: boolean;
listen: (listener: HistoryListener) => HistoryUnsubscribe;
navigate: NavigateFn;
}
export type HistoryListener = () => void;
export type HistoryUnsubscribe = () => void;
export class Router extends React.Component<RouterProps> {}
export interface RouterProps {
basepath?: string;
primary?: boolean;
location?: WindowLocation;
}
export type RouteComponentProps<TParams = {}> = Partial<TParams> & {
path?: string;
default?: boolean;
location?: WindowLocation;
navigate?: NavigateFn;
uri?: string;
};
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export type AnchorProps = Omit<
React.DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>,
"href" // remove href, as it's ignored by the router
>;
export interface LinkProps<TState> extends AnchorProps {
to?: string;
replace?: boolean;
getProps?: (props: LinkGetProps) => {};
state?: TState;
}
export interface LinkGetProps {
isCurrent: boolean;
isPartiallyCurrent: boolean;
href: string;
location: WindowLocation;
}
export class Link<TState> extends React.Component<LinkProps<TState>> {}
export interface RedirectProps<TState> {
from?: string;
to: string;
noThrow?: boolean;
state?: TState;
replace?: boolean;
}
export class Redirect<TState> extends React.Component<RedirectProps<TState>> {}
export interface MatchProps<TParams> {
path: string;
children: MatchRenderFn<TParams>;
}
export type MatchRenderFn<TParams> = (
props: MatchRenderProps<TParams>
) => React.ReactNode;
export interface MatchRenderProps<TParams> {
match: null | { uri: string; path: string } & TParams;
location: WindowLocation;
navigate: NavigateFn;
}
export class Match<TParams> extends React.Component<MatchProps<TParams>> {}
export type NavigateFn = (to: string, options?: NavigateOptions<{}>) => void;
export interface NavigateOptions<TState> {
state?: TState;
replace?: boolean;
}
export interface LocationProps {
children: LocationProviderRenderFn;
}
export class Location extends React.Component<LocationProps> {}
export interface LocationProviderProps {
history: History;
children?: React.ReactNode | LocationProviderRenderFn;
}
export type LocationProviderRenderFn = (
context: LocationContext
) => React.ReactNode;
export interface LocationContext {
location: WindowLocation;
navigate: NavigateFn;
}
export class LocationProvider extends React.Component<LocationProviderProps> {}
export interface ServerLocationProps {
url: string;
}
export class ServerLocation extends React.Component<ServerLocationProps> {}
export const navigate: NavigateFn;
export interface HistorySource {
readonly location: WindowLocation;
addEventListener(name: string, listener: (event: Event) => void): void;
removeEventListener(name: string, listener: (event: Event) => void): void;
history: {
readonly state: any;
pushState(state: any, title: string, uri: string): void;
replaceState(state: any, title: string, uri: string): void;
};
}
export function createHistory(source: HistorySource): History;
export function createMemorySource(initialPath: string): HistorySource;
export interface RedirectRequest {
uri: string;
}
export function isRedirect(error: any): error is RedirectRequest;
export function redirectTo(uri: string): void;