mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Update react-router 0.13.3 -> 1.0.0-rc1
This commit is contained in:
Vendored
+152
@@ -0,0 +1,152 @@
|
||||
// Type definitions for history v1.11.1
|
||||
// Project: https://github.com/rackt/history
|
||||
// Definitions by: Sergey Buturlakin <http://github.com/sergey-buturlakin>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
declare namespace HistoryModule {
|
||||
|
||||
// types based on https://github.com/rackt/history/blob/master/docs/Terms.md
|
||||
|
||||
type Action = string
|
||||
|
||||
type BeforeUnloadHook = () => string
|
||||
|
||||
type CreateHistory = (options: HistoryOptions) => History
|
||||
|
||||
type CreateHistoryEnhancer = (createHistory: CreateHistory) => CreateHistory
|
||||
|
||||
interface History {
|
||||
listenBefore: (hook: TransitionHook) => Function
|
||||
listen: (listener: LocationListener) => Function
|
||||
transitionTo(location: Location): void
|
||||
pushState(state: LocationState, path: Path): void
|
||||
replaceState(state: LocationState, path: Path): void
|
||||
setState(state: LocationState): void
|
||||
go(n: number): void
|
||||
goBack(): void
|
||||
goForward(): void
|
||||
createKey(): LocationKey
|
||||
createPath(path: Path): Path
|
||||
createHref(path: Path): Href
|
||||
}
|
||||
|
||||
type HistoryOptions = Object
|
||||
|
||||
type Href = string
|
||||
|
||||
type Location = {
|
||||
pathname: Pathname
|
||||
search: QueryString
|
||||
query: Query
|
||||
state: LocationState
|
||||
action: Action
|
||||
key: LocationKey
|
||||
}
|
||||
|
||||
type LocationKey = string
|
||||
|
||||
type LocationListener = (location: Location) => void
|
||||
|
||||
type LocationState = Object
|
||||
|
||||
type Path = string // Pathname + QueryString
|
||||
|
||||
type Pathname = string
|
||||
|
||||
type QueryString = string
|
||||
|
||||
type Query = Object
|
||||
|
||||
type TransitionHook = (location: Location, callback: Function) => any
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createBrowserHistory" {
|
||||
|
||||
export default function createBrowserHistory(): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createHashHistory" {
|
||||
|
||||
export default function createHashHistory(): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createMemoryHistory" {
|
||||
|
||||
export default function createMemoryHistory(): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createLocation" {
|
||||
|
||||
export default function createLocation(): HistoryModule.Location
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useBasename" {
|
||||
|
||||
export default function useBasename(enhancer: HistoryModule.CreateHistoryEnhancer): HistoryModule.CreateHistory
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useBeforeUnload" {
|
||||
|
||||
export default function useBeforeUnload(enhancer: HistoryModule.CreateHistoryEnhancer): HistoryModule.CreateHistory
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useQueries" {
|
||||
|
||||
export default function useQueries(enhancer: HistoryModule.CreateHistoryEnhancer): HistoryModule.CreateHistory
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/actions" {
|
||||
|
||||
export const PUSH: string
|
||||
|
||||
export const REPLACE: string
|
||||
|
||||
export const POP: string
|
||||
|
||||
export default {
|
||||
PUSH,
|
||||
REPLACE,
|
||||
POP
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history" {
|
||||
|
||||
export { default as createHistory } from "history/lib/createBrowserHistory"
|
||||
|
||||
export { default as createHashHistory } from "history/lib/createHashHistory"
|
||||
|
||||
export { default as createMemoryHistory } from "history/lib/createMemoryHistory"
|
||||
|
||||
export { default as createLocation } from "history/lib/createLocation"
|
||||
|
||||
export { default as useBasename } from "history/lib/useBasename"
|
||||
|
||||
export { default as useBeforeUnload } from "history/lib/useBeforeUnload"
|
||||
|
||||
export { default as useQueries } from "history/lib/useQueries"
|
||||
|
||||
import * as Actions from "history/lib/actions"
|
||||
|
||||
export { Actions }
|
||||
|
||||
}
|
||||
@@ -1,425 +0,0 @@
|
||||
///<reference path="react-router.d.ts" />
|
||||
"use strict";
|
||||
|
||||
import React = require('react');
|
||||
import ReactAddons = require('react/addons');
|
||||
import Router = require('react-router');
|
||||
|
||||
// Mixin
|
||||
class NavigationTest<T extends Router.Navigation> {
|
||||
v: T;
|
||||
|
||||
makePath() {
|
||||
var v1: string = this.v.makePath('to');
|
||||
var v2: string = this.v.makePath('to', {id: 1});
|
||||
var v3: string = this.v.makePath('to', {id: 1}, {type: 'json'});
|
||||
}
|
||||
makeHref() {
|
||||
var v1: string = this.v.makeHref('to');
|
||||
var v2: string = this.v.makeHref('to', {id: 1});
|
||||
var v3: string = this.v.makeHref('to', {id: 1}, {type: 'json'});
|
||||
}
|
||||
transitionTo() {
|
||||
var v1: void = this.v.transitionTo('to');
|
||||
var v2: void = this.v.transitionTo('to', {id: 1});
|
||||
var v3: void = this.v.transitionTo('to', {id: 1}, {type: 'json'});
|
||||
}
|
||||
replaceWith() {
|
||||
var v1: void = this.v.replaceWith('to');
|
||||
var v2: void = this.v.replaceWith('to', {id: 1});
|
||||
var v3: void = this.v.replaceWith('to', {id: 1}, {type: 'json'});
|
||||
}
|
||||
goBack() {
|
||||
var v1: void = this.v.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
class StateTest<T extends Router.State> {
|
||||
v: T;
|
||||
|
||||
getPath() {
|
||||
var v1: string = this.v.getPath();
|
||||
}
|
||||
|
||||
getRoutes() {
|
||||
var v1: Router.Route[] = this.v.getRoutes();
|
||||
}
|
||||
|
||||
getPathname() {
|
||||
var v1: string = this.v.getPathname();
|
||||
}
|
||||
|
||||
getParams() {
|
||||
var v1: {} = this.v.getParams();
|
||||
}
|
||||
|
||||
getQuery() {
|
||||
var v1: {} = this.v.getQuery();
|
||||
}
|
||||
|
||||
isActive() {
|
||||
var v1: boolean = this.v.isActive('to');
|
||||
var v2: boolean = this.v.isActive('to', {id: 1});
|
||||
var v3: boolean = this.v.isActive('to', {id: 1}, {type: 'json'});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Location
|
||||
class LocationTest<T extends Router.Location> {
|
||||
v: T;
|
||||
|
||||
push() {
|
||||
var v1: void = this.v.push('path/to/hoge');
|
||||
}
|
||||
|
||||
replace() {
|
||||
var v1: void = this.v.replace('path/to/hoge');
|
||||
}
|
||||
|
||||
pop() {
|
||||
var v1: void = this.v.pop();
|
||||
}
|
||||
|
||||
getCurrentPath() {
|
||||
var v1: void = this.v.getCurrentPath();
|
||||
}
|
||||
}
|
||||
new LocationTest<Router.HashLocation>();
|
||||
new LocationTest<Router.HistoryLocation>();
|
||||
new LocationTest<Router.RefreshLocation>();
|
||||
|
||||
class LocationListenerTest<T extends Router.LocationListener> {
|
||||
v: T;
|
||||
|
||||
addChangeListener() {
|
||||
var v1: void = this.v.addChangeListener(() => console.log(1));
|
||||
}
|
||||
|
||||
removeChangeListener() {
|
||||
var v1: void = this.v.removeChangeListener(() => console.log(1));
|
||||
}
|
||||
}
|
||||
new LocationListenerTest<Router.HashLocation>();
|
||||
new LocationListenerTest<Router.HistoryLocation>();
|
||||
|
||||
|
||||
// Behavior
|
||||
class ScrollBehaviorTest<T extends Router.ScrollBehaviorBase> {
|
||||
v: T;
|
||||
|
||||
updateScrollPosition() {
|
||||
var v1: void = this.v.updateScrollPosition({x: 33, y: 102}, 'scrollTop');
|
||||
}
|
||||
}
|
||||
new ScrollBehaviorTest<Router.ImitateBrowserBehavior>();
|
||||
new ScrollBehaviorTest<Router.ScrollToTopBehavior>();
|
||||
|
||||
|
||||
// Component
|
||||
class DefaultRouteTest {
|
||||
v: Router.DefaultRoute;
|
||||
|
||||
props() {
|
||||
var name: string = this.v.props.name;
|
||||
var handler: React.ComponentClass<any> = this.v.props.handler;
|
||||
}
|
||||
|
||||
createElement() {
|
||||
var Handler: React.ComponentClass<any>;
|
||||
React.createElement(Router.DefaultRoute, null);
|
||||
React.createElement(Router.DefaultRoute, {name: 'name', handler: Handler});
|
||||
|
||||
ReactAddons.createElement(Router.DefaultRoute, null);
|
||||
ReactAddons.createElement(Router.DefaultRoute, {name: 'name', handler: Handler});
|
||||
}
|
||||
}
|
||||
|
||||
class LinkTest {
|
||||
v: Router.Link;
|
||||
|
||||
constructor() {
|
||||
new NavigationTest<Router.Link>();
|
||||
new StateTest<Router.Link>();
|
||||
}
|
||||
|
||||
props() {
|
||||
var activeClassName: string = this.v.props.activeClassName;
|
||||
var to: string = this.v.props.to;
|
||||
var params: {} = this.v.props.params;
|
||||
var query: {} = this.v.props.query;
|
||||
var onClick: Function = this.v.props.onClick;
|
||||
}
|
||||
|
||||
getHref() {
|
||||
var v1: string = this.v.getHref();
|
||||
}
|
||||
|
||||
getClassName() {
|
||||
var v1: string = this.v.getClassName();
|
||||
}
|
||||
|
||||
createElement() {
|
||||
React.createElement(Router.Link, null);
|
||||
React.createElement(Router.Link, {to: 'home'});
|
||||
React.createElement(Router.Link, {
|
||||
activeClassName: 'name',
|
||||
to: 'home',
|
||||
params: {},
|
||||
query: {},
|
||||
onClick: () => console.log(1)
|
||||
});
|
||||
|
||||
ReactAddons.createElement(Router.Link, null);
|
||||
ReactAddons.createElement(Router.Link, {to: 'home'});
|
||||
ReactAddons.createElement(Router.Link, {
|
||||
activeClassName: 'name',
|
||||
to: 'home',
|
||||
params: {},
|
||||
query: {},
|
||||
onClick: () => console.log(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class NotFoundRouteTest {
|
||||
v: Router.NotFoundRoute;
|
||||
|
||||
props() {
|
||||
var name: string = this.v.props.name;
|
||||
var handler: React.ComponentClass<any> = this.v.props.handler;
|
||||
}
|
||||
|
||||
createElement() {
|
||||
var Handler: React.ComponentClass<any>;
|
||||
React.createElement(Router.NotFoundRoute, null);
|
||||
React.createElement(Router.NotFoundRoute, {handler: Handler});
|
||||
React.createElement(Router.NotFoundRoute, {handler: Handler, name: "home"});
|
||||
|
||||
ReactAddons.createElement(Router.NotFoundRoute, null);
|
||||
ReactAddons.createElement(Router.NotFoundRoute, {handler: Handler});
|
||||
ReactAddons.createElement(Router.NotFoundRoute, {handler: Handler, name: "home"});
|
||||
}
|
||||
}
|
||||
|
||||
class RedirectTest {
|
||||
v: Router.Redirect;
|
||||
|
||||
props() {
|
||||
var path: string = this.v.props.path;
|
||||
var from: string = this.v.props.from;
|
||||
var to: string = this.v.props.to;
|
||||
}
|
||||
|
||||
createElement() {
|
||||
React.createElement(Router.Redirect, null);
|
||||
React.createElement(Router.Redirect, {});
|
||||
React.createElement(Router.Redirect, {path: 'a', from: 'a', to: 'b'});
|
||||
|
||||
ReactAddons.createElement(Router.Redirect, null);
|
||||
ReactAddons.createElement(Router.Redirect, {});
|
||||
ReactAddons.createElement(Router.Redirect, {path: 'a', from: 'a', to: 'b'});
|
||||
}
|
||||
}
|
||||
|
||||
class RouteTest {
|
||||
v: Router.Route;
|
||||
|
||||
props() {
|
||||
var name: string = this.v.props.name;
|
||||
var path: string = this.v.props.path;
|
||||
var handler: React.ComponentClass<any> = this.v.props.handler;
|
||||
var ignoreScrollBehavior: boolean = this.v.props.ignoreScrollBehavior;
|
||||
}
|
||||
|
||||
createElement() {
|
||||
var Handler: React.ComponentClass<any>;
|
||||
React.createElement(Router.Route, null);
|
||||
React.createElement(Router.Route, {});
|
||||
React.createElement(Router.Route, {name: "home", path: "/", handler: Handler, ignoreScrollBehavior: true});
|
||||
|
||||
ReactAddons.createElement(Router.Route, null);
|
||||
ReactAddons.createElement(Router.Route, {});
|
||||
ReactAddons.createElement(Router.Route, {name: "home", path: "/", handler: Handler, ignoreScrollBehavior: true});
|
||||
}
|
||||
}
|
||||
|
||||
class RouteHandlerTest {
|
||||
v: Router.RouteHandler;
|
||||
|
||||
createElement() {
|
||||
React.createElement(Router.RouteHandler, null);
|
||||
React.createElement(Router.RouteHandler, {});
|
||||
|
||||
ReactAddons.createElement(Router.RouteHandler, null);
|
||||
ReactAddons.createElement(Router.RouteHandler, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// History
|
||||
class HistoryTest {
|
||||
v: Router.History;
|
||||
|
||||
length() {
|
||||
var v1: number = this.v.length;
|
||||
}
|
||||
|
||||
back() {
|
||||
var v1: void = this.v.back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Router
|
||||
class CreateTest {
|
||||
v: Router.Router;
|
||||
|
||||
constructor() {
|
||||
// React.createElement() version
|
||||
this.v = Router.create({
|
||||
routes: React.createElement(Router.Route, null)
|
||||
});
|
||||
this.v = Router.create({
|
||||
routes: React.createElement(Router.Route, null),
|
||||
location: Router.HistoryLocation,
|
||||
scrollBehavior: Router.ImitateBrowserBehavior
|
||||
});
|
||||
|
||||
// React.createFactory() version
|
||||
this.v = Router.create({
|
||||
routes: React.createFactory(Router.Route)()
|
||||
});
|
||||
this.v = Router.create({
|
||||
routes: React.createFactory(Router.Route)(),
|
||||
location: Router.HistoryLocation,
|
||||
scrollBehavior: Router.ImitateBrowserBehavior
|
||||
});
|
||||
}
|
||||
|
||||
run() {
|
||||
this.v.run((Handler) => console.log(Handler));
|
||||
this.v.run((Handler, state) => console.log(Handler, state));
|
||||
}
|
||||
}
|
||||
|
||||
class RunTest {
|
||||
constructor() {
|
||||
// React.createElement() version
|
||||
var v1: Router.Router = Router.run(React.createElement(Router.Route, null), (Handler) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v2: Router.Router = Router.run(React.createElement(Router.Route, null), Router.HistoryLocation, (Handler, state) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v3: Router.Router = Router.run(React.createElement(Router.Route, null), '/foo/bar', (Handler, state) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
|
||||
// React.createFactory() version
|
||||
var v4: Router.Router = Router.run(React.createFactory(Router.Route)(), (Handler) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v5: Router.Router = Router.run(React.createFactory(Router.Route)(), Router.HistoryLocation, (Handler, state) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v6: Router.Router = Router.run(React.createFactory(Router.Route)(), '/foo/bar', (Handler, state) => {
|
||||
React.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Transition
|
||||
class TransitionTest {
|
||||
constructor() {
|
||||
var v1: Router.TransitionStaticLifecycle = {
|
||||
willTransitionTo: (transition, params, query, callback) => {
|
||||
transition.abort();
|
||||
transition.redirect('to');
|
||||
transition.redirect('to', {id: 1});
|
||||
transition.redirect('to', {id: 1}, {type: 'json'});
|
||||
transition.retry();
|
||||
},
|
||||
willTransitionFrom: (transition, component, callback) => {}
|
||||
};
|
||||
var v2: Router.TransitionStaticLifecycle = {
|
||||
willTransitionTo: (transition, params, query) => {},
|
||||
willTransitionFrom: (transition, component) => {}
|
||||
};
|
||||
var v3: Router.TransitionStaticLifecycle = {
|
||||
willTransitionTo: (transition, params) => {},
|
||||
willTransitionFrom: (transition) => {}
|
||||
};
|
||||
var v4: Router.TransitionStaticLifecycle = {
|
||||
willTransitionTo: (transition) => {},
|
||||
willTransitionFrom: () => {}
|
||||
};
|
||||
var v5: Router.TransitionStaticLifecycle = {
|
||||
willTransitionTo: () => {}
|
||||
};
|
||||
var v6: Router.TransitionStaticLifecycle = {
|
||||
willTransitionFrom: () => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Context
|
||||
class ContextTest {
|
||||
v: Router.Context
|
||||
|
||||
makePath() {
|
||||
var v1: string = this.v.makePath('home');
|
||||
var v2: string = this.v.makePath('home', {p1: 1});
|
||||
var v3: string = this.v.makePath('home', {p1: 1}, {q1: 1});
|
||||
}
|
||||
|
||||
makeHref() {
|
||||
var v1: string = this.v.makeHref('home');
|
||||
var v2: string = this.v.makeHref('home', {p1: 1});
|
||||
var v3: string = this.v.makeHref('home', {p1: 1}, {q1: 1});
|
||||
}
|
||||
|
||||
transitionTo() {
|
||||
var v1: void = this.v.transitionTo('home');
|
||||
var v2: void = this.v.transitionTo('home', {p1: 1});
|
||||
var v3: void = this.v.transitionTo('home', {p1: 1}, {q1: 1});
|
||||
}
|
||||
|
||||
replaceWith() {
|
||||
var v1: void = this.v.replaceWith('home');
|
||||
var v2: void = this.v.replaceWith('home', {p1: 1});
|
||||
var v3: void = this.v.replaceWith('home', {p1: 1}, {q1: 1});
|
||||
}
|
||||
|
||||
goBack() {
|
||||
var v: void = this.v.goBack();
|
||||
}
|
||||
|
||||
getCurrentPath() {
|
||||
var v: string = this.v.getCurrentPath();
|
||||
}
|
||||
|
||||
getCurrentRoutes() {
|
||||
var v: Router.Route[] = this.v.getCurrentRoutes();
|
||||
}
|
||||
|
||||
getCurrentPathname() {
|
||||
var v: string = this.v.getCurrentPathname();
|
||||
}
|
||||
|
||||
getCurrentParams() {
|
||||
var v: {} = this.v.getCurrentParams();
|
||||
}
|
||||
|
||||
getCurrentQuery() {
|
||||
var v: {} = this.v.getCurrentQuery();
|
||||
}
|
||||
|
||||
isActive() {
|
||||
var v1: boolean = this.v.isActive('home');
|
||||
var v2: boolean = this.v.isActive('home', {p1: 1});
|
||||
var v3: boolean = this.v.isActive('home', {p1: 1}, {q1: 1});
|
||||
}
|
||||
}
|
||||
Vendored
+271
-299
@@ -1,354 +1,326 @@
|
||||
// Type definitions for React Router 0.13.3
|
||||
// Type definitions for history v1.0.0-rc1
|
||||
// Project: https://github.com/rackt/react-router
|
||||
// Definitions by: Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>
|
||||
// Definitions by: Sergey Buturlakin <http://github.com/sergey-buturlakin>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path='../react/react.d.ts' />
|
||||
|
||||
declare module ReactRouter {
|
||||
import React = __React;
|
||||
///<reference path="../react/react-global.d.ts" />
|
||||
|
||||
//
|
||||
// Transition
|
||||
// ----------------------------------------------------------------------
|
||||
interface Transition {
|
||||
path: string;
|
||||
abortReason: any;
|
||||
retry(): void;
|
||||
abort(reason?: any): void;
|
||||
redirect(to: string, params?: {}, query?: {}): void;
|
||||
cancel(): void;
|
||||
from: (transition: Transition, routes: Route[], components?: React.ReactElement<any>[], callback?: (error?: any) => void) => void;
|
||||
to: (transition: Transition, routes: Route[], params?: {}, query?: {}, callback?: (error?: any) => void) => void;
|
||||
|
||||
declare namespace ReactRouter {
|
||||
|
||||
// types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md
|
||||
|
||||
type Action = string
|
||||
|
||||
type Component = React.ReactType
|
||||
|
||||
type EnterHook = (nextState: RouterState, replaceState: RedirectFunction, callback?: Function) => any
|
||||
|
||||
type LeaveHook = () => any
|
||||
|
||||
interface Location {
|
||||
pathname: Pathname
|
||||
search: QueryString
|
||||
query: Query
|
||||
state: LocationState
|
||||
action: Action
|
||||
key: LocationKey
|
||||
}
|
||||
|
||||
interface TransitionStaticLifecycle {
|
||||
willTransitionTo?(
|
||||
transition: Transition,
|
||||
params: {},
|
||||
query: {},
|
||||
callback: Function
|
||||
): void;
|
||||
type LocationKey = string
|
||||
|
||||
willTransitionFrom?(
|
||||
transition: Transition,
|
||||
component: React.ReactElement<any>,
|
||||
callback: Function
|
||||
): void;
|
||||
type LocationListener = (location: Location) => void
|
||||
|
||||
type LocationState = Object
|
||||
|
||||
type Params = Object
|
||||
|
||||
type Path = string // Pathname + QueryString
|
||||
|
||||
type Pathname = string
|
||||
|
||||
type Query = Object
|
||||
|
||||
type QueryString = string
|
||||
|
||||
type RedirectFunction = (state: LocationState, pathname: Pathname | Path, query?: Query) => void
|
||||
|
||||
interface RouteComponentProps {
|
||||
history?: RouterObject
|
||||
location?: Location
|
||||
params?: Params
|
||||
route?: RouteObject
|
||||
routeParams?: Params
|
||||
routes?: PlainRoute[]
|
||||
}
|
||||
|
||||
//
|
||||
// Route Configuration
|
||||
// ----------------------------------------------------------------------
|
||||
// DefaultRoute
|
||||
interface DefaultRouteProp {
|
||||
name?: string;
|
||||
handler: React.ComponentClass<any>;
|
||||
}
|
||||
interface DefaultRoute extends React.ReactElement<DefaultRouteProp> {}
|
||||
interface DefaultRouteClass extends React.ComponentClass<DefaultRouteProp> {}
|
||||
type RouteComponent = React.ComponentClass<RouteComponentProps>
|
||||
|
||||
// NotFoundRoute
|
||||
interface NotFoundRouteProp {
|
||||
name?: string;
|
||||
handler: React.ComponentClass<any>;
|
||||
}
|
||||
interface NotFoundRoute extends React.ReactElement<NotFoundRouteProp> {}
|
||||
interface NotFoundRouteClass extends React.ComponentClass<NotFoundRouteProp> {}
|
||||
type RouteConfig = RouteObject[]
|
||||
|
||||
// Redirect
|
||||
interface RedirectProp {
|
||||
path?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
}
|
||||
interface Redirect extends React.ReactElement<RedirectProp> {}
|
||||
interface RedirectClass extends React.ComponentClass<RedirectProp> {}
|
||||
type RouteHook = (nextLocation?: Location) => any
|
||||
|
||||
// Route
|
||||
interface RouteProp {
|
||||
name?: string;
|
||||
path?: string;
|
||||
handler?: React.ComponentClass<any>;
|
||||
ignoreScrollBehavior?: boolean;
|
||||
}
|
||||
interface Route extends React.ReactElement<RouteProp> {}
|
||||
interface RouteClass extends React.ComponentClass<RouteProp> {}
|
||||
type RoutePattern = string
|
||||
|
||||
var DefaultRoute: DefaultRouteClass;
|
||||
var NotFoundRoute: NotFoundRouteClass;
|
||||
var Redirect: RedirectClass;
|
||||
var Route: RouteClass;
|
||||
|
||||
interface CreateRouteOptions {
|
||||
name?: string;
|
||||
path?: string;
|
||||
ignoreScrollBehavior?: boolean;
|
||||
isDefault?: boolean;
|
||||
isNotFound?: boolean;
|
||||
onEnter?: (transition: Transition, params: {}, query: {}, callback: Function) => void;
|
||||
onLeave?: (transition: Transition, wtf: any, callback: Function) => void;
|
||||
handler?: Function;
|
||||
parentRoute?: Route;
|
||||
interface RouteObject {
|
||||
component: RouteComponent
|
||||
path: RoutePattern
|
||||
onEnter: EnterHook
|
||||
onLeave: LeaveHook
|
||||
}
|
||||
|
||||
type CreateRouteCallback = (route: Route) => void;
|
||||
|
||||
function createRoute(callback: CreateRouteCallback): Route;
|
||||
function createRoute(options: CreateRouteOptions | string, callback: CreateRouteCallback): Route;
|
||||
function createDefaultRoute(options?: CreateRouteOptions | string): Route;
|
||||
function createNotFoundRoute(options?: CreateRouteOptions | string): Route;
|
||||
|
||||
interface CreateRedirectOptions extends CreateRouteOptions {
|
||||
path?: string;
|
||||
from?: string;
|
||||
to: string;
|
||||
params?: {};
|
||||
query?: {};
|
||||
interface RouterObject {
|
||||
transitionTo: (location: Location) => void
|
||||
pushState: (state: LocationState, pathname: Pathname | Path, query?: Query) => void
|
||||
replaceState: (state: LocationState, pathname: Pathname | Path, query?: Query) => void
|
||||
go(n: Number): void
|
||||
listen(listener: RouterListener): Function
|
||||
match(location: Location, callback: RouterListener): void
|
||||
}
|
||||
function createRedirect(options: CreateRedirectOptions): Redirect;
|
||||
function createRoutesFromReactChildren(children: Route): Route[];
|
||||
|
||||
//
|
||||
// Components
|
||||
// ----------------------------------------------------------------------
|
||||
// Link
|
||||
interface LinkProp extends React.HTMLAttributes {
|
||||
activeClassName?: string;
|
||||
activeStyle?: {};
|
||||
to: string;
|
||||
params?: {};
|
||||
query?: {};
|
||||
}
|
||||
interface Link extends React.ReactElement<LinkProp>, Navigation, State {
|
||||
handleClick(event: any): void;
|
||||
getHref(): string;
|
||||
getClassName(): string;
|
||||
getActiveState(): boolean;
|
||||
}
|
||||
interface LinkClass extends React.ComponentClass<LinkProp> {}
|
||||
|
||||
// RouteHandler
|
||||
interface RouteHandlerProp { }
|
||||
interface RouteHandlerChildContext {
|
||||
routeDepth: number;
|
||||
}
|
||||
interface RouteHandler extends React.ReactElement<RouteHandlerProp> {
|
||||
getChildContext(): RouteHandlerChildContext;
|
||||
getRouteDepth(): number;
|
||||
createChildRouteHandler(props: {}): RouteHandler;
|
||||
}
|
||||
interface RouteHandlerClass extends React.ComponentClass<RouteHandlerProp> {}
|
||||
|
||||
var Link: LinkClass;
|
||||
var RouteHandler: RouteHandlerClass;
|
||||
|
||||
|
||||
//
|
||||
// Top-Level
|
||||
// ----------------------------------------------------------------------
|
||||
interface Router extends React.ReactElement<any> {
|
||||
run(callback: RouterRunCallback): void;
|
||||
}
|
||||
type RouterListener = (error: Error, nextState: RouterState) => void
|
||||
|
||||
interface RouterState {
|
||||
path: string;
|
||||
action: string;
|
||||
pathname: string;
|
||||
params: {};
|
||||
query: {};
|
||||
routes: Route[];
|
||||
location: Location
|
||||
routes: RouteConfig
|
||||
params: Params
|
||||
components: Component[]
|
||||
}
|
||||
|
||||
interface RouterCreateOption {
|
||||
routes: Route;
|
||||
location?: LocationBase;
|
||||
scrollBehavior?: ScrollBehaviorBase;
|
||||
onError?: (error: any) => void;
|
||||
onAbort?: (error: any) => void;
|
||||
|
||||
interface HistoryProp {
|
||||
listen(listener: LocationListener): Function
|
||||
pushState(state: LocationState, path: Path): void
|
||||
replaceState(state: LocationState, path: Path): void
|
||||
go(n: number): void
|
||||
}
|
||||
|
||||
type RouterRunCallback = (Handler: RouteClass, state: RouterState) => void;
|
||||
type RouteType = Route | IndexRoute | PlainRoute | Redirect
|
||||
|
||||
function create(options: RouterCreateOption): Router;
|
||||
function run(routes: Route, callback: RouterRunCallback): Router;
|
||||
function run(routes: Route, location: LocationBase | string, callback: RouterRunCallback): Router;
|
||||
type Components = { [key: string]: Component }
|
||||
|
||||
|
||||
//
|
||||
// Location
|
||||
// ----------------------------------------------------------------------
|
||||
interface LocationBase {
|
||||
getCurrentPath(): void;
|
||||
toString(): string;
|
||||
interface RouterProps {
|
||||
history?: HistoryProp
|
||||
children?: RouteType[]
|
||||
routes?: RouteType[] // alias for children
|
||||
createElement?: (component: Component, props: Object) => any
|
||||
onError?: (err: any) => any
|
||||
onUpdate?: () => any
|
||||
parseQueryString?: (queryString: QueryString) => Query
|
||||
stringifyQuery?: (queryObject: Query) => QueryString
|
||||
}
|
||||
interface Location extends LocationBase {
|
||||
push(path: string): void;
|
||||
replace(path: string): void;
|
||||
pop(): void;
|
||||
interface Router extends React.ComponentClass<RouterProps> {}
|
||||
interface RouterElement extends React.ReactElement<RouterProps> {}
|
||||
const Router: Router
|
||||
|
||||
|
||||
interface LinkProps extends React.HTMLAttributesBase<LinkProps> {
|
||||
activeStyle?: React.CSSProperties
|
||||
activeClassName?: string
|
||||
onlyActiveOnIndex?: boolean
|
||||
to: RoutePattern
|
||||
query?: Query
|
||||
state?: LocationState
|
||||
}
|
||||
interface Link extends React.ComponentClass<LinkProps> {}
|
||||
interface LinkElement extends React.DOMElement<LinkProps> {}
|
||||
const Link: Link
|
||||
|
||||
|
||||
interface RoutePropsBase {
|
||||
children?: RouteType[]
|
||||
ignoreScrollBehavior?: boolean
|
||||
component?: Component
|
||||
components?: Components
|
||||
getComponent?: (location: Location, cb: (err: any, component?: Component) => void) => void
|
||||
getComponents?: (location: Location, cb: (err: any, components?: Components) => void) => void
|
||||
onEnter?: EnterHook
|
||||
onLeave?: LeaveHook
|
||||
}
|
||||
|
||||
interface LocationListener {
|
||||
addChangeListener(listener: Function): void;
|
||||
removeChangeListener(listener: Function): void;
|
||||
interface RouteProps extends RoutePropsBase {
|
||||
path?: RoutePattern
|
||||
}
|
||||
interface Route extends React.ComponentClass<RouteProps> {}
|
||||
interface RouteElement extends React.ReactElement<RouteProps> {}
|
||||
const Route: Route
|
||||
|
||||
|
||||
interface PlainRoute extends RoutePropsBase {
|
||||
childRoutes: RouteType[]
|
||||
getChildRoutes: (location: Location, cb: (err: any, routesArray: RouteType[]) => void) => void
|
||||
}
|
||||
|
||||
interface HashLocation extends Location, LocationListener { }
|
||||
interface HistoryLocation extends Location, LocationListener { }
|
||||
interface RefreshLocation extends Location { }
|
||||
interface StaticLocation extends LocationBase { }
|
||||
interface TestLocation extends Location, LocationListener { }
|
||||
|
||||
var HashLocation: HashLocation;
|
||||
var HistoryLocation: HistoryLocation;
|
||||
var RefreshLocation: RefreshLocation;
|
||||
var StaticLocation: StaticLocation;
|
||||
var TestLocation: TestLocation;
|
||||
interface RedirectProps {
|
||||
path?: RoutePattern
|
||||
from?: RoutePattern // alias for path
|
||||
to: RoutePattern
|
||||
query?: Query
|
||||
state?: LocationState
|
||||
|
||||
|
||||
//
|
||||
// Behavior
|
||||
// ----------------------------------------------------------------------
|
||||
interface ScrollBehaviorBase {
|
||||
updateScrollPosition(position: { x: number; y: number; }, actionType: string): void;
|
||||
}
|
||||
interface ImitateBrowserBehavior extends ScrollBehaviorBase { }
|
||||
interface ScrollToTopBehavior extends ScrollBehaviorBase { }
|
||||
|
||||
var ImitateBrowserBehavior: ImitateBrowserBehavior;
|
||||
var ScrollToTopBehavior: ScrollToTopBehavior;
|
||||
interface Redirect extends React.ReactElement<RedirectProps> {}
|
||||
interface RedirectELement extends React.ReactElement<RedirectELement> {}
|
||||
const Redirect: Redirect
|
||||
|
||||
|
||||
//
|
||||
// Mixin
|
||||
// ----------------------------------------------------------------------
|
||||
interface Navigation {
|
||||
makePath(to: string, params?: {}, query?: {}): string;
|
||||
makeHref(to: string, params?: {}, query?: {}): string;
|
||||
transitionTo(to: string, params?: {}, query?: {}): void;
|
||||
replaceWith(to: string, params?: {}, query?: {}): void;
|
||||
goBack(): void;
|
||||
}
|
||||
interface IndexRouteProps extends RoutePropsBase {}
|
||||
interface IndexRoute extends React.ComponentClass<IndexRouteProps> {}
|
||||
interface IndexRouteElement extends React.ReactElement<IndexRouteProps> {}
|
||||
const IndexRoute: IndexRoute
|
||||
|
||||
interface State {
|
||||
getPath(): string;
|
||||
getRoutes(): Route[];
|
||||
getPathname(): string;
|
||||
getParams(): {};
|
||||
getQuery(): {};
|
||||
isActive(to: string, params?: {}, query?: {}): boolean;
|
||||
}
|
||||
|
||||
var Navigation: Navigation;
|
||||
var State: State;
|
||||
|
||||
|
||||
//
|
||||
// History
|
||||
// ----------------------------------------------------------------------
|
||||
interface History {
|
||||
back(): void;
|
||||
length: number;
|
||||
}
|
||||
var History: History;
|
||||
|
||||
|
||||
//
|
||||
// Context
|
||||
// ----------------------------------------------------------------------
|
||||
interface Context {
|
||||
makePath(to: string, params?: {}, query?: {}): string;
|
||||
makeHref(to: string, params?: {}, query?: {}): string;
|
||||
transitionTo(to: string, params?: {}, query?: {}): void;
|
||||
replaceWith(to: string, params?: {}, query?: {}): void;
|
||||
goBack(): void;
|
||||
|
||||
getCurrentPath(): string;
|
||||
getCurrentRoutes(): Route[];
|
||||
getCurrentPathname(): string;
|
||||
getCurrentParams(): {};
|
||||
getCurrentQuery(): {};
|
||||
isActive(to: string, params?: {}, query?: {}): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Router" {
|
||||
|
||||
export default ReactRouter.Router
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Link" {
|
||||
|
||||
export default ReactRouter.Link
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/IndexRoute" {
|
||||
|
||||
export default ReactRouter.IndexRoute
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Redirect" {
|
||||
|
||||
export default ReactRouter.Redirect
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Route" {
|
||||
|
||||
export default ReactRouter.Route
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/History" {
|
||||
|
||||
const History: any
|
||||
|
||||
export default History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Lifecycle" {
|
||||
|
||||
const Lifecycle: any
|
||||
|
||||
export default Lifecycle
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RouteContext" {
|
||||
|
||||
const RouteContext: any
|
||||
|
||||
export default RouteContext
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/useRoutes" {
|
||||
|
||||
const useRoutes: any
|
||||
|
||||
export default useRoutes
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RouteUtils" {
|
||||
|
||||
export const createRoutes: any
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RoutingContext" {
|
||||
|
||||
const RoutingContext: any
|
||||
|
||||
export default RoutingContext
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/PropTypes" {
|
||||
|
||||
const PropTypes: any
|
||||
|
||||
export default PropTypes
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/match" {
|
||||
|
||||
const match: any
|
||||
|
||||
export default match
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router" {
|
||||
export = ReactRouter;
|
||||
}
|
||||
|
||||
declare module __React {
|
||||
import Router from "react-router/lib/Router"
|
||||
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
import Link from "react-router/lib/Link"
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
import IndexRoute from "react-router/lib/IndexRoute"
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
import Redirect from "react-router/lib/Redirect"
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
import Route from "react-router/lib/Route"
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
import History from "react-router/lib/History"
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
}
|
||||
import Lifecycle from "react-router/lib/Lifecycle"
|
||||
|
||||
declare module "react/addons" {
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
import RouteContext from "react-router/lib/RouteContext"
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
import { createRoutes } from "react-router/lib/RouteUtils"
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
import RoutingContext from "react-router/lib/RoutingContext"
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
import PropTypes from "react-router/lib/PropTypes"
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
import match from "react-router/lib/match"
|
||||
|
||||
export {
|
||||
Router,
|
||||
Link,
|
||||
IndexRoute,
|
||||
Redirect,
|
||||
Route,
|
||||
History,
|
||||
Lifecycle,
|
||||
RouteContext,
|
||||
createRoutes,
|
||||
RoutingContext,
|
||||
PropTypes,
|
||||
match
|
||||
}
|
||||
|
||||
export default Router
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user