Skip to content

Commit de1685e

Browse files
committed
docs update
1 parent 919ccbc commit de1685e

17 files changed

+175
-289
lines changed

docs/api/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ React Router API
1313
- [`Routes`](/docs/api/components/Routes.md)
1414

1515
- Mixins
16-
- [`ActiveState`](/docs/api/mixins/ActiveState.md)
17-
- [`CurrentPath`](/docs/api/mixins/CurrentPath.md)
16+
- [`State`](/docs/api/mixins/State.md)
1817
- [`Navigation`](/docs/api/mixins/Navigation.md)
1918

2019
- Misc

docs/api/Router.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Router = window.ReactRouter
1414

1515
// methods
1616
Router.run
17+
Router.create
1718

1819
// components
1920
Router.DefaultRoute
@@ -23,8 +24,7 @@ Router.Redirect
2324
Router.Route
2425

2526
// mixins
26-
Router.ActiveState
27-
Router.CurrentPath
27+
Router.State
2828
Router.Navigation
2929
```
3030

docs/api/components/DefaultRoute.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
API: `DefaultRoute` (component)
22
===============================
33

4-
A route that is active when the parent route's path matches exactly. Or,
5-
in other words, the default child route for a parent.
4+
A `DefaultRoute` is active when the parent route's path matches exactly.
65

76
Note, this is not a `NotFoundRoute`. It is only active when the parent's
87
route path is matched exactly.
@@ -20,8 +19,8 @@ Example
2019
<Route path="/" handler={App}>
2120

2221
<!--
23-
when the url is `/`, this handler will be active, or in other
24-
words, will be `this.props.activeRouteHandler in the `App` handler
22+
When the url is `/`, this route will be active. In other
23+
words, `Home` will be the `<RouteHandler/>` in `App`.
2524
-->
2625
<DefaultRoute handler={Home}/>
2726

@@ -30,7 +29,7 @@ Example
3029
<Route name="user" handler={User} path="/user/:id"/>
3130

3231
<!-- when the url is `/users`, this will be active -->
33-
<DefaultRoute handler={UsersIndex}/>
32+
<DefaultRoute name="users-index" handler={UsersIndex}/>
3433

3534
</Route>
3635
</Route>
@@ -41,15 +40,14 @@ This is all really just a shortcut for the less intuitive version of the
4140
same functionality:
4241

4342
```xml
44-
<!-- no path or name on what was previously the "users" route -->
45-
<Route handler={Users}>
46-
<!-- the path moved down to the child -->
43+
<!-- don't do this -->
44+
45+
<!-- this route has a path but it'll never match directly because ... -->
46+
<Route path="/users" handler={Users}>
47+
<!-- this child has the same path, and the child matches first -->
4748
<Route name="users-index" path="/users" handler={UsersIndex}/>
4849
<Route name="user" handler={User} path="/user/:id"/>
4950
</Route>
5051
```
5152

52-
`DefaultRoute` feels more natural, so you can name and transition to the
53-
parent route.
54-
5553
[routeProps]:/docs/api/components/Route.md#props

docs/api/components/NotFoundRoute.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ API: `NotFoundRoute` (component)
22
===============================
33

44
When a parent's URL partially matches, but none of the children do, a
5-
`NotFoundRoute` will be matched and its handler rendered at any level of
6-
your route/view hierarchy.
5+
`NotFoundRoute` will be matched and its handler activated at any level
6+
of your route hierarchy.
77

88
Props
99
-----
@@ -14,19 +14,17 @@ Example
1414
-------
1515

1616
```xml
17-
<Routes>
18-
<Route path="/" handler={App}>
19-
<Route name="course" path="course/:courseId" handler={Course}>
20-
<Route name="course-dashboard" path="dashboard" />
17+
<Route path="/" handler={App}>
18+
<Route name="course" path="course/:courseId" handler={Course}>
19+
<Route name="course-dashboard" path="dashboard" handler={Dashboard}/>
2120

22-
<!-- ie: `/course/123/foo` -->
23-
<NotFoundRoute handler={CourseRouteNotFound} />
24-
</Route>
25-
26-
<!-- ie: `/flkjasdf` -->
27-
<NotFoundRoute handler={NotFound} />
21+
<!-- ie: `/course/123/foo` -->
22+
<NotFoundRoute handler={CourseRouteNotFound} />
2823
</Route>
29-
</Routes>
24+
25+
<!-- ie: `/flkjasdf` -->
26+
<NotFoundRoute handler={NotFound} />
27+
</Route>
3028
```
3129

3230
The last `NotFoundRoute` will render inside the `App`, the first will

docs/api/components/Redirect.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,36 @@ Example
3333
lets say we want to change from `/profile/123` to `/about/123`
3434
and redirect `/get-in-touch` to `/contact`
3535
-->
36-
<Routes>
37-
<Route handler={App}>
38-
<Route name="contact" handler={Contact}/>
39-
<Route name="about-user" path="about/:userId" handler={UserProfile}/>
40-
<Route name="course" path="course/:courseId">
41-
<Route name="course-dashboard" path="dashboard" handler={Dashboard}/>
42-
<Route name="course-assignments" path="assignments" handler={Assignments}/>
43-
<!--
44-
anything like `/course/123/invalid` redirects to
45-
`/course/123/dashboard`
46-
-->
47-
<Redirect to="course-dashboard" />
48-
</Route>
36+
<Route handler={App}>
37+
<Route name="contact" handler={Contact}/>
38+
<Route name="about-user" path="about/:userId" handler={UserProfile}/>
39+
<Route name="course" path="course/:courseId">
40+
<Route name="course-dashboard" path="dashboard" handler={Dashboard}/>
41+
<Route name="course-assignments" path="assignments" handler={Assignments}/>
4942
</Route>
50-
43+
5144
<!-- `/get-in-touch` -> `/contact` -->
5245
<Redirect from="get-in-touch" to="contact" />
5346

5447
<!-- `/profile/123` -> `/about/123` -->
5548
<Redirect from="profile/:userId" to="about-user" />
5649

57-
<!-- `/profile/jasmin` -> `/about-user/123` -->
58-
<Redirect from="profile/jasmin" to="about-user" params={{userId: 123}} />
59-
</Routes>
50+
<!-- `/profile/me` -> `/about-user/123` -->
51+
<Redirect from="profile/me" to="about-user" params={{userId: SESSION.USER_ID}} />
52+
</Route>
6053
```
6154

6255
Note that the `<Redirect/>` can be placed anywhere in the route
6356
hierarchy, if you'd prefer the redirects to be next to their respective
64-
routes.
57+
routes, the `from` path will match the same as a regular route `path`.
6558

6659
```xml
67-
<Routes>
68-
<Route handler={App}>
69-
<Route name="contact" handler={Contact}/>
70-
<Redirect from="get-in-touch" to="contact" />
60+
<Route handler={App}>
61+
<Route name="course" path="course/:courseId">
62+
<Route name="course-dashboard" path="dashboard" handler={Dashboard}/>
63+
<!-- /course/123/home -> /course/123/dashboard -->
64+
<Redirect from="home" to="course-dashboard" />
7165
</Route>
72-
</Routes>
66+
</Route>
7367
```
68+

docs/api/components/Route.md

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
API: `Route` (component)
22
=========================
33

4-
Configuration component to declare your application's routes and view hierarchy.
4+
Configuration component to declare your application's routes and entry
5+
view hierarchy.
56

67
Props
78
-----
@@ -23,77 +24,30 @@ about supported path matching syntax.
2324

2425
The component to be rendered when the route is active.
2526

26-
### `addHandlerKey`
27-
28-
Defaults to `false`.
29-
30-
If you have dynamic segments in your URL, a transition from `/users/123`
31-
to `/users/456` does not call `getInitialState`, `componentWillMount` or
32-
`componentWillUnmount`. If you are using those lifecycle hooks to fetch
33-
data and set state, you will also need to implement
34-
`componentWillReceiveProps` on your handler, just like any other
35-
component with changing props. This way, you can leverage the
36-
performance of the React DOM diff algorithm. Look at the `Contact`
37-
handler in the `master-detail` example.
38-
39-
If you'd rather be lazy, set this to `true` and the router will add a
40-
key to your route, causing all new DOM to be built, and then the life
41-
cycle hooks will all be called.
42-
43-
You will want this to be `true` if you're doing animations with React's
44-
TransitionGroup component.
45-
4627
### `children`
4728

48-
Routes can be nested. When a child route matches, the parent route's
49-
handler will have the child route's handler available as
50-
`this.props.activeRouteHandler`. You can then render it in the parent
51-
passing in any additional props as needed.
52-
53-
### `[prop]`
54-
55-
Any additional, user-defined, properties will be become properties of
56-
the rendered handler.
57-
58-
#### Example:
59-
60-
```js
61-
var App;
62-
var foo = "hello";
63-
64-
var routes = (
65-
<Routes>
66-
// pass `foo` to `something`
67-
<Route handler={App} something={foo}/>
68-
</Routes>
69-
);
70-
71-
App = React.createClass({
72-
render: function () {
73-
// access `something` on props
74-
return <div>{this.props.something}</div>
75-
}
76-
});
77-
78-
React.renderComponent(routes, document.body);
79-
document.body.innerHTML // -> <div>hello</div>
80-
```
29+
Routes can be nested. When a child route path matches, the parent route
30+
is also activated. Please refer to the [overview][overview] since this
31+
is a very critical part of the router's design.
8132

8233
Example
8334
-------
8435

8536
```xml
86-
<Routes>
87-
<!-- path defaults to '/' since no name or path provided -->
88-
<Route handler={App}>
89-
<!-- path is automatically assigned to the name since it is omitted -->
90-
<Route name="about" handler={About}/>
91-
<Route name="users" handler={Users}>
92-
<!-- note the dynamic segment in the path -->
93-
<Route name="user" handler={User} path="/user/:id"/>
94-
</Route>
37+
<!-- `path` defaults to '/' since no name or path provided -->
38+
<Route handler={App}>
39+
<!-- path is automatically assigned to the name since it is omitted -->
40+
<Route name="about" handler={About}/>
41+
<Route name="users" handler={Users}>
42+
<!--
43+
note the dynamic segment in the path, and that it starts with `/`,
44+
which makes it "absolute", or rather, it doesn't inherit the path
45+
from the parent route
46+
-->
47+
<Route name="user" handler={User} path="/user/:id"/>
9548
</Route>
96-
</Routes>
49+
</Route>
9750
```
9851

52+
[overview]:/docs/guides/overview.md
9953
[path-matching]:/docs/guides/path-matching.md
Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,9 @@
11
API: `RouteHandler` (component)
22
===============================
33

4-
The component supplied to a route is called a "Route Handler". They are
5-
rendered when their route is active. There are some special props and
6-
static methods available to these components.
7-
8-
Props
9-
-----
10-
11-
### `activeRouteHandler(extraProps)`
12-
13-
Render the active nested route handler with this property, passing in
14-
additional properties as needed. This is the mechanism by which you get
15-
effortless nested UI.
16-
17-
#### Example
18-
19-
```js
20-
var App = React.createClass({
21-
render: function () {
22-
<div>
23-
<h1>Address Book</h1>
24-
{/* the active child route handler will be rendered here */}
25-
{/* you can "trickle down" props to the active child */}
26-
<this.props.activeRouteHandler someProp="foo" />
27-
</div>
28-
}
29-
});
30-
31-
var Contact = React.createClass({
32-
render: function () {
33-
return <h1>{this.props.params.id}</h1>
34-
}
35-
});
36-
37-
var routes = (
38-
<Routes>
39-
<Route handler={App}>
40-
<Route name="contact" path="/contact/:id" handler={Contact}>
41-
</Route>
42-
</Routes>
43-
);
44-
45-
React.renderComponent(routes, document.body);
46-
```
47-
48-
### `name`
49-
50-
The current route name.
51-
52-
### `params`
53-
54-
When a route has dynamic segments like `<Route path="users/:userId"/>`,
55-
the dynamic values from the url are available at
56-
`this.props.params.userId`, etc.
57-
58-
### `query`
59-
60-
The query parameters from the url.
4+
The component supplied to a route is called a "Route Handler". They can
5+
be rendered by the parent handler with `<RouteHandler/>`. There are
6+
some special static methods available to these components.
617

628
Static Lifecycle Methods
639
------------------------
@@ -67,7 +13,7 @@ during route transitions.
6713

6814
### `willTransitionTo(transition, params, query)`
6915

70-
Called when a route is about to render, giving you the opportunity to
16+
Called when a handler is about to render, giving you the opportunity to
7117
abort or redirect the transition. You can pause the transition while you
7218
do some asynchonous work with `transition.wait(promise)`.
7319

@@ -78,7 +24,7 @@ See also: [transition](/docs/api/misc/transition.md)
7824
Called when an active route is being transitioned out giving you an
7925
opportunity to abort the transition. The `component` is the current
8026
component, you'll probably need it to check its state to decide if you
81-
want to allow the transition.
27+
want to allow the transition (like form fields).
8228

8329
See also: [transition](/docs/api/misc/transition.md)
8430

@@ -92,7 +38,7 @@ var Settings = React.createClass({
9238
if (!loggedIn)
9339
return;
9440
transition.abort();
95-
return auth.logIn({transition: transition});
41+
auth.logIn({transition: transition});
9642
// in auth module call `transition.retry()` after being logged in
9743
});
9844
},
@@ -109,4 +55,3 @@ var Settings = React.createClass({
10955
//...
11056
});
11157
```
112-

0 commit comments

Comments
 (0)