Merge pull request #17737 from mtpc/patch-1

[React-router v4] Make Route component extensible
This commit is contained in:
Ron Buckton
2017-07-06 22:57:40 -07:00
committed by GitHub
3 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ export interface RouteProps {
exact?: boolean;
strict?: boolean;
}
export class Route extends React.Component<RouteProps> { }
export class Route<T extends RouteProps = RouteProps> extends React.Component<T> { }
export interface RouterProps {
history: any;
@@ -0,0 +1,16 @@
import * as React from 'react';
import { Route, RouteProps } from 'react-router';
interface CustomRouteInterface extends RouteProps {
aProperty: string;
anotherOne: boolean;
willItEnd?: number;
}
// React advocates composition over inheritance, but doesn't prevent us from using it
export default class CustomRoute extends Route<CustomRouteInterface> {
render() {
const maybeElement = super.render();
return maybeElement && <div className="meaningfulClass">{React.cloneElement(maybeElement, this.props)}</div>;
}
}
+1
View File
@@ -33,6 +33,7 @@
"test/NavigateWithContext.tsx",
"test/MemoryRouter.tsx",
"test/Switch.tsx",
"test/InheritingRoute.tsx",
"test/WithRouter.tsx"
]
}