moira-web
168 строк · 4.4 Кб
1declare module 'react-router-dom' {
2declare type BrowserRouterProps = {
3basename?: string,
4forceRefresh?: boolean,
5getUserConfirmation?: GetUserConfirmation,
6keyLength?: number,
7children?: React$Element<*>,
8};
9
10declare export class BrowserRouter extends React$Component<BrowserRouterProps> {
11props: BrowserRouterProps;
12}
13
14declare export class HashRouter extends React$Component<*> {
15props: {
16basename?: string,
17getUserConfirmation?: GetUserConfirmation,
18hashType?: 'slash' | 'noslash' | 'hashbang',
19children?: React$Element<*>,
20}
21}
22
23declare export class Link extends React$Component<*> {
24props: {
25to?: string | LocationShape,
26replace?: boolean,
27children?: React$Element<*>,
28}
29}
30
31declare export class NavLink extends React$Component<*> {
32props: {
33to: string | LocationShape,
34activeClassName?: string,
35className?: string,
36activeStyle?: Object,
37style?: Object,
38isActive?: (match: Match, location: Location) => boolean,
39children?: React$Element<*>,
40exact?: bool,
41strict?: bool,
42}
43}
44
45// NOTE: Below are duplicated from react-router. If updating these, please
46// update the react-router and react-router-native types as well.
47declare export type Location = {
48pathname: string,
49search: string,
50hash: string,
51state?: any,
52key?: string,
53}
54
55declare export type LocationShape = {
56pathname?: string,
57search?: string,
58hash?: string,
59state?: any,
60}
61
62declare export type HistoryAction = 'PUSH' | 'REPLACE' | 'POP'
63
64declare export type RouterHistory = {
65length: number,
66location: Location,
67action: HistoryAction,
68listen(callback: (location: Location, action: HistoryAction) => void): () => void,
69push(path: string | LocationShape, state?: any): void,
70replace(path: string | LocationShape, state?: any): void,
71go(n: number): void,
72goBack(): void,
73goForward(): void,
74canGo?: (n: number) => bool,
75block(callback: (location: Location, action: HistoryAction) => boolean): void,
76// createMemoryHistory
77index?: number,
78entries?: Array<Location>,
79}
80
81declare export type Match = {
82params: { [key: string]: ?string },
83isExact: boolean,
84path: string,
85url: string,
86}
87
88declare export type ContextRouter = {
89history: RouterHistory,
90location: Location,
91match: Match,
92}
93
94declare export type GetUserConfirmation =
95(message: string, callback: (confirmed: boolean) => void) => void
96
97declare type StaticRouterContext = {
98url?: string,
99}
100
101declare export class StaticRouter extends React$Component<*> {
102props: {
103basename?: string,
104location?: string | Location,
105context: StaticRouterContext,
106children?: React$Element<*>,
107}
108}
109
110declare export class MemoryRouter extends React$Component<*> {
111props: {
112initialEntries?: Array<LocationShape | string>,
113initialIndex?: number,
114getUserConfirmation?: GetUserConfirmation,
115keyLength?: number,
116children?: React$Element<*>,
117}
118}
119
120declare export class Router extends React$Component<*> {
121props: {
122history: RouterHistory,
123children?: React$Element<*>,
124}
125}
126
127declare export class Prompt extends React$Component<*> {
128props: {
129message: string | (location: Location) => string | true,
130when?: boolean,
131}
132}
133
134declare export class Redirect extends React$Component<*> {
135props: {
136to: string | LocationShape,
137push?: boolean,
138}
139}
140
141declare export class Route extends React$Component<*> {
142props: {
143component?: React$ComponentType<any>,
144render?: (router: ContextRouter) => React$Element<*>,
145children?: (router: ContextRouter) => React$Element<*>,
146path?: string,
147exact?: bool,
148strict?: bool,
149}
150}
151
152declare export class Switch extends React$Component<*> {
153props: {
154children?: Array<React$Element<*>>,
155}
156}
157
158declare type FunctionComponent<P> = (props: P) => ?React$Element<any>;
159declare type ClassComponent<D, P, S> = Class<React$Component<D, P, S>>;
160declare export function withRouter<P, S>(Component: ClassComponent<void, P, S> | FunctionComponent<P>): ClassComponent<void, $Diff<P, ContextRouter>, S>;
161
162declare type MatchPathOptions = {
163path: string,
164exact?: boolean,
165strict?: boolean,
166}
167declare export function matchPath(pathname: string, options: MatchPathOptions): null | Match
168}
169