diff --git a/types/react-router/index.d.ts b/types/react-router/index.d.ts index 384cb2289e..f1c24b778f 100644 --- a/types/react-router/index.d.ts +++ b/types/react-router/index.d.ts @@ -59,6 +59,7 @@ export interface RouteComponentProps

{ match: match

; location: H.Location; history: H.History; + staticContext?: any; } export interface RouteProps { diff --git a/types/react-router/test/StaticRouter.tsx b/types/react-router/test/StaticRouter.tsx new file mode 100644 index 0000000000..89999d84cb --- /dev/null +++ b/types/react-router/test/StaticRouter.tsx @@ -0,0 +1,55 @@ +import * as React from 'react'; +import { StaticRouter, Route } from 'react-router-dom'; + +interface StaticContext { + statusCode?: number; +} + +interface RouteStatusProps { + statusCode: number; +} + +const RouteStatus: React.SFC = (props) => ( + { + if (staticContext) { + (staticContext as StaticContext).statusCode = props.statusCode; + } + + return ( +

+ {props.children} +
+ ); + }} + /> +); + +interface PrintContextProps { + staticContext: StaticContext; +} + +const PrintContext: React.SFC = (props) => ( +

+ Static context: {JSON.stringify(props.staticContext)} +

+); + +class StaticRouterExample extends React.Component<{}, {}> { + staticContext: StaticContext = {}; + + render() { + return ( + +
+ +

Route with statusCode 404

+ +
+
+
+ ); + } +} + +export default StaticRouterExample; diff --git a/types/react-router/tsconfig.json b/types/react-router/tsconfig.json index f3a225ece1..4790f0b53d 100644 --- a/types/react-router/tsconfig.json +++ b/types/react-router/tsconfig.json @@ -29,6 +29,7 @@ "test/Recursive.tsx", "test/RouteConfig.tsx", "test/Sidebar.tsx", + "test/StaticRouter.tsx", "test/Switch.tsx", "test/WithRouter.tsx" ]