Skip to content

Commit acd7ced

Browse files
committed
Add some docs about query parsing/stringifying
1 parent 072f990 commit acd7ced

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

doc/00 Guides/Server Rendering.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ synchronously.
2525

2626
```js
2727
// server.js
28-
import { Router } from 'react-router';
29-
import ServerHistory from 'react-router/lib/ServerHistory';
28+
import { Router, Location } from 'react-router';
3029
import routes from './routes';
3130

3231
// you'll want to configure your server to serve up static assets, and
3332
// and then handle the rest with React Router
3433
serveNonStaticPaths((req, res) => {
35-
var history = new ServerHistory(req.path);
36-
Router.match(routes, history, (err, initialState) => {
37-
// do your own data fetching, perhaps using the branch of components
38-
// in the initialState
34+
var location = new Location('/the/path', { the: 'query' });
35+
36+
Router.match(routes, location, (err, transition, initialState) => {
37+
// do your own data fetching, perhaps using the
38+
// branch of components in the initialState
3939
fetchSomeData(initialState.components, (err, initialData) => {
4040
var html = React.renderToString(
4141
<Router history={history} {...initialState}/>

doc/02 Components/0 Router.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ route components nested inside the parents.
1515

1616
Alias for `children`.
1717

18-
### `history` (required)
18+
### `history`
1919

2020
The [`History`][History] the router should set up and listen for changes
2121
on. When the history gets new entries, the router will update its state
@@ -29,6 +29,11 @@ of creating the elements when you're using some sort of data
2929
abstraction, like setting up subscriptions to stores, or passing in some
3030
sort of application module to each component via props.
3131

32+
### `stringifyQuery(query)`
33+
34+
A function that should be used to convert an object to a URL query string.
35+
By default, this function uses `qs.stringify(query, { arrayFormat: 'brackets' })`.
36+
3237

3338
#### Examples
3439

doc/03 History/0 Histories.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@
33
an instance of one with your own options for query parsing.
44

55
```js
6-
// typical usage
7-
import BrowserHistory from 'react-router/lib/BrowserHistory';
8-
<Router history={BrowserHistory}/>
6+
import History from 'react-router/lib/BrowserHistory';
7+
<Router history={History}/>
98
```
109

1110
If you need to do your own query parsing:
1211

1312
```js
14-
// note the `{ ... }` in the import statement...
1513
import { BrowserHistory } from 'react-router/lib/BrowserHistory';
16-
// ...this gives you a class instead of a singleton instance
1714

1815
var history = new BrowserHistory({
1916
parseQueryString(string) {
2017
return customParse(string);
21-
},
22-
stringifyQuery(obj) {
23-
return customStringify(obj);
2418
}
2519
});
2620

2721
var router = <Router history={history}/>;
2822
```
29-

doc/03 History/BrowserHistory.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Example
4343

4444
```js
4545
import { Router } from 'react-router';
46-
import BrowserHistory from 'react-router/lib/BrowserHistory';
46+
import History from 'react-router/lib/BrowserHistory';
4747

4848
React.render((
49-
<Router history={BrowserHistory}>
49+
<Router history={History}>
5050
{/* ... */}
5151
</Router>
5252
), document.body);

doc/03 History/HashHistory.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Normal usage
3333

3434
```js
3535
import { Router } from 'react-router';
36-
import HashHistory from 'react-router/lib/HashHistory';
36+
import History from 'react-router/lib/HashHistory';
3737

3838
React.render((
39-
<Router history={HashHistory}>
39+
<Router history={History}>
4040
{/* ... */}
4141
</Router>
4242
), document.body);
@@ -45,14 +45,13 @@ React.render((
4545
Opting in to the `state` features:
4646

4747
```js
48-
// note the `{ ... }` syntax on the import
4948
import { HashHistory } from 'react-router/lib/HashHistory';
5049

5150
// use the default key which is `_key`
5251
var history = new HashHistory({ queryKey: true });
5352

5453
// use your own
55-
var history = new HashHistory({queryKey: 'k'});
54+
var history = new HashHistory({ queryKey: 'k' });
5655

5756
React.render((
5857
<Router history={history}>

doc/03 History/MemoryHistory.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Example
1010
import { Router } from 'react-router';
1111
import MemoryHistory from 'react-router/lib/MemoryHistory';
1212

13+
var history = new MemoryHistory([ '/', '/a/path' ]);
14+
1315
React.render((
14-
<Router history={MemoryHistory}>
16+
<Router history={history}>
1517
{/* ... */}
1618
</Router>
1719
), document.body);
1820
```
1921

20-
21-
2222
[Histories]:#TODO
2323

0 commit comments

Comments
 (0)