title: React Router v4 Redirect Passing State from Search to Results
body: <p>Have a Search component that when a payload comes back redirects to a Results component. Would like for that Results component to show the passed State of Search using <a href="https://reacttraining.com/react-router/web/api/Redirect" rel="noreferrer">React Router v4 Redirect</a>. My assumption here from the Docs is that using <code>state: { referrer: currentLocation }</code> an object can be passed. </p>
  
  <p><strong>Search</strong></p>
  
  <pre><code>export default class Search extends Component{
    constructor(props){
      super(props);
        this.state = {
          searchValue: '',
          results:[]
        }
      this.handleKeyPress = this.handleKeyPress.bind(this);
    }
  
    handleKeyPress = (e) =&gt; {
      let searchParam = e.target.value;
      if (e.key === 'Enter'){
        axios
          .get(URL+searchParam)
          .then((response) =&gt; {
            this.setState({results: response.data});
          });
      }
    };
  
    render(){
      return(
        &lt;div&gt;
          &lt;input
            ref="search"
            type="text"
            placeholder="Search"
            onKeyPress={this.handleKeyPress.bind(this)}
          /&gt;
          {this.state.results.length &gt; 0 &amp;&amp;
            &lt;Redirect to={{
              pathname: '/results',
              state: { results: this.state.results }
            }} /&gt;
          }
        &lt;/div&gt;
      );
    }
  }
  </code></pre>
  
  <p><strong>Results</strong></p>
  
  <pre><code>export default class Results extends Component{
    constructor(props){
      super(props);
      this.state = {
        results:[] // &lt;&lt;&lt;&lt;&lt;&lt; Not sure if this needs set
      }
    } 
    render(){
      console.log('SEARCH RESULTS STATE', this.state); // &lt;&lt;&lt;&lt; this either returns undefined or just an empty array depending if initial state is set
      return(
        &lt;div&gt;
          &lt;h1&gt;Search Results&lt;/h1&gt;
        &lt;/div&gt;
      );
    }
  }
  </code></pre>
  
  <p>Unless I'm not reading into this correctly, the problem seems to be that when the Redirect happens there isn't anything being passed into the Results component. </p>
  
  <p>If value is entered and is successful Redirect happens Search State returns <code>Object {searchValue: "", results: Array(1)}</code> However Search Results state returns <code>Object {results: Array(0)}</code> or <code>undefined</code> depending on initial state setting. </p>
  
  <p>Have also tried different component lifecycles on Results but unable to get any passed data that way. My thought there was maybe <code>componentWillRecieveProps(nextProps, nextState){}</code> might be able to get some passed data and could have state set via those means.  </p>