Skip to content

Commit 593b055

Browse files
committed
Use stable release of React Router v4
Apparently, it now uses react-router-dom package, which is designed to be used within browser environments
1 parent e986ece commit 593b055

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"react-addons-test-utils": "^15.4.2",
7777
"react-bootstrap": "^0.30.0",
7878
"react-dom": "^15.2.1",
79-
"react-router": "4.0.0-beta.5",
79+
"react-router-dom": "^4.0.0",
8080
"release-script": "^1.0.2",
8181
"rimraf": "^2.5.4",
8282
"shelljs": "^0.7.2",

src/LinkContainer.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import React, { Component, PropTypes } from 'react';
2-
import { Route } from 'react-router';
2+
import { Route } from 'react-router-dom';
33

44
const isModifiedEvent = (event) =>
55
!!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
66

77
export default class LinkContainer extends Component {
88
static contextTypes = {
99
router: PropTypes.shape({
10-
push: PropTypes.func.isRequired,
11-
replace: PropTypes.func.isRequired,
12-
createHref: PropTypes.func.isRequired,
10+
history: PropTypes.shape({
11+
push: PropTypes.func.isRequired,
12+
replace: PropTypes.func.isRequired,
13+
createHref: PropTypes.func.isRequired
14+
}).isRequired
1315
}).isRequired,
1416
};
1517

@@ -50,18 +52,17 @@ export default class LinkContainer extends Component {
5052
if (
5153
!event.defaultPrevented && // onClick prevented default
5254
event.button === 0 && // ignore right clicks
53-
!this.props.target && // let browser handle "target=_blank" etc.
5455
!isModifiedEvent(event) // ignore clicks with modifier keys
5556
) {
5657
event.preventDefault();
5758

58-
const { router } = this.context;
59+
const { history } = this.context.router;
5960
const { replace, to } = this.props;
6061

6162
if (replace) {
62-
router.replace(to);
63+
history.replace(to);
6364
} else {
64-
router.push(to);
65+
history.push(to);
6566
}
6667
}
6768
}
@@ -81,7 +82,7 @@ export default class LinkContainer extends Component {
8182
...props,
8283
} = this.props;
8384

84-
const href = this.context.router.createHref(
85+
const href = this.context.router.history.createHref(
8586
typeof to === 'string' ? { pathname: to } : to
8687
);
8788

@@ -97,7 +98,7 @@ export default class LinkContainer extends Component {
9798
React.Children.only(children),
9899
{
99100
...props,
100-
className: (className || '') + (isActive ? activeClassName : ''),
101+
className: isActive ? [className, activeClassName].join(' ') : className,
101102
style: isActive ? { ...style, ...activeStyle } : style,
102103
href,
103104
onClick: this.handleClick,

test/IndexLinkContainer.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ReactTestUtils from 'react-addons-test-utils';
33
import * as ReactBootstrap from 'react-bootstrap';
44
import { findDOMNode } from 'react-dom';
5-
import { Route, MemoryRouter as Router } from 'react-router';
5+
import { Route, MemoryRouter as Router } from 'react-router-dom';
66

77
import IndexLinkContainer from '../src/IndexLinkContainer';
88

test/LinkContainer.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ReactTestUtils from 'react-addons-test-utils';
33
import * as ReactBootstrap from 'react-bootstrap';
44
import { findDOMNode } from 'react-dom';
5-
import { Route, MemoryRouter as Router } from 'react-router';
5+
import { Route, MemoryRouter as Router } from 'react-router-dom';
66

77
import LinkContainer from '../src/LinkContainer';
88

0 commit comments

Comments
 (0)