11import agent from '../agent' ;
22import Header from './Header' ;
33import React from 'react' ;
4- import PropTypes from 'prop-types' ;
54import { connect } from 'react-redux' ;
65import { 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' ;
717
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+ } } ;
1425
1526const mapDispatchToProps = dispatch => ( {
1627 onLoad : ( payload , token ) =>
@@ -22,7 +33,8 @@ const mapDispatchToProps = dispatch => ({
2233class App extends React . Component {
2334 componentWillReceiveProps ( nextProps ) {
2435 if ( nextProps . redirectTo ) {
25- this . context . router . replace ( nextProps . redirectTo ) ;
36+ // this.context.router.replace(nextProps.redirectTo);
37+ store . dispatch ( push ( nextProps . redirectTo ) ) ;
2638 this . props . onRedirect ( ) ;
2739 }
2840 }
@@ -43,7 +55,17 @@ class App extends React.Component {
4355 < Header
4456 appName = { this . props . appName }
4557 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 >
4769 </ div >
4870 ) ;
4971 }
@@ -57,8 +79,8 @@ class App extends React.Component {
5779 }
5880}
5981
60- App . contextTypes = {
61- router : PropTypes . object . isRequired
62- } ;
82+ // App.contextTypes = {
83+ // router: PropTypes.object.isRequired
84+ // };
6385
6486export default connect ( mapStateToProps , mapDispatchToProps ) ( App ) ;
0 commit comments