Skip to content

Commit b7b021c

Browse files
committed
Merge branch 'bs1180-patch-1'
2 parents cfd1cd1 + ae6eec0 commit b7b021c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

docs/API.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [IndexRedirect](#indexredirect)
1515

1616
* [Handler Components](#handler-components)
17+
- [Named Components](#named-components)
1718

1819
* [Mixins](#mixins)
1920
- [Lifecycle](#lifecycle-mixin)
@@ -175,16 +176,15 @@ class App extends React.Component {
175176
```
176177

177178
##### `components`
178-
Routes can define multiple components as an object of `name:component`
179+
Routes can define one or more named components as an object of `name:component`
179180
pairs to be rendered when the path matches the URL. They can be rendered
180-
by the parent route component with `this.props.children[name]`.
181+
by the parent route component with `this.props[name]`.
181182

182183
```js
183-
// think of it outside the context of the router, if you had pluggable
184-
// portions of your `render`, you might do it like this
185-
<App children={{main: <Users/>, sidebar: <UsersSidebar/>}}/>
184+
// Think of it outside the context of the router - if you had pluggable
185+
// portions of your `render`, you might do it like this:
186+
// <App main={<Users />} sidebar={<UsersSidebar />} />
186187

187-
// So with the router it looks like this:
188188
const routes = (
189189
<Route component={App}>
190190
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}}/>
@@ -196,7 +196,7 @@ const routes = (
196196

197197
class App extends React.Component {
198198
render () {
199-
const { main, sidebar } = this.props.children
199+
const { main, sidebar } = this.props
200200
return (
201201
<div>
202202
<div className="Main">
@@ -408,7 +408,7 @@ The route that rendered this component.
408408
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}`.
409409

410410
#### `children`
411-
The matched child route elements to be rendered.
411+
The matched child route element to be rendered. If the route has [named components](https://github.com/rackt/react-router/blob/master/docs/API.md#named-components) then this will be undefined, and the components will instead be available as direct properties on `this.props`.
412412

413413
##### Example
414414
```js
@@ -434,7 +434,7 @@ class App extends React.Component {
434434
```
435435

436436
### Named Components
437-
When a route has multiple components, the child elements are available by name on `this.props.children`. All route components can participate in the nesting.
437+
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.
438438

439439
#### Example
440440
```js
@@ -456,11 +456,11 @@ class App extends React.Component {
456456
<div>
457457
<div className="Main">
458458
{/* this will either be <Groups> or <Users> */}
459-
{this.props.children.main}
459+
{this.props.main}
460460
</div>
461461
<div className="Sidebar">
462462
{/* this will either be <GroupsSidebar> or <UsersSidebar> */}
463-
{this.props.children.sidebar}
463+
{this.props.sidebar}
464464
</div>
465465
</div>
466466
)
@@ -472,8 +472,8 @@ class Users extends React.Component {
472472
return (
473473
<div>
474474
{/* if at "/users/123" this will be <Profile> */}
475-
{/* UsersSidebar will also get <Profile> as this.props.children,
476-
you pick where it renders */}
475+
{/* UsersSidebar will also get <Profile> as this.props.children.
476+
You can pick where it renders */}
477477
{this.props.children}
478478
</div>
479479
)
@@ -482,7 +482,6 @@ class Users extends React.Component {
482482
```
483483

484484

485-
486485
## Mixins
487486

488487
## Lifecycle Mixin

0 commit comments

Comments
 (0)