mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
Merge pull request #12291 from KostyaEsmukov/react-router-render-prop
react-router: added render prop and fixed applyRouterMiddleware types
This commit is contained in:
2
react-router/index.d.ts
vendored
2
react-router/index.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
// Type definitions for react-router v2.0.0
|
||||
// Project: https://github.com/rackt/react-router
|
||||
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>, Nathan Brown <https://github.com/ngbrown>, Alex Wendland <https://github.com/awendland>
|
||||
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Yuichi Murata <https://github.com/mrk21>, Václav Ostrožlík <https://github.com/vasek17>, Nathan Brown <https://github.com/ngbrown>, Alex Wendland <https://github.com/awendland>, Kostya Esmukov <https://github.com/KostyaEsmukov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="history" />
|
||||
|
||||
20
react-router/lib/Router.d.ts
vendored
20
react-router/lib/Router.d.ts
vendored
@@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import RouterContext from './RouterContext';
|
||||
import {
|
||||
QueryString, Query,
|
||||
Location, LocationDescriptor, LocationState,
|
||||
@@ -48,16 +49,17 @@ declare namespace Router {
|
||||
components: RouteComponent[];
|
||||
}
|
||||
|
||||
interface RouterProps extends React.Props<Router> {
|
||||
history?: History;
|
||||
routes?: RouteConfig; // alias for children
|
||||
createElement?: (component: RouteComponent, props: Object) => any;
|
||||
onError?: (error: any) => any;
|
||||
onUpdate?: () => any;
|
||||
parseQueryString?: ParseQueryString;
|
||||
stringifyQuery?: StringifyQuery;
|
||||
interface RouterProps extends React.Props<Router> {
|
||||
history?: History;
|
||||
routes?: RouteConfig; // alias for children
|
||||
createElement?: (component: RouteComponent, props: Object) => any;
|
||||
onError?: (error: any) => any;
|
||||
onUpdate?: () => any;
|
||||
parseQueryString?: ParseQueryString;
|
||||
stringifyQuery?: StringifyQuery;
|
||||
basename?: string;
|
||||
}
|
||||
render?: (renderProps: React.Props<{}>) => RouterContext;
|
||||
}
|
||||
|
||||
interface PlainRoute {
|
||||
path?: RoutePattern;
|
||||
|
||||
8
react-router/lib/applyRouterMiddleware.d.ts
vendored
8
react-router/lib/applyRouterMiddleware.d.ts
vendored
@@ -1,7 +1,9 @@
|
||||
import * as React from 'react';
|
||||
import Router from './Router';
|
||||
import RouterContext from './RouterContext';
|
||||
|
||||
export interface Middleware {
|
||||
renderRouterContext: (previous: React.Props<{}>[], props: React.Props<{}>) => React.Props<{}>[];
|
||||
renderRouteComponent: (previous: React.Props<{}>[], props: React.Props<{}>) => React.Props<{}>[];
|
||||
renderRouterContext?: (previous: RouterContext, props: React.Props<{}>) => RouterContext;
|
||||
renderRouteComponent?: (previous: Router.RouteComponent, props: React.Props<{}>) => Router.RouteComponent;
|
||||
}
|
||||
export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => React.Props<{}>[];
|
||||
export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => RouterContext;
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as React from "react"
|
||||
import * as ReactDOM from "react-dom"
|
||||
import {renderToString} from "react-dom/server";
|
||||
|
||||
import { browserHistory, hashHistory, match, createMemoryHistory, withRouter, routerShape, Router, Route, IndexRoute, InjectedRouter, Link, RouterOnContext, RouterContext} from "react-router";
|
||||
import { applyRouterMiddleware, browserHistory, hashHistory, match, createMemoryHistory, withRouter, routerShape, Router, Route, IndexRoute, InjectedRouter, Link, RouterOnContext, RouterContext} from "react-router";
|
||||
|
||||
interface MasterContext {
|
||||
router: RouterOnContext;
|
||||
@@ -105,3 +105,15 @@ const routes = (
|
||||
match({history, routes, location: "baseurl"}, (error, redirectLocation, renderProps) => {
|
||||
renderToString(<RouterContext {...renderProps} />);
|
||||
});
|
||||
|
||||
|
||||
ReactDOM.render((
|
||||
<Router
|
||||
history={history}
|
||||
routes={routes}
|
||||
render={applyRouterMiddleware({
|
||||
renderRouteComponent: child => child
|
||||
})}
|
||||
>
|
||||
</Router>
|
||||
), document.body);
|
||||
|
||||
Reference in New Issue
Block a user