Skip to content

Instantly share code, notes, and snippets.

@sagiavinash
Created September 10, 2018 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagiavinash/50dfe3a5b7e68a0c9361b31e0a608ae3 to your computer and use it in GitHub Desktop.
Save sagiavinash/50dfe3a5b7e68a0c9361b31e0a608ae3 to your computer and use it in GitHub Desktop.
Flow Types for React Router V4
/*
* Types for React Router V4
* Example Usage:
* type PropsT = {
* myProp: string,
* } & ContextRouterT<{
* routeParam: string,
* anotherRouteParam: ?string,
* }>
*/
export type LocationT = {
pathname: string,
search: string,
hash: string,
state?: any,
key?: string,
};
export type LocationShapeT = {
pathname?: string,
search?: string,
hash?: string,
state?: any,
};
export type HistoryActionT = 'PUSH' | 'REPLACE' | 'POP';
export type RouterHistoryT = {
length: number,
location: LocationT,
action: HistoryActionT,
listen(
callback: (location: LocationT, action: HistoryActionT) => void
): () => void,
push(path: string | LocationShapeT, state?: any): void,
replace(path: string | LocationShapeT, state?: any): void,
go(n: number): void,
goBack(): void,
goForward(): void,
canGo?: (n: number) => boolean,
block(
callback: (location: LocationT, action: HistoryActionT) => boolean
): void,
// createMemoryHistory
index?: number,
entries?: Array<LocationT>,
};
export type MatchT<ParamsT> = {
params: ParamsT,
isExact: boolean,
path: string,
url: string,
};
export type StaticRouterContextT = {
url?: string,
};
export type ContextRouterT<ParamsT> = {
history: RouterHistoryT,
location: LocationT,
match: MatchT<ParamsT>,
staticContext?: StaticRouterContextT,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment