1
1
import agent from '../agent' ;
2
2
import Header from './Header' ;
3
3
import React from 'react' ;
4
- import PropTypes from 'prop-types' ;
5
4
import { connect } from 'react-redux' ;
6
5
import { APP_LOAD , REDIRECT } from '../constants/actionTypes' ;
6
+ import { Route , Switch } from 'react-router-dom' ;
7
+ import Article from '../components/Article' ;
8
+ import Editor from '../components/Editor' ;
9
+ import Home from '../components/Home' ;
10
+ import Login from '../components/Login' ;
11
+ import Profile from '../components/Profile' ;
12
+ import ProfileFavorites from '../components/ProfileFavorites' ;
13
+ import Register from '../components/Register' ;
14
+ import Settings from '../components/Settings' ;
15
+ import { store } from '../store' ;
16
+ import { push } from 'react-router-redux' ;
7
17
8
- const mapStateToProps = state => ( {
9
- appLoaded : state . common . appLoaded ,
10
- appName : state . common . appName ,
11
- currentUser : state . common . currentUser ,
12
- redirectTo : state . common . redirectTo
13
- } ) ;
18
+ const mapStateToProps = state => {
19
+ return {
20
+ appLoaded : state . common . appLoaded ,
21
+ appName : state . common . appName ,
22
+ currentUser : state . common . currentUser ,
23
+ redirectTo : state . common . redirectTo
24
+ } } ;
14
25
15
26
const mapDispatchToProps = dispatch => ( {
16
27
onLoad : ( payload , token ) =>
@@ -22,7 +33,8 @@ const mapDispatchToProps = dispatch => ({
22
33
class App extends React . Component {
23
34
componentWillReceiveProps ( nextProps ) {
24
35
if ( nextProps . redirectTo ) {
25
- this . context . router . replace ( nextProps . redirectTo ) ;
36
+ // this.context.router.replace(nextProps.redirectTo);
37
+ store . dispatch ( push ( nextProps . redirectTo ) ) ;
26
38
this . props . onRedirect ( ) ;
27
39
}
28
40
}
@@ -43,7 +55,17 @@ class App extends React.Component {
43
55
< Header
44
56
appName = { this . props . appName }
45
57
currentUser = { this . props . currentUser } />
46
- { this . props . children }
58
+ < Switch >
59
+ < Route exact path = "/" component = { Home } />
60
+ < Route path = "/login" component = { Login } />
61
+ < Route path = "/register" component = { Register } />
62
+ < Route path = "/editor/:slug" component = { Editor } />
63
+ < Route path = "/editor" component = { Editor } />
64
+ < Route path = "/article/:id" component = { Article } />
65
+ < Route path = "/settings" component = { Settings } />
66
+ < Route path = "/@:username/favorites" component = { ProfileFavorites } />
67
+ < Route path = "/@:username" component = { Profile } />
68
+ </ Switch >
47
69
</ div >
48
70
) ;
49
71
}
@@ -57,8 +79,8 @@ class App extends React.Component {
57
79
}
58
80
}
59
81
60
- App . contextTypes = {
61
- router : PropTypes . object . isRequired
62
- } ;
82
+ // App.contextTypes = {
83
+ // router: PropTypes.object.isRequired
84
+ // };
63
85
64
86
export default connect ( mapStateToProps , mapDispatchToProps ) ( App ) ;
0 commit comments