Skip to content

Commit c1c8eb5

Browse files
committed
Merge pull request #1429 from Schniz/history-singletons
History singletons
2 parents 3fe4d7d + fb5de73 commit c1c8eb5

File tree

23 files changed

+44
-45
lines changed

23 files changed

+44
-45
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ What's it look like?
6666

6767
```js
6868
import { Router, Route } from 'react-router';
69-
import BrowserHistory from 'react-router/lib/BrowserHistory';
69+
import { history } from 'react-router/lib/BrowserHistory';
7070

7171
var App = React.createClass({/*...*/});
7272
var About = React.createClass({/*...*/});
@@ -115,7 +115,7 @@ var User = React.createClass({
115115
// instead, all you really need is a single root route, you don't need to
116116
// colocate the entire config).
117117
React.render((
118-
<Router history={new BrowserHistory}>
118+
<Router history={history}>
119119
<Route path="/" component={App}>
120120
<Route path="about" component={About}/>
121121
<Route path="users" component={Users}>

doc/00 Guides/0 Overview.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Let's refactor our app to use React Router.
111111
// first we import some components
112112
import { Router, Route, Link } from 'react-router';
113113
// the histories are imported separately for smaller builds
114-
import HashHistory from 'react-router/lib/HashHistory';
114+
import { history } from 'react-router/lib/HashHistory';
115115

116116
// ...
117117

@@ -141,7 +141,7 @@ var App = React.createClass({
141141
// Finally we render a `Router` component with some `Route`s, it'll do all
142142
// the fancy routing stuff for us.
143143
React.render((
144-
<Router history={new HashHistory}>
144+
<Router history={history}>
145145
<Route path="/" component={App}>
146146
<Route path="about" component={About}/>
147147
<Route path="inbox" component={Inbox}/>
@@ -162,7 +162,7 @@ var routes = {
162162
]
163163
};
164164

165-
React.render(<Router history={new HashHistory} children={routes}/>, document.body);
165+
React.render(<Router history={history} children={routes}/>, document.body);
166166
```
167167

168168
Adding more UI
@@ -191,7 +191,7 @@ var Inbox = React.createClass({
191191
});
192192

193193
React.render((
194-
<Router history={new HashHistory}>
194+
<Router history={history}>
195195
<Route component={App}>
196196
<Route path="about" component={About}/>
197197
<Route path="inbox" component={Inbox}>
@@ -230,4 +230,3 @@ var Message = React.createClass({
230230
That's the gist of React Router. Application UIs are boxes inside of
231231
boxes inside of boxes; now you can keep those boxes in sync with the
232232
URL.
233-

doc/03 History/0 Histories.md

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

55
```js
6-
import History from 'react-router/lib/BrowserHistory';
7-
<Router history={History}/>
6+
import { history } from 'react-router/lib/BrowserHistory';
7+
<Router history={history}/>
88
```
99

1010
If you need to do your own query parsing:

doc/03 History/BrowserHistory.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ 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={new BrowserHistory}>
49+
<Router history={ history }>
5050
{/* ... */}
5151
</Router>
5252
), document.body);
5353
```
5454

5555
[Histories]:#TODO
56-

doc/03 History/HashHistory.md

Lines changed: 2 additions & 3 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={new HashHistory}>
39+
<Router history={history}>
4040
{/* ... */}
4141
</Router>
4242
), document.body);
@@ -61,4 +61,3 @@ React.render((
6161
```
6262

6363
[Histories]:#TODO
64-

examples/animations/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { cloneElement } from 'react/addons';
2-
import HashHistory from 'react-router/lib/HashHistory';
2+
import { history } from 'react-router/lib/HashHistory';
33
import { Router, Route, Link } from 'react-router';
44

55
var { CSSTransitionGroup } = React.addons;
@@ -46,7 +46,7 @@ var Page2 = React.createClass({
4646

4747

4848
React.render((
49-
<Router history={new HashHistory}>
49+
<Router history={history}>
5050
<Route path="/" component={App}>
5151
<Route path="page1" component={Page1} />
5252
<Route path="page2" component={Page2} />

examples/async-data/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import HashHistory from 'react-router/lib/HashHistory';
2+
import { history } from 'react-router/lib/HashHistory';
33
import { Router, Route, Link, Navigation } from 'react-router';
44
import { loadContacts, loadContact, createContact } from './utils';
55
import AsyncProps from 'react-router/lib/experimental/AsyncProps';
@@ -106,7 +106,7 @@ var Index = React.createClass({
106106
});
107107

108108
React.render((
109-
<Router history={new HashHistory} createElement={AsyncProps.createElement}>
109+
<Router history={history} createElement={AsyncProps.createElement}>
110110
<Route component={AsyncProps} renderInitialLoad={() => <Spinner/> }>
111111
<Route component={App}>
112112
<Route path="/" component={Index}/>

examples/auth-flow/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { findDOMNode } from 'react';
22
import { Router, Route, Link, Navigation } from 'react-router';
33
import HashHistory from 'react-router/lib/HashHistory';
44
import auth from './auth';
5+
var history = new HashHistory({ queryKey: true });
56

67
var App = React.createClass({
78
getInitialState() {
@@ -120,7 +121,7 @@ function requireAuth(nextState, transition) {
120121
}
121122

122123
React.render((
123-
<Router history={new HashHistory({ queryKey: true })}>
124+
<Router history={history}>
124125
<Route path="/" component={App}>
125126
<Route path="login" component={Login}/>
126127
<Route path="logout" component={Logout}/>

examples/dynamic-segments/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import HashHistory from 'react-router/lib/HashHistory';
2+
import { history } from 'react-router/lib/HashHistory';
33
import { Router, Route, Link, Redirect } from 'react-router';
44

55
var App = React.createClass({
@@ -47,7 +47,7 @@ var Task = React.createClass({
4747
});
4848

4949
React.render((
50-
<Router history={new HashHistory}>
50+
<Router history={history}>
5151
<Route path="/" component={App}>
5252
<Route path="user/:userID" component={User}>
5353
<Route path="tasks/:taskID" component={Task}/>

examples/huge-apps/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import HashHistory from 'react-router/lib/HashHistory';
2+
import { history } from 'react-router/lib/HashHistory';
33
import { Router } from 'react-router';
44
import AsyncProps from 'react-router/lib/experimental/AsyncProps';
55
import stubbedCourses from './stubs/COURSES';
@@ -28,7 +28,7 @@ var rootRoute = {
2828
React.render((
2929
<Router
3030
routes={rootRoute}
31-
history={new HashHistory}
31+
history={history}
3232
createElement={AsyncProps.createElement}
3333
/>
3434
), document.getElementById('example'));

0 commit comments

Comments
 (0)