Skip to content

Commit d10420d

Browse files
committed
moar docs
1 parent 41ef6d7 commit d10420d

File tree

6 files changed

+94
-19
lines changed

6 files changed

+94
-19
lines changed

doc/00 Guides/Path Matching.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TODO
2+

doc/01 Route Configuration/0 Route.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ Props
99
The path used in the URL.
1010

1111
It will concat with the parent route's path unless it starts with `/`.
12-
In which case you will need to use `childWillMatch` on the parent route
13-
so the router knows to keep going down the route tree.
12+
In which case you will need to use `absoluteChildPaths` on the parent
13+
route so the router knows to keep going down the route tree even though
14+
the parent path doesn't match the url.
1415

1516
If left undefined, the router will try to match the child routes.
1617

@@ -27,8 +28,8 @@ be rendered by the parent route component with `this.props.children`.
2728
```js
2829
var routes = (
2930
<Route component={App}>
30-
<Route path="groups" components={Groups}/>
31-
<Route path="users" components={Users}/>
31+
<Route path="groups" component={Groups}/>
32+
<Route path="users" component={Users}/>
3233
</Route>
3334
);
3435

@@ -47,12 +48,18 @@ var App = React.createClass({
4748
### `components`
4849

4950
Routes can define multiple components as an object of name:component
50-
pairs to be rendered when the path matches the url. They can be rendred
51+
pairs to be rendered when the path matches the url. They can be rendered
5152
by the parent route component with `this.props[name]`.
5253

5354
#### Example
5455

5556
```js
57+
// think of it outside the context of the router, if you had pluggable
58+
// portions of your `render`, you might do it like this
59+
<App main={<Users/>} sidebar={<UsersSidebar/>}/>
60+
<App main={<Groups/>} sidebar={<GroupsSidebar/>}/>
61+
62+
// So with the router its looks like this:
5663
var routes = (
5764
<Route component={App}>
5865
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}}/>
@@ -89,6 +96,7 @@ var Users = React.createClass({
8996
);
9097
}
9198
});
99+
92100
```
93101

94102
### `getComponents(state, cb)`

doc/01 Route Configuration/Plain Route.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
A route configuration object. `Router` turns JSX `<Route/>`s into
2-
these objects, but you can use them direclty if you prefer. All of the
2+
these objects, but you can use them directly if you prefer. All of the
33
props are the same as `<Route/>` props, except those listed here.
44

55
Props
@@ -13,7 +13,7 @@ An array of child routes, same as `children` in JSX route configs.
1313

1414
Same as `childRoutes` but asynchronous and receives the location state.
1515
Useful for code-splitting and dynamic route matching (given some state
16-
or session data, return a different set of child routes).
16+
or session data to return a different set of child routes).
1717

1818
#### `callback` signature
1919

@@ -39,5 +39,20 @@ var myRoute = {
3939
cb(null, [announcementsRoute, gradesRoute, assignmentsRoute]);
4040
}
4141
};
42+
43+
// navigation dependent child routes
44+
// can link with some state
45+
<Link to="/picture/123" state={{fromDashboard: true}}/>
46+
47+
var myRoute = {
48+
path: 'picture/:id',
49+
getChildRoutes (state, cb) {
50+
// state gets passed to `getChildRoutes`
51+
if (state && state.fromDashboard)
52+
cb(null, [dashboardPictureRoute])
53+
else
54+
cb(null, [pictureRoute])
55+
}
56+
};
4257
```
4358

doc/02 Components/0 Router.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ history changes, `Router` will match a branch of its [`Routes`][Route],
1111
and render their configured [components][RouteComponent], with child
1212
route components nested inside the parents.
1313

14+
### `routes`
15+
16+
Alias for `children`.
17+
1418
### `history` (required)
1519

1620
The [`History`][History] the router should set up and listen for changes
@@ -44,15 +48,6 @@ function createElement(Component, props) {
4448
}
4549
```
4650

47-
### `parseQueryString(queryString)`
48-
49-
A custom prop to parse query strings differently than the default.
50-
51-
### `stringifyQuery(obj)`
52-
53-
A custom prop to stringify query objects that come from [`Links`][Link]
54-
and [`router.transitionTo()`][transitionTo].
55-
5651
### `onError(error)`
5752

5853
While the router is matching, errors may bubble up, here

doc/03 History/0 Histories.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
`Router` sets up a `History` and updates `Router` state when the
2-
`History` emits changes. You can implement your own history, if you'd
3-
like to handle query parsing in a custom way, as soon as we decide what
4-
that API looks like ...
2+
`History` emits changes. You can implement your own history, or create
3+
an instance of one with your own options for query parsing.
4+
5+
```js
6+
// typical usage
7+
import BrowserHistory from 'react-router/lib/BrowserHistory';
8+
<Router history={BrowserHistory}/>
9+
```
10+
11+
If you need to do your own query parsing:
12+
13+
```js
14+
// note the `{ ... }` in the import statement...
15+
import { BrowserHistory } from 'react-router/lib/BrowserHistory';
16+
// ...this gives you a class instead of a singleton instance
17+
18+
var history = new BrowserHistory({
19+
parseQueryString(string) {
20+
return customParse(string);
21+
},
22+
stringifyQuery(obj) {
23+
return customStringify(obj);
24+
}
25+
});
26+
27+
var router = <Router history={history}/>;
28+
```
529

doc/03 History/HashHistory.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@ For example: ` http://example.com/?lang=es#/messages?sort=date`,
1616
`lang=es` is invisible to a `HashHistory` router, but `sort=date` is
1717
recognized, and will be used as the query parameters.
1818

19+
Using location state
20+
--------------------
21+
22+
`HashHistory` shims the `state` features of `window.history.pushState`,
23+
but you have to opt-in because it puts a key in the URL and we didn't
24+
want a bunch of issues opened about it :P
25+
26+
If you want to use the `location.state` features, opt-in. See the
27+
examples.
28+
1929
Example
2030
-------
2131

32+
Normal usage
33+
2234
```js
2335
import { Router } from 'react-router';
2436
import HashHistory from 'react-router/lib/HashHistory';
@@ -28,6 +40,25 @@ React.render((
2840
{/* ... */}
2941
</Router>
3042
), document.body);
43+
```
44+
45+
Opting in to the `state` features:
46+
47+
```js
48+
// note the `{ ... }` syntax on the import
49+
import { HashHistory } from 'react-router/lib/HashHistory';
50+
51+
// use the default key which is `_key`
52+
var history = new HashHistory({ queryKey: true });
53+
54+
// use your own
55+
var history = new HashHistory({queryKey: 'k'});
56+
57+
React.render((
58+
<Router history={history}>
59+
{/* ... */}
60+
</Router>
61+
), document.body);
3162
```
3263

3364
[Histories]:#TODO

0 commit comments

Comments
 (0)