1
1
import React , { Component , PropTypes } from 'react' ;
2
- import { Route } from 'react-router' ;
2
+ import { Route } from 'react-router-dom ' ;
3
3
4
4
const isModifiedEvent = ( event ) =>
5
5
! ! ( event . metaKey || event . altKey || event . ctrlKey || event . shiftKey ) ;
6
6
7
7
export default class LinkContainer extends Component {
8
8
static contextTypes = {
9
9
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
13
15
} ) . isRequired ,
14
16
} ;
15
17
@@ -50,18 +52,17 @@ export default class LinkContainer extends Component {
50
52
if (
51
53
! event . defaultPrevented && // onClick prevented default
52
54
event . button === 0 && // ignore right clicks
53
- ! this . props . target && // let browser handle "target=_blank" etc.
54
55
! isModifiedEvent ( event ) // ignore clicks with modifier keys
55
56
) {
56
57
event . preventDefault ( ) ;
57
58
58
- const { router } = this . context ;
59
+ const { history } = this . context . router ;
59
60
const { replace, to } = this . props ;
60
61
61
62
if ( replace ) {
62
- router . replace ( to ) ;
63
+ history . replace ( to ) ;
63
64
} else {
64
- router . push ( to ) ;
65
+ history . push ( to ) ;
65
66
}
66
67
}
67
68
}
@@ -81,7 +82,7 @@ export default class LinkContainer extends Component {
81
82
...props ,
82
83
} = this . props ;
83
84
84
- const href = this . context . router . createHref (
85
+ const href = this . context . router . history . createHref (
85
86
typeof to === 'string' ? { pathname : to } : to
86
87
) ;
87
88
@@ -97,7 +98,7 @@ export default class LinkContainer extends Component {
97
98
React . Children . only ( children ) ,
98
99
{
99
100
...props ,
100
- className : ( className || '' ) + ( isActive ? activeClassName : '' ) ,
101
+ className : isActive ? [ className , activeClassName ] . join ( ' ' ) : className ,
101
102
style : isActive ? { ...style , ...activeStyle } : style ,
102
103
href,
103
104
onClick : this . handleClick ,
0 commit comments