Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,6 @@ The dynamic segments of the URL.
#### `route`
The route that rendered this component.

#### `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}`.

#### `children`
The matched child route element to be rendered. If the route has [named components](/docs/API.md#named-components) then this will be undefined, and the components will instead be available as direct properties on `this.props`.

Expand Down Expand Up @@ -543,6 +540,8 @@ class App extends React.Component {

#### `history` (deprecated)

#### `routeParams` (deprecated)

### Named Components
When a route has one or more named components, the child elements are available by name on `this.props`. In this case `this.props.children` will be undefined. All route components can participate in the nesting.

Expand Down
7 changes: 6 additions & 1 deletion modules/RouterContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ const RouterContext = React.createClass({
return element // Don't create new children; use the grandchildren.

const route = routes[index]
const routeParams = getRouteParams(route, params)

let routeParams = getRouteParams(route, params)
if (__DEV__) {
routeParams = deprecateObjectProperties(routeParams, '`routeParams` is deprecated. Use `params` instead.')
}

const props = {
history,
location,
Expand Down
38 changes: 38 additions & 0 deletions modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,44 @@ describe('Router', function () {
})
})

it('passes params to route components', function (done) {
function MyComponent({ params }) {
return <div>{params.name}</div>
}

render((
<Router history={createHistory('/foo')}>
<Route>
<Route path=":name" component={MyComponent} />
</Route>
</Router>
), node, function () {
expect(node.textContent).toMatch(/foo/)
done()
})
})

it('passes routeParams to route components', function (done) {
if (canUseMembrane) {
shouldWarn('deprecated')
}

function MyComponent({ routeParams }) {
return <div>{routeParams.name}</div>
}

render((
<Router history={createHistory('/bar')}>
<Route>
<Route path=":name" component={MyComponent} />
</Route>
</Router>
), node, function () {
expect(node.textContent).toMatch(/bar/)
done()
})
})

it('renders with a custom "createElement" prop', function (done) {
class Wrapper extends Component {
render() {
Expand Down