diff --git a/docs/API.md b/docs/API.md index 7c6569506a..7cfa0fed41 100644 --- a/docs/API.md +++ b/docs/API.md @@ -485,6 +485,9 @@ The dynamic segments of the URL. #### `route` The route that rendered this component. +#### `router` +Contains methods relevant to routing. Most useful for imperatively transitioning around the application. + #### `routeParams` A subset of `this.props.params` that were directly specified in this component's route. For example, if the route's path is `users/:userId` and the URL is `/users/123/portfolios/345` then `this.props.routeParams` will be `{userId: '123'}`, and `this.props.params` will be `{userId: '123', portfolioId: 345}`. diff --git a/modules/RouterContext.js b/modules/RouterContext.js index 271d813308..f678aedefc 100644 --- a/modules/RouterContext.js +++ b/modules/RouterContext.js @@ -44,7 +44,7 @@ const RouterContext = React.createClass({ }, render() { - const { location, routes, params, components } = this.props + const { location, routes, params, components, router } = this.props let element = null if (components) { @@ -58,6 +58,7 @@ const RouterContext = React.createClass({ location, params, route, + router, routeParams, routes } diff --git a/modules/__tests__/RouterContext-test.js b/modules/__tests__/RouterContext-test.js index b568ff09c3..7ce4f62bb7 100644 --- a/modules/__tests__/RouterContext-test.js +++ b/modules/__tests__/RouterContext-test.js @@ -67,6 +67,19 @@ describe('RouterContext', () => { done() }) }) + + it('injects a `router` object into props of route components', (done) => { + class RoutedComponent extends React.Component { + render() { + expect(this.props.router).toBeA(Object) + return null + } + } + + match({ location: '/', routes: { path: '/', component: RoutedComponent } }, (err, redirect, renderProps) => { + render(, node, done) + }) + }) describe('some weird tests that test implementation and should probably go away', () => { it('proxies calls to `push` to `props.history`', (done) => {