mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-24 11:29:30 +08:00
Merge pull request #6073 from sergey-buturlakin/master
Defintitions for react-router v1.0.0
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/// <reference path="../react/react.d.ts"/>
|
||||
/// <reference path="../react/react-dom.d.ts"/>
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
/// <reference path="../react-router/react-router.d.ts" />
|
||||
/// <reference path="../react-router/react-router-0.13.3.d.ts" />
|
||||
/// <reference path="../object-assign/object-assign.d.ts" />
|
||||
|
||||
import { Component, ReactElement } from 'react';
|
||||
|
||||
Vendored
+192
@@ -0,0 +1,192 @@
|
||||
// Type definitions for history v1.13.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 | boolean
|
||||
|
||||
type CreateHistory<T> = (options?: HistoryOptions) => T
|
||||
|
||||
type CreateHistoryEnhancer<T, E> = (createHistory: CreateHistory<T>) => CreateHistory<T & E>
|
||||
|
||||
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
|
||||
push(path: Path): void
|
||||
replace(path: Path): void
|
||||
go(n: number): void
|
||||
goBack(): void
|
||||
goForward(): void
|
||||
createKey(): LocationKey
|
||||
createPath(path: Path): Path
|
||||
createHref(path: Path): Href
|
||||
createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location
|
||||
|
||||
/** @deprecated use location.key to save state instead */
|
||||
setState(state: LocationState): void
|
||||
/** @deprecated use listenBefore instead */
|
||||
registerTransitionHook(hook: TransitionHook): void
|
||||
/** @deprecated use the callback returned from listenBefore instead */
|
||||
unregisterTransitionHook(hook: TransitionHook): void
|
||||
}
|
||||
|
||||
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 Query = Object
|
||||
|
||||
type QueryString = string
|
||||
|
||||
type TransitionHook = (location: Location, callback: Function) => any
|
||||
|
||||
|
||||
interface HistoryBeforeUnload {
|
||||
listenBeforeUnload(hook: BeforeUnloadHook): Function
|
||||
}
|
||||
|
||||
interface HistoryQueries {
|
||||
pushState(state: LocationState, pathname: Pathname | Path, query?: Query): void
|
||||
replaceState(state: LocationState, pathname: Pathname | Path, query?: Query): void
|
||||
createPath(path: Path, query?: Query): Path
|
||||
createHref(path: Path, query?: Query): Href
|
||||
}
|
||||
|
||||
|
||||
// Global usage, without modules, needs the small trick, because lib.d.ts
|
||||
// already has `history` and `History` global definitions:
|
||||
// var createHistory = ((window as any).History as HistoryModule.Module).createHistory;
|
||||
interface Module {
|
||||
createHistory: CreateHistory<History>
|
||||
createHashHistory: CreateHistory<History>
|
||||
createMemoryHistory: CreateHistory<History>
|
||||
createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location
|
||||
useBasename<T>(createHistory: CreateHistory<T>): CreateHistory<T>
|
||||
useBeforeUnload<T>(createHistory: CreateHistory<T>): CreateHistory<T & HistoryBeforeUnload>
|
||||
useQueries<T>(createHistory: CreateHistory<T>): CreateHistory<T & HistoryQueries>
|
||||
actions: {
|
||||
PUSH: string
|
||||
REPLACE: string
|
||||
POP: string
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createBrowserHistory" {
|
||||
|
||||
export default function createBrowserHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createHashHistory" {
|
||||
|
||||
export default function createHashHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createMemoryHistory" {
|
||||
|
||||
export default function createMemoryHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/createLocation" {
|
||||
|
||||
export default function createLocation(path?: HistoryModule.Path, state?: HistoryModule.LocationState, action?: HistoryModule.Action, key?: HistoryModule.LocationKey): HistoryModule.Location
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useBasename" {
|
||||
|
||||
export default function useBasename<T>(createHistory: HistoryModule.CreateHistory<T>): HistoryModule.CreateHistory<T>
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useBeforeUnload" {
|
||||
|
||||
export default function useBeforeUnload<T>(createHistory: HistoryModule.CreateHistory<T>): HistoryModule.CreateHistory<T & HistoryModule.HistoryBeforeUnload>
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "history/lib/useQueries" {
|
||||
|
||||
export default function useQueries<T>(createHistory: HistoryModule.CreateHistory<T>): HistoryModule.CreateHistory<T & HistoryModule.HistoryQueries>
|
||||
|
||||
}
|
||||
|
||||
|
||||
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 }
|
||||
|
||||
}
|
||||
+354
@@ -0,0 +1,354 @@
|
||||
// Type definitions for React Router 0.13.3
|
||||
// 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: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path='../react/react.d.ts' />
|
||||
|
||||
declare module ReactRouter {
|
||||
import React = __React;
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
interface TransitionStaticLifecycle {
|
||||
willTransitionTo?(
|
||||
transition: Transition,
|
||||
params: {},
|
||||
query: {},
|
||||
callback: Function
|
||||
): void;
|
||||
|
||||
willTransitionFrom?(
|
||||
transition: Transition,
|
||||
component: React.ReactElement<any>,
|
||||
callback: Function
|
||||
): void;
|
||||
}
|
||||
|
||||
//
|
||||
// Route Configuration
|
||||
// ----------------------------------------------------------------------
|
||||
// DefaultRoute
|
||||
interface DefaultRouteProp {
|
||||
name?: string;
|
||||
handler: React.ComponentClass<any>;
|
||||
}
|
||||
interface DefaultRoute extends React.ReactElement<DefaultRouteProp> {}
|
||||
interface DefaultRouteClass extends React.ComponentClass<DefaultRouteProp> {}
|
||||
|
||||
// NotFoundRoute
|
||||
interface NotFoundRouteProp {
|
||||
name?: string;
|
||||
handler: React.ComponentClass<any>;
|
||||
}
|
||||
interface NotFoundRoute extends React.ReactElement<NotFoundRouteProp> {}
|
||||
interface NotFoundRouteClass extends React.ComponentClass<NotFoundRouteProp> {}
|
||||
|
||||
// Redirect
|
||||
interface RedirectProp {
|
||||
path?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
}
|
||||
interface Redirect extends React.ReactElement<RedirectProp> {}
|
||||
interface RedirectClass extends React.ComponentClass<RedirectProp> {}
|
||||
|
||||
// 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> {}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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?: {};
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
interface RouterState {
|
||||
path: string;
|
||||
action: string;
|
||||
pathname: string;
|
||||
params: {};
|
||||
query: {};
|
||||
routes: Route[];
|
||||
}
|
||||
|
||||
interface RouterCreateOption {
|
||||
routes: Route;
|
||||
location?: LocationBase;
|
||||
scrollBehavior?: ScrollBehaviorBase;
|
||||
onError?: (error: any) => void;
|
||||
onAbort?: (error: any) => void;
|
||||
}
|
||||
|
||||
type RouterRunCallback = (Handler: RouteClass, state: RouterState) => void;
|
||||
|
||||
function create(options: RouterCreateOption): Router;
|
||||
function run(routes: Route, callback: RouterRunCallback): Router;
|
||||
function run(routes: Route, location: LocationBase | string, callback: RouterRunCallback): Router;
|
||||
|
||||
|
||||
//
|
||||
// Location
|
||||
// ----------------------------------------------------------------------
|
||||
interface LocationBase {
|
||||
getCurrentPath(): void;
|
||||
toString(): string;
|
||||
}
|
||||
interface Location extends LocationBase {
|
||||
push(path: string): void;
|
||||
replace(path: string): void;
|
||||
pop(): void;
|
||||
}
|
||||
|
||||
interface LocationListener {
|
||||
addChangeListener(listener: Function): void;
|
||||
removeChangeListener(listener: Function): 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;
|
||||
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
|
||||
//
|
||||
// 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 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" {
|
||||
export = ReactRouter;
|
||||
}
|
||||
|
||||
declare module __React {
|
||||
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
}
|
||||
|
||||
declare module "react/addons" {
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
///<reference path="react-router.d.ts" />
|
||||
///<reference path='../react/react-dom.d.ts' />
|
||||
"use strict";
|
||||
|
||||
import React = require('react');
|
||||
import ReactDOM = require('react-dom');
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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"});
|
||||
}
|
||||
}
|
||||
|
||||
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'});
|
||||
}
|
||||
}
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
class RouteHandlerTest {
|
||||
v: Router.RouteHandler;
|
||||
|
||||
createElement() {
|
||||
React.createElement(Router.RouteHandler, null);
|
||||
React.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) => {
|
||||
ReactDOM.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v2: Router.Router = Router.run(React.createElement(Router.Route, null), Router.HistoryLocation, (Handler, state) => {
|
||||
ReactDOM.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v3: Router.Router = Router.run(React.createElement(Router.Route, null), '/foo/bar', (Handler, state) => {
|
||||
ReactDOM.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
|
||||
// React.createFactory() version
|
||||
var v4: Router.Router = Router.run(React.createFactory(Router.Route)(), (Handler) => {
|
||||
ReactDOM.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v5: Router.Router = Router.run(React.createFactory(Router.Route)(), Router.HistoryLocation, (Handler, state) => {
|
||||
ReactDOM.render(React.createElement(Handler, null), document.body);
|
||||
});
|
||||
var v6: Router.Router = Router.run(React.createFactory(Router.Route)(), '/foo/bar', (Handler, state) => {
|
||||
ReactDOM.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});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
/// <reference path="../react/react.d.ts" />
|
||||
/// <reference path="../react/react-dom.d.ts" />
|
||||
/// <reference path="./history.d.ts" />
|
||||
/// <reference path="./react-router.d.ts" />
|
||||
|
||||
|
||||
import * as React from "react"
|
||||
import * as ReactDOM from "react-dom"
|
||||
|
||||
import { Router, Route, IndexRoute, Link } from "react-router"
|
||||
|
||||
import createHistory from "history/lib/createBrowserHistory"
|
||||
|
||||
|
||||
class Master extends React.Component<React.Props<{}>, {}> {
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
<h1>Master</h1>
|
||||
<Link to="/">Dashboard</Link> <Link to="/users">Users</Link>
|
||||
<p>{this.props.children}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Dashboard extends React.Component<{}, {}> {
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
This is a dashboard
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NotFound extends React.Component<{}, {}> {
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
This path does not exists
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Users extends React.Component<{}, {}> {
|
||||
|
||||
render() {
|
||||
return <div>
|
||||
This is a user list
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ReactDOM.render((
|
||||
<Router history={createHistory()}>
|
||||
<Route path="/" component={Master}>
|
||||
<IndexRoute component={Dashboard} />
|
||||
<Route path="users" component={Users}/>
|
||||
<Route path="*" component={NotFound}/>
|
||||
</Route>
|
||||
</Router>
|
||||
), document.body)
|
||||
@@ -0,0 +1 @@
|
||||
--noImplicitAny -jsx react --target es5
|
||||
Vendored
+391
-320
@@ -1,354 +1,425 @@
|
||||
// Type definitions for React Router 0.13.3
|
||||
// Type definitions for react-router v1.0.0
|
||||
// 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>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
///<reference path='../react/react.d.ts' />
|
||||
|
||||
declare module ReactRouter {
|
||||
import React = __React;
|
||||
/// <reference path="../react/react.d.ts" />
|
||||
/// <reference path="./history.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 {
|
||||
|
||||
import React = __React
|
||||
|
||||
import H = HistoryModule
|
||||
|
||||
// types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md
|
||||
|
||||
type Component = React.ReactType
|
||||
|
||||
type EnterHook = (nextState: RouterState, replaceState: RedirectFunction, callback?: Function) => any
|
||||
|
||||
type LeaveHook = () => any
|
||||
|
||||
type Params = Object
|
||||
|
||||
type ParseQueryString = (queryString: H.QueryString) => H.Query
|
||||
|
||||
type RedirectFunction = (state: H.LocationState, pathname: H.Pathname | H.Path, query?: H.Query) => void
|
||||
|
||||
type RouteComponent = Component
|
||||
|
||||
// use the following interface in an app code to get access to route param values, history, location...
|
||||
// interface MyComponentProps extends ReactRouter.RouteComponentProps<{}, { id: number }> {}
|
||||
// somewhere in MyComponent
|
||||
// ...
|
||||
// let id = this.props.routeParams.id
|
||||
// ...
|
||||
// this.props.history. ...
|
||||
// ...
|
||||
interface RouteComponentProps<P, R> {
|
||||
history?: History
|
||||
location?: H.Location
|
||||
params?: P
|
||||
route?: PlainRoute
|
||||
routeParams?: R
|
||||
routes?: PlainRoute[]
|
||||
}
|
||||
|
||||
interface TransitionStaticLifecycle {
|
||||
willTransitionTo?(
|
||||
transition: Transition,
|
||||
params: {},
|
||||
query: {},
|
||||
callback: Function
|
||||
): void;
|
||||
type RouteComponents = { [key: string]: RouteComponent }
|
||||
|
||||
willTransitionFrom?(
|
||||
transition: Transition,
|
||||
component: React.ReactElement<any>,
|
||||
callback: Function
|
||||
): void;
|
||||
}
|
||||
type RouteConfig = React.ReactNode | PlainRoute | 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 RouteHook = (nextLocation?: H.Location) => any
|
||||
|
||||
// NotFoundRoute
|
||||
interface NotFoundRouteProp {
|
||||
name?: string;
|
||||
handler: React.ComponentClass<any>;
|
||||
}
|
||||
interface NotFoundRoute extends React.ReactElement<NotFoundRouteProp> {}
|
||||
interface NotFoundRouteClass extends React.ComponentClass<NotFoundRouteProp> {}
|
||||
type RoutePattern = string
|
||||
|
||||
// Redirect
|
||||
interface RedirectProp {
|
||||
path?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
}
|
||||
interface Redirect extends React.ReactElement<RedirectProp> {}
|
||||
interface RedirectClass extends React.ComponentClass<RedirectProp> {}
|
||||
type StringifyQuery = (queryObject: H.Query) => H.QueryString
|
||||
|
||||
// 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> {}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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?: {};
|
||||
}
|
||||
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: H.Location
|
||||
routes: PlainRoute[]
|
||||
params: Params
|
||||
components: RouteComponent[]
|
||||
}
|
||||
|
||||
interface RouterCreateOption {
|
||||
routes: Route;
|
||||
location?: LocationBase;
|
||||
scrollBehavior?: ScrollBehaviorBase;
|
||||
onError?: (error: any) => void;
|
||||
onAbort?: (error: any) => void;
|
||||
|
||||
interface HistoryBase extends H.History {
|
||||
routes: PlainRoute[]
|
||||
parseQueryString?: ParseQueryString
|
||||
stringifyQuery?: StringifyQuery
|
||||
}
|
||||
|
||||
type RouterRunCallback = (Handler: RouteClass, state: RouterState) => void;
|
||||
|
||||
function create(options: RouterCreateOption): Router;
|
||||
function run(routes: Route, callback: RouterRunCallback): Router;
|
||||
function run(routes: Route, location: LocationBase | string, callback: RouterRunCallback): Router;
|
||||
type History = HistoryBase & H.HistoryQueries & HistoryRoutes
|
||||
|
||||
|
||||
//
|
||||
// Location
|
||||
// ----------------------------------------------------------------------
|
||||
interface LocationBase {
|
||||
getCurrentPath(): void;
|
||||
toString(): string;
|
||||
/* components */
|
||||
|
||||
interface RouterProps extends React.Props<Router> {
|
||||
history?: H.History
|
||||
routes?: RouteConfig // alias for children
|
||||
createElement?: (component: RouteComponent, props: Object) => any
|
||||
onError?: (error: any) => any
|
||||
onUpdate?: () => any
|
||||
parseQueryString?: ParseQueryString
|
||||
stringifyQuery?: StringifyQuery
|
||||
}
|
||||
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.HTMLAttributes, React.Props<Link> {
|
||||
activeStyle?: React.CSSProperties
|
||||
activeClassName?: string
|
||||
onlyActiveOnIndex?: boolean
|
||||
to: RoutePattern
|
||||
query?: H.Query
|
||||
state?: H.LocationState
|
||||
}
|
||||
interface Link extends React.ComponentClass<LinkProps> {}
|
||||
interface LinkElement extends React.ReactElement<LinkProps> {}
|
||||
const Link: Link
|
||||
|
||||
|
||||
const IndexLink: Link
|
||||
|
||||
|
||||
interface RoutingContextProps extends React.Props<RoutingContext> {
|
||||
history: H.History
|
||||
createElement: (component: RouteComponent, props: Object) => any
|
||||
location: H.Location
|
||||
routes: RouteConfig
|
||||
params: Params
|
||||
components?: RouteComponent[]
|
||||
}
|
||||
interface RoutingContext extends React.ComponentClass<RoutingContextProps> {}
|
||||
interface RoutingContextElement extends React.ReactElement<RoutingContextProps> {}
|
||||
const RoutingContext: RoutingContext
|
||||
|
||||
|
||||
/* components (configuration) */
|
||||
|
||||
interface RouteProps extends React.Props<Route> {
|
||||
path?: RoutePattern
|
||||
component?: RouteComponent
|
||||
components?: RouteComponents
|
||||
getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void
|
||||
getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void
|
||||
onEnter?: EnterHook
|
||||
onLeave?: LeaveHook
|
||||
}
|
||||
interface Route extends React.ComponentClass<RouteProps> {}
|
||||
interface RouteElement extends React.ReactElement<RouteProps> {}
|
||||
const Route: Route
|
||||
|
||||
|
||||
interface PlainRoute {
|
||||
path?: RoutePattern
|
||||
component?: RouteComponent
|
||||
components?: RouteComponents
|
||||
getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void
|
||||
getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void
|
||||
onEnter?: EnterHook
|
||||
onLeave?: LeaveHook
|
||||
indexRoute?: PlainRoute
|
||||
getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void
|
||||
childRoutes?: PlainRoute[]
|
||||
getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void
|
||||
}
|
||||
|
||||
interface LocationListener {
|
||||
addChangeListener(listener: Function): void;
|
||||
removeChangeListener(listener: Function): void;
|
||||
|
||||
interface RedirectProps extends React.Props<Redirect> {
|
||||
path?: RoutePattern
|
||||
from?: RoutePattern // alias for path
|
||||
to: RoutePattern
|
||||
query?: H.Query
|
||||
state?: H.LocationState
|
||||
}
|
||||
interface Redirect extends React.ComponentClass<RedirectProps> {}
|
||||
interface RedirectElement extends React.ReactElement<RedirectProps> {}
|
||||
const Redirect: Redirect
|
||||
|
||||
|
||||
interface IndexRouteProps extends React.Props<IndexRoute> {
|
||||
component?: RouteComponent
|
||||
components?: RouteComponents
|
||||
getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void
|
||||
getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void
|
||||
onEnter?: EnterHook
|
||||
onLeave?: LeaveHook
|
||||
}
|
||||
interface IndexRoute extends React.ComponentClass<IndexRouteProps> {}
|
||||
interface IndexRouteElement extends React.ReactElement<IndexRouteProps> {}
|
||||
const IndexRoute: IndexRoute
|
||||
|
||||
|
||||
interface IndexRedirectProps extends React.Props<IndexRedirect> {
|
||||
to: RoutePattern
|
||||
query?: H.Query
|
||||
state?: H.LocationState
|
||||
}
|
||||
interface IndexRedirect extends React.ComponentClass<IndexRedirectProps> {}
|
||||
interface IndexRedirectElement extends React.ReactElement<IndexRedirectProps> {}
|
||||
const IndexRedirect: IndexRedirect
|
||||
|
||||
|
||||
/* mixins */
|
||||
|
||||
interface HistoryMixin {
|
||||
history: History
|
||||
}
|
||||
const History: React.Mixin<any, any>
|
||||
|
||||
|
||||
interface LifecycleMixin {
|
||||
routerWillLeave(nextLocation: H.Location): string | boolean
|
||||
}
|
||||
const Lifecycle: React.Mixin<any, any>
|
||||
|
||||
|
||||
const RouteContext: React.Mixin<any, any>
|
||||
|
||||
|
||||
/* utils */
|
||||
|
||||
interface HistoryRoutes {
|
||||
listen(listener: RouterListener): Function
|
||||
listenBeforeLeavingRoute(route: PlainRoute, hook: RouteHook): void
|
||||
match(location: H.Location, callback: (error: any, nextState: RouterState, nextLocation: H.Location) => void): void
|
||||
isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean
|
||||
}
|
||||
|
||||
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;
|
||||
function useRoutes<T>(createHistory: HistoryModule.CreateHistory<T>): HistoryModule.CreateHistory<T & HistoryRoutes>
|
||||
|
||||
|
||||
//
|
||||
// Behavior
|
||||
// ----------------------------------------------------------------------
|
||||
interface ScrollBehaviorBase {
|
||||
updateScrollPosition(position: { x: number; y: number; }, actionType: string): void;
|
||||
function createRoutes(routes: RouteConfig): PlainRoute[]
|
||||
|
||||
|
||||
interface MatchArgs {
|
||||
routes?: RouteConfig
|
||||
history?: H.History
|
||||
location?: H.Location
|
||||
parseQueryString?: ParseQueryString
|
||||
stringifyQuery?: StringifyQuery
|
||||
}
|
||||
interface ImitateBrowserBehavior extends ScrollBehaviorBase { }
|
||||
interface ScrollToTopBehavior extends ScrollBehaviorBase { }
|
||||
|
||||
var ImitateBrowserBehavior: ImitateBrowserBehavior;
|
||||
var ScrollToTopBehavior: ScrollToTopBehavior;
|
||||
|
||||
|
||||
//
|
||||
// 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 MatchState extends RouterState {
|
||||
history: History
|
||||
}
|
||||
function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void
|
||||
|
||||
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/IndexLink" {
|
||||
|
||||
export default ReactRouter.IndexLink
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/IndexRedirect" {
|
||||
|
||||
export default ReactRouter.IndexRedirect
|
||||
|
||||
}
|
||||
|
||||
|
||||
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" {
|
||||
|
||||
export default ReactRouter.History
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/Lifecycle" {
|
||||
|
||||
export default ReactRouter.Lifecycle
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RouteContext" {
|
||||
|
||||
export default ReactRouter.RouteContext
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/useRoutes" {
|
||||
|
||||
export default ReactRouter.useRoutes
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RouteUtils" {
|
||||
|
||||
type E = __React.ReactElement<any>
|
||||
|
||||
export function isReactChildren(object: E | E[]): boolean
|
||||
|
||||
export function createRouteFromReactElement(element: E): ReactRouter.PlainRoute
|
||||
|
||||
export function createRoutesFromReactChildren(children: E | E[], parentRoute: ReactRouter.PlainRoute): ReactRouter.PlainRoute[]
|
||||
|
||||
export import createRoutes = ReactRouter.createRoutes
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/RoutingContext" {
|
||||
|
||||
export default ReactRouter.RoutingContext
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/PropTypes" {
|
||||
|
||||
import React = __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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router/lib/match" {
|
||||
|
||||
export default ReactRouter.match
|
||||
|
||||
}
|
||||
|
||||
|
||||
declare module "react-router" {
|
||||
export = ReactRouter;
|
||||
}
|
||||
|
||||
declare module __React {
|
||||
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
}
|
||||
|
||||
declare module "react/addons" {
|
||||
// for DefaultRoute
|
||||
function createElement(
|
||||
type: ReactRouter.DefaultRouteClass,
|
||||
props: ReactRouter.DefaultRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.DefaultRoute;
|
||||
|
||||
// for Link
|
||||
function createElement(
|
||||
type: ReactRouter.LinkClass,
|
||||
props: ReactRouter.LinkProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Link;
|
||||
|
||||
// for NotFoundRoute
|
||||
function createElement(
|
||||
type: ReactRouter.NotFoundRouteClass,
|
||||
props: ReactRouter.NotFoundRouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.NotFoundRoute;
|
||||
|
||||
// for Redirect
|
||||
function createElement(
|
||||
type: ReactRouter.RedirectClass,
|
||||
props: ReactRouter.RedirectProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Redirect;
|
||||
|
||||
// for Route
|
||||
function createElement(
|
||||
type: ReactRouter.RouteClass,
|
||||
props: ReactRouter.RouteProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.Route;
|
||||
|
||||
// for RouteHandler
|
||||
function createElement(
|
||||
type: ReactRouter.RouteHandlerClass,
|
||||
props: ReactRouter.RouteHandlerProp,
|
||||
...children: __React.ReactNode[]): ReactRouter.RouteHandler;
|
||||
|
||||
import Router from "react-router/lib/Router"
|
||||
|
||||
import Link from "react-router/lib/Link"
|
||||
|
||||
import IndexLink from "react-router/lib/IndexLink"
|
||||
|
||||
import IndexRedirect from "react-router/lib/IndexRedirect"
|
||||
|
||||
import IndexRoute from "react-router/lib/IndexRoute"
|
||||
|
||||
import Redirect from "react-router/lib/Redirect"
|
||||
|
||||
import Route from "react-router/lib/Route"
|
||||
|
||||
import History from "react-router/lib/History"
|
||||
|
||||
import Lifecycle from "react-router/lib/Lifecycle"
|
||||
|
||||
import RouteContext from "react-router/lib/RouteContext"
|
||||
|
||||
import useRoutes from "react-router/lib/useRoutes"
|
||||
|
||||
import { createRoutes } from "react-router/lib/RouteUtils"
|
||||
|
||||
import RoutingContext from "react-router/lib/RoutingContext"
|
||||
|
||||
import PropTypes from "react-router/lib/PropTypes"
|
||||
|
||||
import match from "react-router/lib/match"
|
||||
|
||||
export {
|
||||
Router,
|
||||
Link,
|
||||
IndexLink,
|
||||
IndexRedirect,
|
||||
IndexRoute,
|
||||
Redirect,
|
||||
Route,
|
||||
History,
|
||||
Lifecycle,
|
||||
RouteContext,
|
||||
useRoutes,
|
||||
createRoutes,
|
||||
RoutingContext,
|
||||
PropTypes,
|
||||
match
|
||||
}
|
||||
|
||||
export default Router
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user