diff --git a/modules/__tests__/withRouter-test.js b/modules/__tests__/withRouter-test.js index ebfdc58fbd..c083bd74bf 100644 --- a/modules/__tests__/withRouter-test.js +++ b/modules/__tests__/withRouter-test.js @@ -38,4 +38,25 @@ describe('withRouter', function () { done() }) }) + + it('still uses router prop if provided', function (done) { + const Test = withRouter(function (props) { + props.test(props) + return null + }) + const router = { + push() {}, + replace() {}, + go() {}, + goBack() {}, + goForward() {}, + setRouteLeaveHook() {}, + isActive() {} + } + const test = function (props) { + expect(props.router).toBe(router) + } + + render(, node, done) + }) }) diff --git a/modules/withRouter.js b/modules/withRouter.js index e9e7f32fda..396c5ad6c9 100644 --- a/modules/withRouter.js +++ b/modules/withRouter.js @@ -9,8 +9,10 @@ function getDisplayName(WrappedComponent) { export default function withRouter(WrappedComponent) { const WithRouter = React.createClass({ contextTypes: { router: routerShape }, + propTypes: { router: routerShape }, render() { - return + const router = this.props.router || this.context.router + return } })