Skip to content

Commit 3c9cc45

Browse files
committed
More docs updates
1 parent eb3baa7 commit 3c9cc45

File tree

2 files changed

+101
-128
lines changed

2 files changed

+101
-128
lines changed

doc/02 Components/Route Component.md

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## Route Components
2+
3+
A route's component is rendered when that route matches the URL. The router will inject the following properties into your component when it's rendered:
4+
5+
#### `isTransitioning`
6+
7+
A boolean value that is `true` when the router is transitioning, `false` otherwise.
8+
9+
#### `location`
10+
11+
The current [location](http://rackt.github.io/history/docs/Location.html).
12+
13+
#### `params`
14+
15+
The dynamic segments of the URL.
16+
17+
#### `route`
18+
19+
The route that rendered this component.
20+
21+
#### `routeParams`
22+
23+
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}`.
24+
25+
#### `children`
26+
27+
The matched child route elements to be rendered.
28+
29+
#### Example
30+
31+
```js
32+
React.render((
33+
<Router history={history}>
34+
<Route path="/" component={App}>
35+
<Route path="groups" components={Groups} />
36+
<Route path="users" components={Users} />
37+
</Route>
38+
</Router>
39+
), node);
40+
41+
var App = React.createClass({
42+
render() {
43+
return (
44+
<div>
45+
{/* this will be either <Users> or <Groups> */}
46+
{this.props.children}
47+
</div>
48+
);
49+
}
50+
});
51+
```
52+
53+
### Named Child Components
54+
55+
When a route has multiple components, the child elements are available by name on `this.props`. All route components can participate in the nesting.
56+
57+
#### Example
58+
59+
```js
60+
React.render((
61+
<Router history={HashHistory}>
62+
<Route path="/" component={App}>
63+
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}} />
64+
<Route path="users" components={{main: Users, sidebar: UsersSidebar}}>
65+
<Route path="users/:userId" components={Profile} />
66+
</Route>
67+
</Route>
68+
</Router>
69+
), node);
70+
71+
var App = React.createClass({
72+
render() {
73+
// the matched child route components become props in the parent
74+
return (
75+
<div>
76+
<div className="Main">
77+
{/* this will either be <Groups> or <Users> */}
78+
{this.props.main}
79+
</div>
80+
<div className="Sidebar">
81+
{/* this will either be <GroupsSidebar> or <UsersSidebar> */}
82+
{this.props.sidebar}
83+
</div>
84+
</div>
85+
);
86+
}
87+
});
88+
89+
var Users = React.createClass({
90+
render() {
91+
return (
92+
<div>
93+
{/* if at "/users/123" this will be <Profile> */}
94+
{/* UsersSidebar will also get <Profile> as this.props.children,
95+
you pick where it renders */}
96+
{this.props.children}
97+
</div>
98+
);
99+
}
100+
});
101+
```

0 commit comments

Comments
 (0)