1
1
import * as React from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
+ import { push } from 'react-router-redux' ;
3
4
import UserAction from '../../stores/user/UserAction' ;
4
5
import MetaAction from '../../stores/meta/MetaAction' ;
5
6
import IStore from '../../stores/IStore' ;
@@ -13,6 +14,7 @@ interface IStateToProps {
13
14
readonly user : IUserReducerState ;
14
15
}
15
16
interface IDispatchToProps {
17
+ historyPush : ( route : string ) => void ;
16
18
loadUser : ( ) => void ;
17
19
setMeta : ( meta : IMetaReducerState ) => void ;
18
20
}
@@ -21,12 +23,15 @@ const mapStateToProps = (state: IStore): IStateToProps => ({
21
23
user : state . userReducer ,
22
24
} ) ;
23
25
const mapDispatchToProps = ( dispatch : Dispatch < IStore > ) : IDispatchToProps => ( {
26
+ historyPush : ( route : string ) => dispatch ( push ( route ) ) ,
24
27
loadUser : ( ) => dispatch ( UserAction . loadUser ( ) ) ,
25
28
setMeta : ( meta : IMetaReducerState ) => dispatch ( MetaAction . setMeta ( meta ) ) ,
26
29
} ) ;
27
30
28
31
class Home extends React . Component < IStateToProps & IDispatchToProps & IProps , IState > {
29
32
33
+ private _onClickPushExampleHandler : ( event : React . MouseEvent < HTMLButtonElement > ) => void = this . _onClickPushExample . bind ( this ) ;
34
+
30
35
public componentWillMount ( ) : void {
31
36
this . props . setMeta ( {
32
37
title : 'Home Page' ,
@@ -55,10 +60,17 @@ class Home extends React.Component<IStateToProps & IDispatchToProps & IProps, IS
55
60
</ button >
56
61
</ p >
57
62
</ div >
63
+ < button onClick = { this . _onClickPushExampleHandler } > { 'Go to About' } </ button >
58
64
</ div >
59
65
) ;
60
66
}
61
67
68
+ private _onClickPushExample ( event : React . MouseEvent < HTMLButtonElement > ) : void {
69
+ event . preventDefault ( ) ;
70
+
71
+ this . props . historyPush ( '/About' ) ;
72
+ }
73
+
62
74
}
63
75
64
76
export default connect < IStateToProps , IDispatchToProps , IProps > ( mapStateToProps , mapDispatchToProps ) ( Home ) ;
0 commit comments