title: How do I redirect within an ErrorBoundary?
body: <p>I'm using ErrorBoundary in my React app and want to redirect to the main page when an error occurs - but my redirect is not working. Instead, the application stays on the same page.</p>
  <p>In comparison, adding a button allows the user to switch pages on clicking it.</p>
  <p>But I instead want to automatically take the user there when the error occurs.</p>
  <p>Surely there must be an easy way to do this that I'm missing.</p>
  <pre><code>import React from 'react';
  import { Redirect } from 'react-router-dom';
  
  class ErrorBoundary extends React.Component {
    constructor(props) {
      super(props);
      this.state = { error: null, errorInfo: null };
    }
  
    componentDidCatch(error, errorInfo) {
      this.setState({
        error: error,
        errorInfo: errorInfo
      })
      console.log(error, errorInfo);
    }
  
    render() {
      if (this.state.errorInfo) {
        return (
          &lt;div&gt;
            {/* &lt;Button href=&quot;/index.html&quot;&gt;Go Home&lt;/Button&gt; */}
            &lt;Redirect to=&quot;/index.html&quot; /&gt;
          &lt;/div&gt;
        );
      }
  
      return this.props.children; 
    }
  }
  
  export default ErrorBoundary;
  </code></pre>
  <p>I've also tried returning a Route with no luck:</p>
  <pre><code>render() {
    if (this.state.errorInfo) {
      return (
        &lt;Route path=&quot;/Home&quot; component={Home} /&gt;
      );
    }
  </code></pre>