title: withRouter and connect() cause app to crash
body: <p>I am trying to use withRouter so I can push to the history to redirect a user once they register on. It was working perfect before until I decided to implement react-redux and such. I added the connect() HOC to the Login component and now the App fails to load as when I put withRouter() within the Register component. I have already tried </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>withRouter(connect(...)(MyComponent))</code></pre>
  </div>
  </div>
  </p>
  
  <p>but it does not work. I am at a loss to what to do. </p>
  
  <p>Register.js</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React from "react";
  import "./Register.css";
  import { withRouter } from 'react-router';
  const initialUser = {
    username: "",
    email: "",
    password: "",
    password2: "",
    name: ""
  };
  
  class Register extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        user: initialUser,
        registered: ""
      };
    }
  
    handleChange = event =&gt; {
      this.setState({
        user: {
          ...this.state.user,
          [event.target.name]: event.target.value
        }
      });
    };
  
  
    isRegistered = () =&gt; {
      const { registered } = this.state;
      if (registered) {
        this.props.context.history.push('/path')
      }
    };
  
    onRegister = event =&gt; {
      event.preventDefault();
      fetch("http://localhost:3000/register", {
        method: "post",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(this.state.user)
      })
        .then(res =&gt; res.json())
        .then(data =&gt; {
          if (data.isRegistered) {
            this.setState({ registered: true });
            this.isRegistered();
          }
        });
    };
  
    render() {
      return (
        &lt;div className="login-page"&gt;
          &lt;div className="form"&gt;
            &lt;form className="login-form" onSubmit={this.onRegister}&gt;
              &lt;input
                type="text"
                placeholder="name"
                name="name"
                value={this.state.user.name}
                onChange={this.handleChange}
              /&gt;
              &lt;input
                type="text"
                placeholder="username"
                name="username"
                value={this.state.user.username}
                onChange={this.handleChange}
              /&gt;
              &lt;input
                type="text"
                placeholder="email"
                name="email"
                value={this.state.user.email}
                onChange={this.handleChange}
              /&gt;
              &lt;input
                type="password"
                placeholder="password"
                name="password"
                value={this.state.user.password}
                onChange={this.handleChange}
              /&gt;
              &lt;input
                type="password"
                placeholder="confirm password"
                name="password2"
                value={this.state.user.password2}
                onChange={this.handleChange}
              /&gt;
              &lt;button className="bluecolor" type="submit"&gt;
                Register
              &lt;/button&gt;
              &lt;p className="message"&gt;
                Have an account? &lt;a href="/login"&gt;Login&lt;/a&gt;
              &lt;/p&gt;
            &lt;/form&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default withRouter(Register);</code></pre>
  </div>
  </div>
  </p>
  
  <p>Login.js</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React from "react";
  import { connect } from 'react-redux';
  import { setUserStatus } from '../../../actions'
  
  const mapStateToProps = state =&gt; {
    console.log('mapstate', state.isLoggedIn)
    return {
      isLoggedIn: state.isLoggedIn
    }
  }
  const mapDispatchToProps = (dispatch) =&gt; {
    return {
      onLoggedInSuccess: () =&gt; dispatch(setUserStatus(true))
    }
  } 
  
  const initialUser = {
    username: "",
    password: "",
  };
  
  class Login extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        user: initialUser,
        loggedIn: false
      };
    }
  
    handleChange = event =&gt; {
      this.setState({
        user: {
          ...this.state.user,
          [event.target.name]: event.target.value
        }
      });
    };
    onLoginClick = () =&gt; {
      const { loggedIn } = this.state;
      console.log(loggedIn, 'this.state')
      if (loggedIn) {
        this.props.onLoggedInSuccess(true);
      }
    };
    onLogin = event =&gt; {
      event.preventDefault();
      fetch("http://localhost:3000/login", {
        method: "post",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(this.state.user)
      })
        .then(res =&gt; res.json())
        .then(data =&gt; {
          if (data.loggedIn) {
            this.setState({ loggedIn: true });
            this.onLoginClick();
          }
        });
    };
  
    render() {
      return (
        &lt;div className="login-page"&gt;
          &lt;div className="form"&gt;
            &lt;form className="login-form" onSubmit={this.onLogin}&gt;
              &lt;input
                type="text"
                placeholder="username"
                name="username"
                value={this.state.user.username}
                onChange={this.handleChange}
              /&gt;
              &lt;input
                type="password"
                placeholder="password"
                name="password"
                value={this.state.user.password}
                onChange={this.handleChange}
              /&gt;
              &lt;button className="bluecolor" type="submit"&gt;
                Login
              &lt;/button&gt;
              &lt;p className="message"&gt;
                Have an account? &lt;a href="/login"&gt;Login&lt;/a&gt;
              &lt;/p&gt;
            &lt;/form&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default connect(mapStateToProps,
      mapDispatchToProps)(Login);</code></pre>
  </div>
  </div>
  </p>
  
  <p>App.js</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React, { Component } from 'react';
  import RegisterFull from "./Components/Register/RegisterFull";
  import LoginFull from "./Components/Login/LoginFull";
  import HomeFull from "./Components/Home/HomeFull";
  import FullContact from "./Components/Contact/FullContact";
  import './App.css';
  import './Components/flex.css'
  import {BrowserRouter as Router, Route, Switch} from "react-router-dom";
  class App extends Component {
    constructor(props) {
      super(props);
      this.state = {
        signedIn: false
      };
    }
    loginUser = () =&gt; {
      this.setState({ signedIn: true });
    };
  
    render() {
      console.log(this)
      return (
        &lt;Router&gt;
          &lt;Switch&gt;
            &lt;Route exact path="/" component={HomeFull} /&gt;
            &lt;Route exact path="/contact" component={FullContact} /&gt;
            &lt;Route exact path="/login" component={LoginFull} /&gt;
            &lt;Route exact path="/register" component={RegisterFull} /&gt;
            &lt;Route exact path="/about" component={HomeFull} /&gt;
          &lt;/Switch&gt;
        &lt;/Router&gt;
      );
    }
  }
  
  export default App;</code></pre>
  </div>
  </div>
  </p>