Skip to content

Commit 2389c61

Browse files
committed
[changed] Export history classes
This commit normalizes the way we export history classes. Instead of automatically creating a new Browser/HashHistory for people when they require the module, we just export the class like we do with History and MemoryHistory. This gives us a few things: 1) We don't have to explain to people that they need to import { HashHistory } in order to create their own HashHistory. 2) We don't require people using CommonJS to var HashHistory = require('react-router/lib/HashHistory').default which sucks
1 parent 285a61f commit 2389c61

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

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 History from 'react-router/lib/BrowserHistory';
46+
import BrowserHistory from 'react-router/lib/BrowserHistory';
4747

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

doc/03 History/HashHistory.md

Lines changed: 3 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 History from 'react-router/lib/HashHistory';
36+
import HashHistory from 'react-router/lib/HashHistory';
3737

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

4747
```js
48-
import { HashHistory } from 'react-router/lib/HashHistory';
48+
import HashHistory from 'react-router/lib/HashHistory';
4949

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

modules/BrowserHistory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function updateCurrentState(extraState) {
1919
* refreshes if HTML5 history is not available, so URLs are always
2020
* the same across browsers.
2121
*/
22-
export class BrowserHistory extends DOMHistory {
22+
class BrowserHistory extends DOMHistory {
2323

2424
constructor(options) {
2525
super(options);
@@ -108,4 +108,4 @@ export class BrowserHistory extends DOMHistory {
108108

109109
}
110110

111-
export default new BrowserHistory;
111+
export default BrowserHistory;

modules/HashHistory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ function updateCurrentState(queryKey, extraState) {
6262
* Support for persistence of state across page refreshes is provided using a
6363
* combination of a URL query string parameter and DOM storage. However, this
6464
* support is not enabled by default. In order to use it, create your own
65-
* HashHistory, like this:
65+
* HashHistory.
6666
*
67-
* import { HashHistory } from 'react-router/lib/HashHistory';
67+
* import HashHistory from 'react-router/lib/HashHistory';
6868
* var StatefulHashHistory = new HashHistory({ queryKey: '_key' });
6969
* React.render(<Router history={StatefulHashHistory} .../>, ...);
7070
*/
71-
export class HashHistory extends DOMHistory {
71+
class HashHistory extends DOMHistory {
7272

7373
constructor(options={}) {
7474
super(options);
@@ -170,4 +170,4 @@ export class HashHistory extends DOMHistory {
170170

171171
}
172172

173-
export default new HashHistory;
173+
export default HashHistory;

modules/__tests__/BrowserHistory-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import describeHistory from './describeHistory';
22
import BrowserHistory from '../BrowserHistory';
33

44
describe('BrowserHistory', function () {
5-
describeHistory(BrowserHistory);
5+
describeHistory(new BrowserHistory);
66
});

modules/__tests__/HashHistory-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import describeHistory from './describeHistory';
22
import HashHistory from '../HashHistory';
33

44
describe('HashHistory', function () {
5-
describeHistory(HashHistory);
5+
describeHistory(new HashHistory);
66
});

modules/__tests__/scrollManagement-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import expect from 'expect';
22
import React, { render } from 'react';
3-
import { HashHistory } from '../HashHistory';
3+
import HashHistory from '../HashHistory';
44
import { getWindowScrollPosition } from '../DOMUtils';
55
import Router from '../Router';
66
import Route from '../Route';

0 commit comments

Comments
 (0)