Skip to content
Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ What's it look like?

```js
import { Router, Route } from 'react-router';
import BrowserHistory from 'react-router/lib/BrowserHistory';
import { history } from 'react-router/lib/BrowserHistory';

var App = React.createClass({/*...*/});
var About = React.createClass({/*...*/});
Expand Down Expand Up @@ -115,7 +115,7 @@ var User = React.createClass({
// instead, all you really need is a single root route, you don't need to
// colocate the entire config).
React.render((
<Router history={new BrowserHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
<Route path="users" component={Users} indexComponent={RecentUsers}>
Expand Down
9 changes: 4 additions & 5 deletions doc/00 Guides/0 Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Let's refactor our app to use React Router.
// first we import some components
import { Router, Route, Link } from 'react-router';
// the histories are imported separately for smaller builds
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';

// ...

Expand Down Expand Up @@ -141,7 +141,7 @@ var App = React.createClass({
// Finally we render a `Router` component with some `Route`s, it'll do all
// the fancy routing stuff for us.
React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
<Route path="inbox" component={Inbox}/>
Expand All @@ -162,7 +162,7 @@ var routes = {
]
};

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

Adding more UI
Expand Down Expand Up @@ -191,7 +191,7 @@ var Inbox = React.createClass({
});

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

4 changes: 2 additions & 2 deletions doc/03 History/0 Histories.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
an instance of one with your own options for query parsing.

```js
import History from 'react-router/lib/BrowserHistory';
<Router history={History}/>
import { history } from 'react-router/lib/BrowserHistory';
<Router history={history}/>
```

If you need to do your own query parsing:
Expand Down
5 changes: 2 additions & 3 deletions doc/03 History/BrowserHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ Example

```js
import { Router } from 'react-router';
import BrowserHistory from 'react-router/lib/BrowserHistory';
import { history } from 'react-router/lib/BrowserHistory';

React.render((
<Router history={new BrowserHistory}>
<Router history={ history }>
{/* ... */}
</Router>
), document.body);
```

[Histories]:#TODO

5 changes: 2 additions & 3 deletions doc/03 History/HashHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Normal usage

```js
import { Router } from 'react-router';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';

React.render((
<Router history={new HashHistory}>
<Router history={history}>
{/* ... */}
</Router>
), document.body);
Expand All @@ -61,4 +61,3 @@ React.render((
```

[Histories]:#TODO

4 changes: 2 additions & 2 deletions examples/animations/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { cloneElement } from 'react/addons';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link } from 'react-router';

var { CSSTransitionGroup } = React.addons;
Expand Down Expand Up @@ -46,7 +46,7 @@ var Page2 = React.createClass({


React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="page1" component={Page1} />
<Route path="page2" component={Page2} />
Expand Down
4 changes: 2 additions & 2 deletions examples/async-data/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link, Navigation } from 'react-router';
import { loadContacts, loadContact, createContact } from './utils';
import AsyncProps from 'react-router/lib/experimental/AsyncProps';
Expand Down Expand Up @@ -106,7 +106,7 @@ var Index = React.createClass({
});

React.render((
<Router history={new HashHistory} createElement={AsyncProps.createElement}>
<Router history={history} createElement={AsyncProps.createElement}>
<Route component={AsyncProps} renderInitialLoad={() => <Spinner/> }>
<Route component={App}>
<Route path="/" component={Index}/>
Expand Down
3 changes: 2 additions & 1 deletion examples/auth-flow/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { findDOMNode } from 'react';
import { Router, Route, Link, Navigation } from 'react-router';
import HashHistory from 'react-router/lib/HashHistory';
import auth from './auth';
var history = new HashHistory({ queryKey: true });

var App = React.createClass({
getInitialState() {
Expand Down Expand Up @@ -120,7 +121,7 @@ function requireAuth(nextState, transition) {
}

React.render((
<Router history={new HashHistory({ queryKey: true })}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="login" component={Login}/>
<Route path="logout" component={Logout}/>
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic-segments/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link, Redirect } from 'react-router';

var App = React.createClass({
Expand Down Expand Up @@ -47,7 +47,7 @@ var Task = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="user/:userID" component={User}>
<Route path="tasks/:taskID" component={Task}/>
Expand Down
4 changes: 2 additions & 2 deletions examples/huge-apps/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router } from 'react-router';
import AsyncProps from 'react-router/lib/experimental/AsyncProps';
import stubbedCourses from './stubs/COURSES';
Expand Down Expand Up @@ -28,7 +28,7 @@ var rootRoute = {
React.render((
<Router
routes={rootRoute}
history={new HashHistory}
history={history}
createElement={AsyncProps.createElement}
/>
), document.getElementById('example'));
4 changes: 2 additions & 2 deletions examples/master-detail/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { findDOMNode } from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Navigation, Route, Link } from 'react-router';
import ContactStore from './ContactStore';

Expand Down Expand Up @@ -150,7 +150,7 @@ var NotFound = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route component={App}>
<Route path="/" component={Index}/>
<Route path="contact/new" component={NewContact}/>
Expand Down
4 changes: 2 additions & 2 deletions examples/passing-props-to-children/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var React = require('react');
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
var { Router, Route, Link, Navigation } = require('react-router');

var App = React.createClass({
Expand Down Expand Up @@ -72,7 +72,7 @@ var Taco = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="taco/:name" component={Taco}/>
</Route>
Expand Down
4 changes: 2 additions & 2 deletions examples/pinterest/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Router, Link } from 'react-router';
import HashHistory from 'react-router/lib/HashHistory';
var history = new HashHistory({ queryKey: 'k' });

var pictures = [
{id: 0, src: 'http://placekitten.com/601/601'},
Expand Down Expand Up @@ -127,7 +128,7 @@ var RootRoute = {
};

React.render(
<Router history={new HashHistory({ queryKey: 'k' })} children={RootRoute}/>,
<Router history={history} children={RootRoute}/>,
document.getElementById('example')
);

Expand Down Expand Up @@ -160,4 +161,3 @@ React.render(
//
// 10. I am very glad there aren't ten steps to explain this ...
//

4 changes: 2 additions & 2 deletions examples/query-params/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link } from 'react-router';

var User = React.createClass({
Expand Down Expand Up @@ -32,7 +32,7 @@ var App = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="user/:userID" component={User}/>
</Route>
Expand Down
4 changes: 2 additions & 2 deletions examples/shared-root/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link } from 'react-router';

var App = React.createClass({
Expand Down Expand Up @@ -70,7 +70,7 @@ var ForgotPassword = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route component={SignedOut}>
<Route path="signin" component={SignIn}/>
Expand Down
4 changes: 2 additions & 2 deletions examples/sidebar/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';
import { Router, Route, Link } from 'react-router';
import data from './data';

Expand Down Expand Up @@ -93,7 +93,7 @@ var App = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="category/:category" components={{content: Category, sidebar: CategorySidebar}}>
<Route path=":item" component={Item}/>
Expand Down
4 changes: 2 additions & 2 deletions examples/transitions/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { findDOMNode } from 'react';
import { Router, Route, Link, Navigation, TransitionHook } from 'react-router';
import HashHistory from 'react-router/lib/HashHistory';
import { history } from 'react-router/lib/HashHistory';

var App = React.createClass({
render() {
Expand Down Expand Up @@ -57,7 +57,7 @@ var Form = React.createClass({
});

React.render((
<Router history={new HashHistory}>
<Router history={history}>
<Route path="/" component={App}>
<Route path="dashboard" component={Dashboard}/>
<Route path="form" component={Form}/>
Expand Down
2 changes: 1 addition & 1 deletion modules/BrowserHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BrowserHistory extends DOMHistory {
window.location.replace(path);
}
}

}

export var history = new BrowserHistory;
export default BrowserHistory;
1 change: 0 additions & 1 deletion modules/DOMHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getWindowScrollPosition } from './DOMUtils';
* A history interface that assumes a DOM environment.
*/
class DOMHistory extends History {

constructor(options={}) {
super(options);
this.getScrollPosition = options.getScrollPosition || getWindowScrollPosition;
Expand Down
4 changes: 2 additions & 2 deletions modules/HashHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function saveState(path, queryKey, state) {
function readState(path, queryKey) {
var sessionKey = getQueryStringValueFromPath(path, queryKey);
var json = sessionKey && window.sessionStorage.getItem(sessionKey);

if (json) {
try {
return JSON.parse(json);
Expand Down Expand Up @@ -167,7 +167,7 @@ class HashHistory extends DOMHistory {
makeHref(path) {
return '#' + path;
}

}

export var history = new HashHistory;
export default HashHistory;
3 changes: 2 additions & 1 deletion modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import describeHistory from './describeHistory';
import BrowserHistory from '../BrowserHistory';
import BrowserHistory, { history } from '../BrowserHistory';

describe('BrowserHistory', function () {
describeHistory(new BrowserHistory);
describeHistory(history);
});
3 changes: 2 additions & 1 deletion modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import describeHistory from './describeHistory';
import HashHistory from '../HashHistory';
import HashHistory, { history } from '../HashHistory';

describe('HashHistory', function () {
describeHistory(new HashHistory);
describeHistory(history);
});
2 changes: 1 addition & 1 deletion modules/__tests__/MemoryHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('MemoryHistory', function () {
it('cannot go forward', function () {
expect(history.canGoForward()).toBe(false);
});

describe('and then replacing that path', function () {
beforeEach(function () {
history.replaceState(null, '/replace');
Expand Down