mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
Update react-router definitions to 3.0.x
This commit is contained in:
137
react-router/index.d.ts
vendored
137
react-router/index.d.ts
vendored
@@ -1,91 +1,56 @@
|
||||
// Type definitions for react-router v2.0.0
|
||||
// Type definitions for react-router 3.0
|
||||
// Project: https://github.com/rackt/react-router
|
||||
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>, Nathan Brown <https://github.com/ngbrown>, Alex Wendland <https://github.com/awendland>, Kostya Esmukov <https://github.com/KostyaEsmukov>
|
||||
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>, Nathan Brown <https://github.com/ngbrown>, Alex Wendland <https://github.com/awendland>, Kostya Esmukov <https://github.com/KostyaEsmukov>, Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="history" />
|
||||
|
||||
export as namespace ReactRouter;
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export const routerShape: React.Requireable<any>
|
||||
|
||||
export const locationShape: React.Requireable<any>
|
||||
|
||||
import Router from "./lib/Router";
|
||||
import Link from "./lib/Link";
|
||||
import IndexLink from "./lib/IndexLink";
|
||||
import IndexRedirect from "./lib/IndexRedirect";
|
||||
import IndexRoute from "./lib/IndexRoute";
|
||||
import Redirect from "./lib/Redirect";
|
||||
import Route from "./lib/Route";
|
||||
import * as History from "./lib/routerHistory";
|
||||
import Lifecycle from "./lib/Lifecycle";
|
||||
import RouteContext from "./lib/RouteContext";
|
||||
import browserHistory from "./lib/browserHistory";
|
||||
import hashHistory from "./lib/hashHistory";
|
||||
import useRoutes from "./lib/useRoutes";
|
||||
import { createRoutes } from "./lib/RouteUtils";
|
||||
import { formatPattern } from "./lib/PatternUtils";
|
||||
import RouterContext from "./lib/RouterContext";
|
||||
import PropTypes from "./lib/PropTypes";
|
||||
import match from "./lib/match";
|
||||
import useRouterHistory from "./lib/useRouterHistory";
|
||||
import createMemoryHistory from "./lib/createMemoryHistory";
|
||||
import withRouter from "./lib/withRouter";
|
||||
import applyRouterMiddleware from "./lib/applyRouterMiddleware";
|
||||
|
||||
// PlainRoute is defined in the API documented at:
|
||||
// https://github.com/rackt/react-router/blob/master/docs/API.md
|
||||
// but not included in any of the .../lib modules above.
|
||||
export type PlainRoute = Router.PlainRoute;
|
||||
|
||||
// The following definitions are also very useful to export
|
||||
// because by using these types lots of potential type errors
|
||||
// can be exposed:
|
||||
export type EnterHook = Router.EnterHook;
|
||||
export type LeaveHook = Router.LeaveHook;
|
||||
export type ParseQueryString = Router.ParseQueryString;
|
||||
export type LocationDescriptor = Router.LocationDescriptor;
|
||||
export type RedirectFunction = Router.RedirectFunction;
|
||||
export type RouteComponent = Router.RouteComponent;
|
||||
export type RouteComponentProps<P, R> = Router.RouteComponentProps<P, R>;
|
||||
export type RouteConfig = Router.RouteConfig;
|
||||
export type RouteHook = Router.RouteHook;
|
||||
export type StringifyQuery = Router.StringifyQuery;
|
||||
export type RouterListener = Router.RouterListener;
|
||||
export type RouterState = Router.RouterState;
|
||||
export type InjectedRouter = Router.InjectedRouter;
|
||||
|
||||
export type HistoryBase = History.HistoryBase;
|
||||
export type RouterOnContext = Router.RouterOnContext;
|
||||
export type RouteProps = Route.RouteProps;
|
||||
export type LinkProps = Link.LinkProps;
|
||||
|
||||
export {
|
||||
Router,
|
||||
Link,
|
||||
IndexLink,
|
||||
IndexRedirect,
|
||||
IndexRoute,
|
||||
Redirect,
|
||||
Route,
|
||||
History,
|
||||
browserHistory,
|
||||
hashHistory,
|
||||
Lifecycle,
|
||||
RouteContext,
|
||||
useRoutes,
|
||||
createRoutes,
|
||||
formatPattern,
|
||||
RouterContext,
|
||||
PropTypes,
|
||||
match,
|
||||
useRouterHistory,
|
||||
createMemoryHistory,
|
||||
withRouter,
|
||||
applyRouterMiddleware
|
||||
};
|
||||
Basename,
|
||||
ChangeHook,
|
||||
EnterHook,
|
||||
InjectedRouter,
|
||||
LeaveHook,
|
||||
Location,
|
||||
LocationDescriptor,
|
||||
ParseQueryString,
|
||||
RouteComponent,
|
||||
RouteComponents,
|
||||
RouteComponentProps,
|
||||
RouteConfig,
|
||||
RoutePattern,
|
||||
RouterProps,
|
||||
RouterState,
|
||||
StringifyQuery,
|
||||
Query
|
||||
} from "react-router/lib/Router";
|
||||
export { LinkProps } from "react-router/lib/Link";
|
||||
export { IndexLinkProps } from "react-router/lib/IndexLink";
|
||||
export { RouteProps, PlainRoute } from "react-router/lib/Route";
|
||||
export { IndexRouteProps } from "react-router/lib/IndexRoute";
|
||||
export { RedirectProps } from "react-router/lib/Redirect";
|
||||
export { IndexRedirectProps } from "react-router/lib/IndexRedirect";
|
||||
|
||||
export default Router;
|
||||
/* components */
|
||||
export { default as Router } from "react-router/lib/Router";
|
||||
export { default as Link } from "react-router/lib/Link";
|
||||
export { default as IndexLink } from "react-router/lib/IndexLink";
|
||||
export { default as withRouter } from "react-router/lib/withRouter";
|
||||
|
||||
/* components (configuration) */
|
||||
export { default as IndexRedirect } from "react-router/lib/IndexRedirect";
|
||||
export { default as IndexRoute } from "react-router/lib/IndexRoute";
|
||||
export { default as Redirect } from "react-router/lib/Redirect";
|
||||
export { default as Route } from "react-router/lib/Route";
|
||||
|
||||
/* utils */
|
||||
export { createRoutes } from "react-router/lib/RouteUtils";
|
||||
export { default as RouterContext } from "react-router/lib/RouterContext";
|
||||
export { routerShape, locationShape } from "react-router/lib/PropTypes";
|
||||
export { default as match } from "react-router/lib/match";
|
||||
export { default as useRouterHistory } from "react-router/lib/useRouterHistory";
|
||||
export { formatPattern } from "react-router/lib/PatternUtils";
|
||||
export { default as applyRouterMiddleware } from "react-router/lib/applyRouterMiddleware";
|
||||
|
||||
/* histories */
|
||||
export { default as browserHistory } from "react-router/lib/browserHistory";
|
||||
export { default as hashHistory } from "react-router/lib/hashHistory";
|
||||
export { default as createMemoryHistory } from "react-router/lib/createMemoryHistory";
|
||||
|
||||
16
react-router/lib/IndexLink.d.ts
vendored
16
react-router/lib/IndexLink.d.ts
vendored
@@ -1,5 +1,15 @@
|
||||
import Link from './Link';
|
||||
import { ComponentClass, CSSProperties, HTMLProps } from "react";
|
||||
import { Location, LocationDescriptor } from "react-router/lib/Router";
|
||||
|
||||
type ToLocationFunction = (location: Location) => LocationDescriptor;
|
||||
|
||||
export interface IndexLinkProps extends HTMLProps<any> {
|
||||
to: LocationDescriptor | ToLocationFunction;
|
||||
activeClassName?: string;
|
||||
activeStyle?: CSSProperties;
|
||||
}
|
||||
|
||||
type IndexLink = ComponentClass<IndexLinkProps>;
|
||||
declare const IndexLink: IndexLink;
|
||||
|
||||
declare const IndexLink: Link;
|
||||
export default IndexLink;
|
||||
|
||||
|
||||
25
react-router/lib/IndexRedirect.d.ts
vendored
25
react-router/lib/IndexRedirect.d.ts
vendored
@@ -1,17 +1,12 @@
|
||||
import Router from './Router';
|
||||
import * as React from 'react';
|
||||
import * as H from 'history';
|
||||
import { ComponentClass, ClassAttributes } from "react";
|
||||
import { RoutePattern, Query } from "react-router";
|
||||
|
||||
declare const self: self.IndexRedirect;
|
||||
type self = self.IndexRedirect;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface IndexRedirectProps extends React.Props<self> {
|
||||
to: Router.RoutePattern;
|
||||
query?: H.Query;
|
||||
state?: H.LocationState;
|
||||
}
|
||||
interface IndexRedirectElement extends React.ReactElement<IndexRedirectProps> { }
|
||||
interface IndexRedirect extends React.ComponentClass<self.IndexRedirectProps> { }
|
||||
export interface IndexRedirectProps extends ClassAttributes<any> {
|
||||
to: RoutePattern;
|
||||
query?: Query;
|
||||
}
|
||||
|
||||
type IndexRedirect = ComponentClass<IndexRedirectProps>;
|
||||
declare const IndexRedirect: IndexRedirect;
|
||||
|
||||
export default IndexRedirect;
|
||||
|
||||
44
react-router/lib/IndexRoute.d.ts
vendored
44
react-router/lib/IndexRoute.d.ts
vendored
@@ -1,20 +1,28 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import * as H from 'history';
|
||||
import { ComponentClass, ClassAttributes } from "react";
|
||||
import { LocationState } from "history";
|
||||
import {
|
||||
EnterHook,
|
||||
ChangeHook,
|
||||
LeaveHook,
|
||||
RouteComponent,
|
||||
RouteComponents,
|
||||
RouterState
|
||||
} from "react-router";
|
||||
|
||||
declare const self: self.IndexRoute;
|
||||
type self = self.IndexRoute;
|
||||
export default self;
|
||||
type ComponentCallback = (err: any, component: RouteComponent) => void;
|
||||
type ComponentsCallback = (err: any, components: RouteComponents) => void;
|
||||
|
||||
declare namespace self {
|
||||
interface IndexRouteProps extends React.Props<IndexRoute> {
|
||||
component?: Router.RouteComponent;
|
||||
components?: Router.RouteComponents;
|
||||
getComponent?: (location: H.Location, cb: (error: any, component?: Router.RouteComponent) => void) => void;
|
||||
getComponents?: (location: H.Location, cb: (error: any, components?: Router.RouteComponents) => void) => void;
|
||||
onEnter?: Router.EnterHook;
|
||||
onLeave?: Router.LeaveHook;
|
||||
}
|
||||
interface IndexRoute extends React.ComponentClass<IndexRouteProps> { }
|
||||
interface IndexRouteElement extends React.ReactElement<IndexRouteProps> { }
|
||||
}
|
||||
export interface IndexRouteProps {
|
||||
component?: RouteComponent;
|
||||
components?: RouteComponents;
|
||||
getComponent?(nextState: RouterState, callback: ComponentCallback): void;
|
||||
getComponents?(nextState: RouterState, callback: ComponentsCallback): void;
|
||||
onEnter?: EnterHook;
|
||||
onChange?: ChangeHook;
|
||||
onLeave?: LeaveHook;
|
||||
}
|
||||
|
||||
type IndexRoute = ComponentClass<IndexRouteProps>;
|
||||
declare const IndexRoute: IndexRoute;
|
||||
|
||||
export default IndexRoute;
|
||||
|
||||
22
react-router/lib/Link.d.ts
vendored
22
react-router/lib/Link.d.ts
vendored
@@ -1,19 +1,11 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import { ComponentClass, CSSProperties, HTMLProps } from "react";
|
||||
import { IndexLinkProps } from "react-router/lib/IndexLink";
|
||||
|
||||
export interface LinkProps extends IndexLinkProps {
|
||||
onlyActiveOnIndex?: boolean;
|
||||
}
|
||||
|
||||
type Link = ComponentClass<LinkProps>;
|
||||
declare const Link: Link;
|
||||
type Link = Link.Link;
|
||||
|
||||
export default Link;
|
||||
|
||||
declare namespace Link {
|
||||
interface LinkProps extends React.HTMLAttributes<Link> {
|
||||
activeStyle?: React.CSSProperties;
|
||||
activeClassName?: string;
|
||||
onlyActiveOnIndex?: boolean;
|
||||
to: Router.RoutePattern | Router.LocationDescriptor | ((...args: any[]) => Router.LocationDescriptor);
|
||||
}
|
||||
|
||||
interface Link extends React.ComponentClass<LinkProps> {}
|
||||
interface LinkElement extends React.ReactElement<LinkProps> {}
|
||||
}
|
||||
|
||||
4
react-router/lib/PatternUtils.d.ts
vendored
4
react-router/lib/PatternUtils.d.ts
vendored
@@ -1 +1,3 @@
|
||||
export function formatPattern(pattern: string, params: {}): string;
|
||||
import { RoutePattern } from "react-router";
|
||||
|
||||
export function formatPattern(pattern: RoutePattern, params: any): string;
|
||||
|
||||
35
react-router/lib/PropTypes.d.ts
vendored
35
react-router/lib/PropTypes.d.ts
vendored
@@ -1,19 +1,22 @@
|
||||
import * as React from 'react';
|
||||
import { Requireable, Validator } from "react";
|
||||
|
||||
export function falsy(props: any, propName: string, componentName: string): Error;
|
||||
export const history: React.Requireable<any>;
|
||||
export const location: React.Requireable<any>;
|
||||
export const component: React.Requireable<any>;
|
||||
export const components: React.Requireable<any>;
|
||||
export const route: React.Requireable<any>;
|
||||
export const routes: React.Requireable<any>;
|
||||
export interface RouterShape extends Validator<any> {
|
||||
push: Requireable<any>;
|
||||
replace: Requireable<any>;
|
||||
go: Requireable<any>;
|
||||
goBack: Requireable<any>;
|
||||
goForward: Requireable<any>;
|
||||
setRouteLeaveHook: Requireable<any>;
|
||||
isActive: Requireable<any>;
|
||||
}
|
||||
|
||||
export default {
|
||||
falsy,
|
||||
history,
|
||||
location,
|
||||
component,
|
||||
components,
|
||||
route
|
||||
};
|
||||
export interface LocationShape extends Validator<any> {
|
||||
pathname: Requireable<any>;
|
||||
search: Requireable<any>;
|
||||
state: any;
|
||||
action: Requireable<any>;
|
||||
key: any;
|
||||
}
|
||||
|
||||
export const routerShape: RouterShape;
|
||||
export const locationShape: LocationShape;
|
||||
|
||||
27
react-router/lib/Redirect.d.ts
vendored
27
react-router/lib/Redirect.d.ts
vendored
@@ -1,19 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import * as H from 'history';
|
||||
import { ComponentClass, ClassAttributes } from "react";
|
||||
import { RoutePattern, Query } from "react-router";
|
||||
import { IndexRedirectProps } from "react-router/lib/IndexRedirect";
|
||||
|
||||
declare const self: self.Redirect;
|
||||
type self = typeof self;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface RedirectProps extends React.Props<Redirect> {
|
||||
path?: Router.RoutePattern;
|
||||
from?: Router.RoutePattern; // alias for path
|
||||
to: Router.RoutePattern;
|
||||
query?: H.Query;
|
||||
state?: H.LocationState;
|
||||
}
|
||||
interface Redirect extends React.ComponentClass<RedirectProps> { }
|
||||
interface RedirectElement extends React.ReactElement<RedirectProps> { }
|
||||
export interface RedirectProps extends IndexRedirectProps {
|
||||
from: RoutePattern;
|
||||
}
|
||||
|
||||
type Redirect = ComponentClass<RedirectProps>;
|
||||
declare const Redirect: Redirect;
|
||||
|
||||
export default Redirect;
|
||||
|
||||
50
react-router/lib/Route.d.ts
vendored
50
react-router/lib/Route.d.ts
vendored
@@ -1,25 +1,31 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import { Location } from 'history';
|
||||
import { ComponentClass, ClassAttributes } from "react";
|
||||
import { LocationState } from "history";
|
||||
import {
|
||||
EnterHook,
|
||||
ChangeHook,
|
||||
LeaveHook,
|
||||
RouteComponent,
|
||||
RouteComponents,
|
||||
RoutePattern,
|
||||
RouterState
|
||||
} from "react-router";
|
||||
import { IndexRouteProps } from "react-router/lib/IndexRoute";
|
||||
|
||||
declare const self: self.Route;
|
||||
type self = self.Route;
|
||||
export default self;
|
||||
export interface RouteProps extends IndexRouteProps {
|
||||
path?: RoutePattern;
|
||||
}
|
||||
|
||||
declare namespace self {
|
||||
type Route = ComponentClass<RouteProps>;
|
||||
declare const Route: Route;
|
||||
|
||||
interface RouteProps extends React.Props<Route> {
|
||||
path?: Router.RoutePattern;
|
||||
component?: Router.RouteComponent;
|
||||
components?: Router.RouteComponents;
|
||||
getComponent?: (nextState: Router.RouterState, cb: (error: any, component?: Router.RouteComponent) => void) => void
|
||||
getComponents?: (nextState: Router.RouterState, cb: (error: any, components?: Router.RouteComponents) => void) => void
|
||||
onEnter?: Router.EnterHook;
|
||||
onLeave?: Router.LeaveHook;
|
||||
onChange?: Router.ChangeHook;
|
||||
getIndexRoute?: (location: Location, cb: (error: any, indexRoute: Router.RouteConfig) => void) => void;
|
||||
getChildRoutes?: (location: Location, cb: (error: any, childRoutes: Router.RouteConfig) => void) => void;
|
||||
}
|
||||
interface Route extends React.ComponentClass<RouteProps> {}
|
||||
interface RouteElement extends React.ReactElement<RouteProps> {}
|
||||
}
|
||||
export default Route;
|
||||
|
||||
type RouteCallback = (err: any, route: PlainRoute) => void;
|
||||
type RoutesCallback = (err: any, routesArray: PlainRoute[]) => void;
|
||||
|
||||
export interface PlainRoute extends RouteProps {
|
||||
childRoutes?: PlainRoute[];
|
||||
getChildRoutes?(partialNextState: LocationState, callback: RoutesCallback): void;
|
||||
indexRoute?: PlainRoute;
|
||||
getIndexRoute?(partialNextState: LocationState, callback: RouteCallback): void;
|
||||
}
|
||||
|
||||
9
react-router/lib/RouteUtils.d.ts
vendored
9
react-router/lib/RouteUtils.d.ts
vendored
@@ -1,8 +1,3 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import { RouteConfig, PlainRoute } from "react-router";
|
||||
|
||||
type E = React.ReactElement<any>;
|
||||
export function isReactChildren(object: E | E[]): boolean;
|
||||
export function createRouteFromReactElement(element: E): Router.PlainRoute;
|
||||
export function createRoutesFromReactChildren(children: E | E[], parentRoute: Router.PlainRoute): Router.PlainRoute[];
|
||||
export function createRoutes(routes: Router.RouteConfig): Router.PlainRoute[];
|
||||
export function createRoutes(routes: RouteConfig): PlainRoute[];
|
||||
|
||||
212
react-router/lib/Router.d.ts
vendored
212
react-router/lib/Router.d.ts
vendored
@@ -1,116 +1,106 @@
|
||||
import * as React from 'react';
|
||||
import RouterContext from './RouterContext';
|
||||
import { Component, ComponentClass, ClassAttributes, ReactNode, StatelessComponent } from "react";
|
||||
import {
|
||||
QueryString, Query,
|
||||
Location, LocationDescriptor, LocationState as HLocationState,
|
||||
History, Href,
|
||||
Pathname, Path } from 'history';
|
||||
Hash,
|
||||
History,
|
||||
Href,
|
||||
LocationKey,
|
||||
LocationState,
|
||||
Path,
|
||||
Pathname,
|
||||
Search
|
||||
} from "history";
|
||||
import { PlainRoute } from "react-router";
|
||||
|
||||
export type Basename = string;
|
||||
export type Query = any;
|
||||
export type Action = "PUSH" | "REPLACE" | "POP";
|
||||
export interface Params {
|
||||
[key: string]: string;
|
||||
}
|
||||
export type RoutePattern = string;
|
||||
export type RouteComponent = ComponentClass<any> | StatelessComponent<any>;
|
||||
export interface RouteComponents {
|
||||
[name: string]: RouteComponent;
|
||||
}
|
||||
export type RouteConfig = ReactNode | PlainRoute | PlainRoute[];
|
||||
|
||||
export type ParseQueryString = (queryString: Search) => Query;
|
||||
export type StringifyQuery = (queryObject: Query) => Search;
|
||||
|
||||
type AnyFunction = (...args: any[]) => any;
|
||||
|
||||
export type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: AnyFunction) => any;
|
||||
export type LeaveHook = (prevState: RouterState) => any;
|
||||
export type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback?: AnyFunction) => any;
|
||||
export type RouteHook = (nextLocation?: Location) => any;
|
||||
|
||||
export interface Location {
|
||||
patname: Pathname;
|
||||
search: Search;
|
||||
query: Query;
|
||||
state: LocationState;
|
||||
action: Action;
|
||||
key: LocationKey;
|
||||
}
|
||||
|
||||
export interface LocationDescriptorObject {
|
||||
pathname?: Pathname;
|
||||
query?: Query;
|
||||
hash?: Hash;
|
||||
state?: LocationState;
|
||||
}
|
||||
|
||||
export type LocationDescriptor = Path | LocationDescriptorObject;
|
||||
|
||||
export interface RedirectFunction {
|
||||
(location: LocationDescriptor): void;
|
||||
(state: LocationState, pathname: Pathname | Path, query?: Query): void;
|
||||
}
|
||||
|
||||
export interface RouterState {
|
||||
location: Location;
|
||||
routes: PlainRoute[];
|
||||
params: Params;
|
||||
components: RouteComponent[];
|
||||
}
|
||||
|
||||
type LocationFunction = (location: LocationDescriptor) => void;
|
||||
type GoFunction = (n: number) => void;
|
||||
type NavigateFunction = () => void;
|
||||
type ActiveFunction = (location: LocationDescriptor, indexOnly?: boolean) => boolean;
|
||||
type LeaveHookFunction = (route: any, callback: RouteHook) => void;
|
||||
type CreatePartFunction<Part> = (path: Path, query?: any) => Part;
|
||||
|
||||
export interface InjectedRouter {
|
||||
push: LocationFunction;
|
||||
replace: LocationFunction;
|
||||
go: GoFunction;
|
||||
goBack: NavigateFunction;
|
||||
goForward: NavigateFunction;
|
||||
setRouteLeaveHook: LeaveHookFunction;
|
||||
createPath: CreatePartFunction<Path>;
|
||||
createHref: CreatePartFunction<Href>;
|
||||
isActive: ActiveFunction;
|
||||
}
|
||||
|
||||
export interface RouteComponentProps<P, R> {
|
||||
location?: Location;
|
||||
params?: P & R;
|
||||
route?: PlainRoute;
|
||||
router?: InjectedRouter;
|
||||
routeParams?: R;
|
||||
}
|
||||
|
||||
export interface RouterProps extends ClassAttributes<any> {
|
||||
routes?: RouteConfig;
|
||||
history?: History;
|
||||
createElement?(component: RouteComponent, props: any): any;
|
||||
onError?(error: any): any;
|
||||
onUpdate?(): any;
|
||||
render?(props: any): ReactNode;
|
||||
}
|
||||
|
||||
type Router = ComponentClass<RouterProps>;
|
||||
declare const Router: Router;
|
||||
interface Router extends React.ComponentClass<Router.RouterProps> { }
|
||||
|
||||
export default Router;
|
||||
|
||||
// types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md
|
||||
|
||||
declare namespace Router {
|
||||
type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[];
|
||||
type RoutePattern = string;
|
||||
type RouteComponents = { [key: string]: RouteComponent };
|
||||
|
||||
type ParseQueryString = (queryString: QueryString) => Query;
|
||||
type StringifyQuery = (queryObject: Query) => QueryString;
|
||||
|
||||
type Component = React.ReactType;
|
||||
type RouteComponent = Component;
|
||||
|
||||
type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => void;
|
||||
type LeaveHook = () => void;
|
||||
type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void;
|
||||
type RouteHook = (nextLocation?: Location) => any;
|
||||
|
||||
type Params = { [param: string]: string };
|
||||
|
||||
type RouterListener = (error: Error, nextState: RouterState) => void;
|
||||
|
||||
type LocationDescriptor = {
|
||||
pathname?: Pathname
|
||||
query?: Query
|
||||
hash?: Href
|
||||
state?: HLocationState
|
||||
}
|
||||
|
||||
interface RedirectFunction {
|
||||
(location: LocationDescriptor): void;
|
||||
/**
|
||||
* @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated
|
||||
*/
|
||||
(state: HLocationState, pathname: Pathname | Path, query?: Query): void;
|
||||
}
|
||||
|
||||
interface RouterState {
|
||||
location: Location;
|
||||
routes: PlainRoute[];
|
||||
params: Params;
|
||||
components: RouteComponent[];
|
||||
}
|
||||
|
||||
interface RouterProps extends React.Props<Router> {
|
||||
history?: History;
|
||||
routes?: RouteConfig; // alias for children
|
||||
createElement?: (component: RouteComponent, props: Object) => any;
|
||||
onError?: (error: any) => any;
|
||||
onUpdate?: () => any;
|
||||
parseQueryString?: ParseQueryString;
|
||||
stringifyQuery?: StringifyQuery;
|
||||
basename?: string;
|
||||
render?: (renderProps: React.Props<{}>) => RouterContext;
|
||||
}
|
||||
|
||||
interface PlainRoute {
|
||||
path?: RoutePattern;
|
||||
component?: RouteComponent;
|
||||
components?: RouteComponents;
|
||||
getComponent?: (location: Location, cb: (error: any, component?: RouteComponent) => void) => void;
|
||||
getComponents?: (location: Location, cb: (error: any, components?: RouteComponents) => void) => void;
|
||||
onEnter?: EnterHook;
|
||||
onLeave?: LeaveHook;
|
||||
indexRoute?: PlainRoute;
|
||||
getIndexRoute?: (location: Location, cb: (error: any, indexRoute: RouteConfig) => void) => void;
|
||||
childRoutes?: PlainRoute[];
|
||||
getChildRoutes?: (location: Location, cb: (error: any, childRoutes: RouteConfig) => void) => void;
|
||||
}
|
||||
|
||||
interface RouteComponentProps<P, R> {
|
||||
history?: History;
|
||||
location?: Location;
|
||||
params?: P;
|
||||
route?: PlainRoute;
|
||||
routeParams?: R;
|
||||
routes?: PlainRoute[];
|
||||
children?: React.ReactElement<any>;
|
||||
}
|
||||
|
||||
interface RouterOnContext extends History {
|
||||
setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void;
|
||||
isActive(pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean): boolean;
|
||||
}
|
||||
|
||||
// Wrap a component using withRouter(Component) to provide a router object
|
||||
// to the Component's props, allowing the Component to programmatically call
|
||||
// push and other functions.
|
||||
//
|
||||
// https://github.com/reactjs/react-router/blob/v2.4.0/upgrade-guides/v2.4.0.md
|
||||
|
||||
interface InjectedRouter {
|
||||
push: (pathOrLoc: Path | LocationDescriptor) => void
|
||||
replace: (pathOrLoc: Path | LocationDescriptor) => void
|
||||
go: (n: number) => void
|
||||
goBack: () => void
|
||||
goForward: () => void
|
||||
setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void
|
||||
createPath(path: History.Path, query?: History.Query): History.Path
|
||||
createHref(path: History.Path, query?: History.Query): History.Href
|
||||
isActive: (pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean) => boolean
|
||||
}
|
||||
}
|
||||
|
||||
27
react-router/lib/RouterContext.d.ts
vendored
27
react-router/lib/RouterContext.d.ts
vendored
@@ -1,25 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import * as H from 'history';
|
||||
import Router from './Router';
|
||||
import { ComponentClass } from "react";
|
||||
|
||||
declare const self: self.RouterContext;
|
||||
type self = self.RouterContext;
|
||||
export default self;
|
||||
type RouterContext = ComponentClass<any>;
|
||||
declare const RouterContext: RouterContext;
|
||||
|
||||
declare namespace self {
|
||||
interface RouterContextProps extends React.Props<RouterContext> {
|
||||
history?: H.History;
|
||||
router: Router;
|
||||
createElement: (component: Router.RouteComponent, props: Object) => any;
|
||||
location: H.Location;
|
||||
routes: Router.RouteConfig;
|
||||
params: Router.Params;
|
||||
components?: Router.RouteComponent[];
|
||||
}
|
||||
interface RouterContext extends React.ComponentClass<RouterContextProps> {}
|
||||
interface RouterContextElement extends React.ReactElement<RouterContextProps> {
|
||||
history?: H.History;
|
||||
location: H.Location;
|
||||
router?: Router;
|
||||
}
|
||||
}
|
||||
export default RouterContext;
|
||||
|
||||
12
react-router/lib/applyRouterMiddleware.d.ts
vendored
12
react-router/lib/applyRouterMiddleware.d.ts
vendored
@@ -1,9 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import RouterContext from './RouterContext';
|
||||
import { RouteComponent } from "react-router";
|
||||
import RouterContext from "react-router/lib/RouterContext";
|
||||
|
||||
export interface Middleware {
|
||||
renderRouterContext?: (previous: RouterContext, props: React.Props<{}>) => RouterContext;
|
||||
renderRouteComponent?: (previous: Router.RouteComponent, props: React.Props<{}>) => Router.RouteComponent;
|
||||
renderRouterContext?: (previous: RouterContext, props: any) => RouterContext;
|
||||
renderRouteComponent?: (previous: RouteComponent, props: any) => RouteComponent;
|
||||
}
|
||||
export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => RouterContext;
|
||||
|
||||
export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: any) => RouterContext;
|
||||
|
||||
4
react-router/lib/browserHistory.d.ts
vendored
4
react-router/lib/browserHistory.d.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import { History } from './routerHistory';
|
||||
import { History } from "history";
|
||||
|
||||
declare const browserHistory: History;
|
||||
|
||||
export default browserHistory;
|
||||
|
||||
6
react-router/lib/createMemoryHistory.d.ts
vendored
6
react-router/lib/createMemoryHistory.d.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import * as H from 'history';
|
||||
import { History, CreateHistory } from "history";
|
||||
|
||||
export default function createMemoryHistory(options?: H.HistoryOptions): H.History;
|
||||
declare const createMemoryHistory: CreateHistory<History>;
|
||||
|
||||
export default createMemoryHistory;
|
||||
|
||||
4
react-router/lib/hashHistory.d.ts
vendored
4
react-router/lib/hashHistory.d.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import { History } from './routerHistory';
|
||||
import { History } from "history";
|
||||
|
||||
declare const hashHistory: History;
|
||||
|
||||
export default hashHistory;
|
||||
|
||||
25
react-router/lib/match.d.ts
vendored
25
react-router/lib/match.d.ts
vendored
@@ -1,17 +1,16 @@
|
||||
import * as H from 'history';
|
||||
import Router from './Router';
|
||||
import { History } from "history";
|
||||
import { Basename, LocationDescriptor, ParseQueryString, RouteConfig, StringifyQuery } from "react-router";
|
||||
|
||||
interface MatchArgs {
|
||||
routes?: Router.RouteConfig;
|
||||
history?: H.History;
|
||||
location?: H.Location | string;
|
||||
parseQueryString?: Router.ParseQueryString;
|
||||
stringifyQuery?: Router.StringifyQuery;
|
||||
routes: RouteConfig;
|
||||
location: LocationDescriptor;
|
||||
history?: History;
|
||||
basename?: Basename;
|
||||
parseQueryString?: ParseQueryString;
|
||||
stringifyQuery?: StringifyQuery;
|
||||
}
|
||||
interface MatchState extends Router.RouterState {
|
||||
history: H.History;
|
||||
router: Router;
|
||||
createElement: (component: Router.RouteComponent, props: Object) => any;
|
||||
}
|
||||
export default function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void;
|
||||
|
||||
export type MatchCallback = (error: any, redirectLocation: Location, renderProps: any) => void;
|
||||
|
||||
export default function match(args: MatchArgs, cb: MatchCallback): void;
|
||||
|
||||
|
||||
8
react-router/lib/useRouterHistory.d.ts
vendored
8
react-router/lib/useRouterHistory.d.ts
vendored
@@ -1,7 +1,5 @@
|
||||
import { History, HistoryOptions, HistoryQueries, CreateHistory } from 'history';
|
||||
import { History, CreateHistoryEnhancer } from "history";
|
||||
|
||||
interface CreateRouterHistory {
|
||||
(options?: HistoryOptions): History & HistoryQueries;
|
||||
}
|
||||
declare const useRouterHistory: CreateHistoryEnhancer<History, any>;
|
||||
|
||||
export default function useRouterHistory<T>(createHistory: CreateHistory<T>): CreateRouterHistory;
|
||||
export default useRouterHistory;
|
||||
|
||||
11
react-router/lib/withRouter.d.ts
vendored
11
react-router/lib/withRouter.d.ts
vendored
@@ -1,4 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import { ComponentClass, StatelessComponent } from "react";
|
||||
|
||||
declare function withRouter<C extends React.ComponentClass<any> | React.StatelessComponent<any> | React.PureComponent<any, any>>(component: C): C
|
||||
export default withRouter;
|
||||
interface Options {
|
||||
withRef?: boolean;
|
||||
}
|
||||
|
||||
type ComponentConstructor<P> = ComponentClass<P> | StatelessComponent<P>;
|
||||
|
||||
export default function withRouter<P>(component: ComponentConstructor<P>, options?: Options): ComponentClass<P>;
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
import * as React from "react"
|
||||
import * as ReactDOM from "react-dom"
|
||||
import {renderToString} from "react-dom/server";
|
||||
import * as React from "react";
|
||||
import { Component, ValidationMap } from "react";
|
||||
import * as ReactDOM from "react-dom";
|
||||
import { renderToString } from "react-dom/server";
|
||||
|
||||
import { applyRouterMiddleware, browserHistory, hashHistory, match, createMemoryHistory, withRouter, routerShape, Router, Route, IndexRoute, InjectedRouter, Link, RouterOnContext, RouterContext, LinkProps} from "react-router";
|
||||
import {
|
||||
applyRouterMiddleware,
|
||||
browserHistory,
|
||||
hashHistory,
|
||||
match,
|
||||
createMemoryHistory,
|
||||
withRouter,
|
||||
routerShape,
|
||||
Router,
|
||||
Route,
|
||||
IndexRoute,
|
||||
InjectedRouter,
|
||||
Link,
|
||||
RouterContext,
|
||||
LinkProps
|
||||
} from "react-router";
|
||||
|
||||
const NavLink = (props: LinkProps) => (
|
||||
<Link {...props} activeClassName="active" />
|
||||
)
|
||||
|
||||
interface MasterContext {
|
||||
router: RouterOnContext;
|
||||
router: InjectedRouter;
|
||||
}
|
||||
|
||||
class Master extends React.Component<React.Props<{}>, {}> {
|
||||
class Master extends Component<any, any> {
|
||||
|
||||
static contextTypes: React.ValidationMap<any> = {
|
||||
router: routerShape
|
||||
static contextTypes: ValidationMap<any> = {
|
||||
"router": routerShape
|
||||
};
|
||||
|
||||
context: MasterContext;
|
||||
|
||||
navigate() {
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
"strictNullChecks": false,
|
||||
"jsx": "react",
|
||||
"baseUrl": "../",
|
||||
"paths": {
|
||||
"history": ["history/v2"]
|
||||
},
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
|
||||
91
react-router/v2/index.d.ts
vendored
Normal file
91
react-router/v2/index.d.ts
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// Type definitions for react-router v2.0.0
|
||||
// Project: https://github.com/rackt/react-router
|
||||
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>, Nathan Brown <https://github.com/ngbrown>, Alex Wendland <https://github.com/awendland>, Kostya Esmukov <https://github.com/KostyaEsmukov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="history" />
|
||||
|
||||
export as namespace ReactRouter;
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export const routerShape: React.Requireable<any>
|
||||
|
||||
export const locationShape: React.Requireable<any>
|
||||
|
||||
import Router from "./lib/Router";
|
||||
import Link from "./lib/Link";
|
||||
import IndexLink from "./lib/IndexLink";
|
||||
import IndexRedirect from "./lib/IndexRedirect";
|
||||
import IndexRoute from "./lib/IndexRoute";
|
||||
import Redirect from "./lib/Redirect";
|
||||
import Route from "./lib/Route";
|
||||
import * as History from "./lib/routerHistory";
|
||||
import Lifecycle from "./lib/Lifecycle";
|
||||
import RouteContext from "./lib/RouteContext";
|
||||
import browserHistory from "./lib/browserHistory";
|
||||
import hashHistory from "./lib/hashHistory";
|
||||
import useRoutes from "./lib/useRoutes";
|
||||
import { createRoutes } from "./lib/RouteUtils";
|
||||
import { formatPattern } from "./lib/PatternUtils";
|
||||
import RouterContext from "./lib/RouterContext";
|
||||
import PropTypes from "./lib/PropTypes";
|
||||
import match from "./lib/match";
|
||||
import useRouterHistory from "./lib/useRouterHistory";
|
||||
import createMemoryHistory from "./lib/createMemoryHistory";
|
||||
import withRouter from "./lib/withRouter";
|
||||
import applyRouterMiddleware from "./lib/applyRouterMiddleware";
|
||||
|
||||
// PlainRoute is defined in the API documented at:
|
||||
// https://github.com/rackt/react-router/blob/master/docs/API.md
|
||||
// but not included in any of the .../lib modules above.
|
||||
export type PlainRoute = Router.PlainRoute;
|
||||
|
||||
// The following definitions are also very useful to export
|
||||
// because by using these types lots of potential type errors
|
||||
// can be exposed:
|
||||
export type EnterHook = Router.EnterHook;
|
||||
export type LeaveHook = Router.LeaveHook;
|
||||
export type ParseQueryString = Router.ParseQueryString;
|
||||
export type LocationDescriptor = Router.LocationDescriptor;
|
||||
export type RedirectFunction = Router.RedirectFunction;
|
||||
export type RouteComponent = Router.RouteComponent;
|
||||
export type RouteComponentProps<P, R> = Router.RouteComponentProps<P, R>;
|
||||
export type RouteConfig = Router.RouteConfig;
|
||||
export type RouteHook = Router.RouteHook;
|
||||
export type StringifyQuery = Router.StringifyQuery;
|
||||
export type RouterListener = Router.RouterListener;
|
||||
export type RouterState = Router.RouterState;
|
||||
export type InjectedRouter = Router.InjectedRouter;
|
||||
|
||||
export type HistoryBase = History.HistoryBase;
|
||||
export type RouterOnContext = Router.RouterOnContext;
|
||||
export type RouteProps = Route.RouteProps;
|
||||
export type LinkProps = Link.LinkProps;
|
||||
|
||||
export {
|
||||
Router,
|
||||
Link,
|
||||
IndexLink,
|
||||
IndexRedirect,
|
||||
IndexRoute,
|
||||
Redirect,
|
||||
Route,
|
||||
History,
|
||||
browserHistory,
|
||||
hashHistory,
|
||||
Lifecycle,
|
||||
RouteContext,
|
||||
useRoutes,
|
||||
createRoutes,
|
||||
formatPattern,
|
||||
RouterContext,
|
||||
PropTypes,
|
||||
match,
|
||||
useRouterHistory,
|
||||
createMemoryHistory,
|
||||
withRouter,
|
||||
applyRouterMiddleware
|
||||
};
|
||||
|
||||
export default Router;
|
||||
5
react-router/v2/lib/IndexLink.d.ts
vendored
Normal file
5
react-router/v2/lib/IndexLink.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import Link from './Link';
|
||||
|
||||
declare const IndexLink: Link;
|
||||
export default IndexLink;
|
||||
|
||||
17
react-router/v2/lib/IndexRedirect.d.ts
vendored
Normal file
17
react-router/v2/lib/IndexRedirect.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import Router from './Router';
|
||||
import * as React from 'react';
|
||||
import * as H from 'history';
|
||||
|
||||
declare const self: self.IndexRedirect;
|
||||
type self = self.IndexRedirect;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface IndexRedirectProps extends React.Props<self> {
|
||||
to: Router.RoutePattern;
|
||||
query?: H.Query;
|
||||
state?: H.LocationState;
|
||||
}
|
||||
interface IndexRedirectElement extends React.ReactElement<IndexRedirectProps> { }
|
||||
interface IndexRedirect extends React.ComponentClass<self.IndexRedirectProps> { }
|
||||
}
|
||||
20
react-router/v2/lib/IndexRoute.d.ts
vendored
Normal file
20
react-router/v2/lib/IndexRoute.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import * as H from 'history';
|
||||
|
||||
declare const self: self.IndexRoute;
|
||||
type self = self.IndexRoute;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface IndexRouteProps extends React.Props<IndexRoute> {
|
||||
component?: Router.RouteComponent;
|
||||
components?: Router.RouteComponents;
|
||||
getComponent?: (location: H.Location, cb: (error: any, component?: Router.RouteComponent) => void) => void;
|
||||
getComponents?: (location: H.Location, cb: (error: any, components?: Router.RouteComponents) => void) => void;
|
||||
onEnter?: Router.EnterHook;
|
||||
onLeave?: Router.LeaveHook;
|
||||
}
|
||||
interface IndexRoute extends React.ComponentClass<IndexRouteProps> { }
|
||||
interface IndexRouteElement extends React.ReactElement<IndexRouteProps> { }
|
||||
}
|
||||
19
react-router/v2/lib/Link.d.ts
vendored
Normal file
19
react-router/v2/lib/Link.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
|
||||
declare const Link: Link;
|
||||
type Link = Link.Link;
|
||||
|
||||
export default Link;
|
||||
|
||||
declare namespace Link {
|
||||
interface LinkProps extends React.HTMLAttributes<Link> {
|
||||
activeStyle?: React.CSSProperties;
|
||||
activeClassName?: string;
|
||||
onlyActiveOnIndex?: boolean;
|
||||
to: Router.RoutePattern | Router.LocationDescriptor | ((...args: any[]) => Router.LocationDescriptor);
|
||||
}
|
||||
|
||||
interface Link extends React.ComponentClass<LinkProps> {}
|
||||
interface LinkElement extends React.ReactElement<LinkProps> {}
|
||||
}
|
||||
1
react-router/v2/lib/PatternUtils.d.ts
vendored
Normal file
1
react-router/v2/lib/PatternUtils.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export function formatPattern(pattern: string, params: {}): string;
|
||||
19
react-router/v2/lib/PropTypes.d.ts
vendored
Normal file
19
react-router/v2/lib/PropTypes.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export function falsy(props: any, propName: string, componentName: string): Error;
|
||||
export const history: React.Requireable<any>;
|
||||
export const location: React.Requireable<any>;
|
||||
export const component: React.Requireable<any>;
|
||||
export const components: React.Requireable<any>;
|
||||
export const route: React.Requireable<any>;
|
||||
export const routes: React.Requireable<any>;
|
||||
|
||||
export default {
|
||||
falsy,
|
||||
history,
|
||||
location,
|
||||
component,
|
||||
components,
|
||||
route
|
||||
};
|
||||
|
||||
19
react-router/v2/lib/Redirect.d.ts
vendored
Normal file
19
react-router/v2/lib/Redirect.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import * as H from 'history';
|
||||
|
||||
declare const self: self.Redirect;
|
||||
type self = typeof self;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface RedirectProps extends React.Props<Redirect> {
|
||||
path?: Router.RoutePattern;
|
||||
from?: Router.RoutePattern; // alias for path
|
||||
to: Router.RoutePattern;
|
||||
query?: H.Query;
|
||||
state?: H.LocationState;
|
||||
}
|
||||
interface Redirect extends React.ComponentClass<RedirectProps> { }
|
||||
interface RedirectElement extends React.ReactElement<RedirectProps> { }
|
||||
}
|
||||
25
react-router/v2/lib/Route.d.ts
vendored
Normal file
25
react-router/v2/lib/Route.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import { Location } from 'history';
|
||||
|
||||
declare const self: self.Route;
|
||||
type self = self.Route;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
|
||||
interface RouteProps extends React.Props<Route> {
|
||||
path?: Router.RoutePattern;
|
||||
component?: Router.RouteComponent;
|
||||
components?: Router.RouteComponents;
|
||||
getComponent?: (nextState: Router.RouterState, cb: (error: any, component?: Router.RouteComponent) => void) => void
|
||||
getComponents?: (nextState: Router.RouterState, cb: (error: any, components?: Router.RouteComponents) => void) => void
|
||||
onEnter?: Router.EnterHook;
|
||||
onLeave?: Router.LeaveHook;
|
||||
onChange?: Router.ChangeHook;
|
||||
getIndexRoute?: (location: Location, cb: (error: any, indexRoute: Router.RouteConfig) => void) => void;
|
||||
getChildRoutes?: (location: Location, cb: (error: any, childRoutes: Router.RouteConfig) => void) => void;
|
||||
}
|
||||
interface Route extends React.ComponentClass<RouteProps> {}
|
||||
interface RouteElement extends React.ReactElement<RouteProps> {}
|
||||
}
|
||||
8
react-router/v2/lib/RouteUtils.d.ts
vendored
Normal file
8
react-router/v2/lib/RouteUtils.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
|
||||
type E = React.ReactElement<any>;
|
||||
export function isReactChildren(object: E | E[]): boolean;
|
||||
export function createRouteFromReactElement(element: E): Router.PlainRoute;
|
||||
export function createRoutesFromReactChildren(children: E | E[], parentRoute: Router.PlainRoute): Router.PlainRoute[];
|
||||
export function createRoutes(routes: Router.RouteConfig): Router.PlainRoute[];
|
||||
116
react-router/v2/lib/Router.d.ts
vendored
Normal file
116
react-router/v2/lib/Router.d.ts
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
import * as React from 'react';
|
||||
import RouterContext from './RouterContext';
|
||||
import {
|
||||
QueryString, Query,
|
||||
Location, LocationDescriptor, LocationState as HLocationState,
|
||||
History, Href,
|
||||
Pathname, Path } from 'history';
|
||||
|
||||
declare const Router: Router;
|
||||
interface Router extends React.ComponentClass<Router.RouterProps> { }
|
||||
|
||||
export default Router;
|
||||
|
||||
// types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md
|
||||
|
||||
declare namespace Router {
|
||||
type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[];
|
||||
type RoutePattern = string;
|
||||
type RouteComponents = { [key: string]: RouteComponent };
|
||||
|
||||
type ParseQueryString = (queryString: QueryString) => Query;
|
||||
type StringifyQuery = (queryObject: Query) => QueryString;
|
||||
|
||||
type Component = React.ReactType;
|
||||
type RouteComponent = Component;
|
||||
|
||||
type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => void;
|
||||
type LeaveHook = () => void;
|
||||
type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void;
|
||||
type RouteHook = (nextLocation?: Location) => any;
|
||||
|
||||
type Params = { [param: string]: string };
|
||||
|
||||
type RouterListener = (error: Error, nextState: RouterState) => void;
|
||||
|
||||
type LocationDescriptor = {
|
||||
pathname?: Pathname
|
||||
query?: Query
|
||||
hash?: Href
|
||||
state?: HLocationState
|
||||
}
|
||||
|
||||
interface RedirectFunction {
|
||||
(location: LocationDescriptor): void;
|
||||
/**
|
||||
* @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated
|
||||
*/
|
||||
(state: HLocationState, pathname: Pathname | Path, query?: Query): void;
|
||||
}
|
||||
|
||||
interface RouterState {
|
||||
location: Location;
|
||||
routes: PlainRoute[];
|
||||
params: Params;
|
||||
components: RouteComponent[];
|
||||
}
|
||||
|
||||
interface RouterProps extends React.Props<Router> {
|
||||
history?: History;
|
||||
routes?: RouteConfig; // alias for children
|
||||
createElement?: (component: RouteComponent, props: Object) => any;
|
||||
onError?: (error: any) => any;
|
||||
onUpdate?: () => any;
|
||||
parseQueryString?: ParseQueryString;
|
||||
stringifyQuery?: StringifyQuery;
|
||||
basename?: string;
|
||||
render?: (renderProps: React.Props<{}>) => RouterContext;
|
||||
}
|
||||
|
||||
interface PlainRoute {
|
||||
path?: RoutePattern;
|
||||
component?: RouteComponent;
|
||||
components?: RouteComponents;
|
||||
getComponent?: (location: Location, cb: (error: any, component?: RouteComponent) => void) => void;
|
||||
getComponents?: (location: Location, cb: (error: any, components?: RouteComponents) => void) => void;
|
||||
onEnter?: EnterHook;
|
||||
onLeave?: LeaveHook;
|
||||
indexRoute?: PlainRoute;
|
||||
getIndexRoute?: (location: Location, cb: (error: any, indexRoute: RouteConfig) => void) => void;
|
||||
childRoutes?: PlainRoute[];
|
||||
getChildRoutes?: (location: Location, cb: (error: any, childRoutes: RouteConfig) => void) => void;
|
||||
}
|
||||
|
||||
interface RouteComponentProps<P, R> {
|
||||
history?: History;
|
||||
location?: Location;
|
||||
params?: P;
|
||||
route?: PlainRoute;
|
||||
routeParams?: R;
|
||||
routes?: PlainRoute[];
|
||||
children?: React.ReactElement<any>;
|
||||
}
|
||||
|
||||
interface RouterOnContext extends History {
|
||||
setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void;
|
||||
isActive(pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean): boolean;
|
||||
}
|
||||
|
||||
// Wrap a component using withRouter(Component) to provide a router object
|
||||
// to the Component's props, allowing the Component to programmatically call
|
||||
// push and other functions.
|
||||
//
|
||||
// https://github.com/reactjs/react-router/blob/v2.4.0/upgrade-guides/v2.4.0.md
|
||||
|
||||
interface InjectedRouter {
|
||||
push: (pathOrLoc: Path | LocationDescriptor) => void
|
||||
replace: (pathOrLoc: Path | LocationDescriptor) => void
|
||||
go: (n: number) => void
|
||||
goBack: () => void
|
||||
goForward: () => void
|
||||
setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void
|
||||
createPath(path: History.Path, query?: History.Query): History.Path
|
||||
createHref(path: History.Path, query?: History.Query): History.Href
|
||||
isActive: (pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean) => boolean
|
||||
}
|
||||
}
|
||||
25
react-router/v2/lib/RouterContext.d.ts
vendored
Normal file
25
react-router/v2/lib/RouterContext.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as React from 'react';
|
||||
import * as H from 'history';
|
||||
import Router from './Router';
|
||||
|
||||
declare const self: self.RouterContext;
|
||||
type self = self.RouterContext;
|
||||
export default self;
|
||||
|
||||
declare namespace self {
|
||||
interface RouterContextProps extends React.Props<RouterContext> {
|
||||
history?: H.History;
|
||||
router: Router;
|
||||
createElement: (component: Router.RouteComponent, props: Object) => any;
|
||||
location: H.Location;
|
||||
routes: Router.RouteConfig;
|
||||
params: Router.Params;
|
||||
components?: Router.RouteComponent[];
|
||||
}
|
||||
interface RouterContext extends React.ComponentClass<RouterContextProps> {}
|
||||
interface RouterContextElement extends React.ReactElement<RouterContextProps> {
|
||||
history?: H.History;
|
||||
location: H.Location;
|
||||
router?: Router;
|
||||
}
|
||||
}
|
||||
9
react-router/v2/lib/applyRouterMiddleware.d.ts
vendored
Normal file
9
react-router/v2/lib/applyRouterMiddleware.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import RouterContext from './RouterContext';
|
||||
|
||||
export interface Middleware {
|
||||
renderRouterContext?: (previous: RouterContext, props: React.Props<{}>) => RouterContext;
|
||||
renderRouteComponent?: (previous: Router.RouteComponent, props: React.Props<{}>) => Router.RouteComponent;
|
||||
}
|
||||
export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => RouterContext;
|
||||
3
react-router/v2/lib/browserHistory.d.ts
vendored
Normal file
3
react-router/v2/lib/browserHistory.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { History } from './routerHistory';
|
||||
declare const browserHistory: History;
|
||||
export default browserHistory;
|
||||
3
react-router/v2/lib/createMemoryHistory.d.ts
vendored
Normal file
3
react-router/v2/lib/createMemoryHistory.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as H from 'history';
|
||||
|
||||
export default function createMemoryHistory(options?: H.HistoryOptions): H.History;
|
||||
3
react-router/v2/lib/hashHistory.d.ts
vendored
Normal file
3
react-router/v2/lib/hashHistory.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { History } from './routerHistory';
|
||||
declare const hashHistory: History;
|
||||
export default hashHistory;
|
||||
17
react-router/v2/lib/match.d.ts
vendored
Normal file
17
react-router/v2/lib/match.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as H from 'history';
|
||||
import Router from './Router';
|
||||
|
||||
interface MatchArgs {
|
||||
routes?: Router.RouteConfig;
|
||||
history?: H.History;
|
||||
location?: H.Location | string;
|
||||
parseQueryString?: Router.ParseQueryString;
|
||||
stringifyQuery?: Router.StringifyQuery;
|
||||
}
|
||||
interface MatchState extends Router.RouterState {
|
||||
history: H.History;
|
||||
router: Router;
|
||||
createElement: (component: Router.RouteComponent, props: Object) => any;
|
||||
}
|
||||
export default function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void;
|
||||
|
||||
7
react-router/v2/lib/useRouterHistory.d.ts
vendored
Normal file
7
react-router/v2/lib/useRouterHistory.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { History, HistoryOptions, HistoryQueries, CreateHistory } from 'history';
|
||||
|
||||
interface CreateRouterHistory {
|
||||
(options?: HistoryOptions): History & HistoryQueries;
|
||||
}
|
||||
|
||||
export default function useRouterHistory<T>(createHistory: CreateHistory<T>): CreateRouterHistory;
|
||||
4
react-router/v2/lib/withRouter.d.ts
vendored
Normal file
4
react-router/v2/lib/withRouter.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import * as React from 'react';
|
||||
|
||||
declare function withRouter<C extends React.ComponentClass<any> | React.StatelessComponent<any> | React.PureComponent<any, any>>(component: C): C
|
||||
export default withRouter;
|
||||
Reference in New Issue
Block a user