title: React context being lost after redirect
body: <p>Creating context</p>
  
  <pre><code>export default React.createContext({
  user:null,
  login:()=&gt;{}
  })
  </code></pre>
  
  <p>Context controller </p>
  
  <pre><code>export default class ContextHandler extends Component{
  state = {
      user: null,
  }
  logout = () =&gt; {
      this.setState({
          user: null
      })
  }
  
  login = user =&gt; {
      this.setState({
          user: user
      })
  };
  
  render(){
      return(
          &lt;AuthContext.Provider value={{ user: this.state, login: this.login, logout: this.logout }} &gt;
              {this.props.children}
          &lt;/AuthContext.Provider&gt;
      )
  }
  }
  </code></pre>
  
  <p>App.js</p>
  
  <pre><code>class App extends Component{
  render() {
      return (
              &lt;BrowserRouter&gt;
                  &lt;div&gt;
                      &lt;Switch&gt;
                          &lt;Route path="/" exact component={Header} /&gt;
                          &lt;Route path="/login" exact component={Login} /&gt;
                          &lt;Route path="/profile" exact component={UserProfile} /&gt;
                          &lt;Route path="/inputform" exact component={InputForm} /&gt;
                      &lt;/Switch&gt;
                  &lt;/div&gt;
              &lt;/BrowserRouter&gt;
      )
  }
  }
  
  export default App;
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>ReactDOM.render((
  &lt;ContextHandler&gt;
      &lt;App/&gt;
  &lt;/ContextHandler&gt;
  ),
  document.getElementById('root'));
  registerServiceWorker();
  </code></pre>
  
  <p>User Profile Page </p>
  
  <pre><code>componentDidMount() {
      if (!this.context.user) {
          return ( &lt;Redirect to = "/login"/&gt; )
      }
  
      else{
          this.setState({
              loading:true
          })
          getUserEntries(this.context.user.token,(entries)=&gt;{
              if(entries !== null){
                  this.setState({
                      userEntries:entries
                  })
              }
          })
      }
  }
  
     render() {
      let samples, producers
      if(!this.context.user){
          return(
              &lt;Redirect to="/login"/&gt;
          )
      }
  
      if (this.state.userEntries) {
          samples = (this.buildList(this.state.userEntries.samples))
          producers = (this.buildList(this.state.userEntries.producers))
      }
  </code></pre>
  
  <p>Once I log in I'm directed to the user page with the correct context. Once I navigate to another page and try go back to the user profile page the context is lost. and i have to login again??</p>
  
  <p>The only two components consuming the context are the nav bar and the user profile page.
  Note: I am using the new 16.6 context API i.e no consumer tags in render.</p>