title: Redirecting to an external link using React
body: <p>I've found <a href="https://stackoverflow.com/a/44563899/5049813">this solution</a> for redirecting to an external link, and it has worked for one of my pages.</p>
  
  <p>But for a different page it is no longer working, and I'm not sure why.</p>
  
  <p><code>redirect.jsx</code>:</p>
  
  <pre><code>import React from "react";
  import { BrowserRouter, Route } from 'react-router-dom'
  
  export default class Redirect extends React.Component {
      render() {
          return (
              &lt;Route path='/hello' component={() =&gt; {
              window.location.href = "example.com";
              return null;}}/&gt;
          );
      }
  }
  </code></pre>
  
  <p><code>test.jsx</code>:</p>
  
  <pre><code>import React from "react";
  import ReactDOM from "react-dom";
  import {BrowserRouter} from 'react-router-dom'
  import MainExport from './components/redirect.jsx';
  
  ReactDOM.render(
      &lt;BrowserRouter&gt;
          &lt;div&gt;
              &lt;MainExport /&gt;
          &lt;/div&gt;
      &lt;/BrowserRouter&gt;, document.getElementById("content")
  );
  </code></pre>
  
  <p><code>test.html</code>:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div className="App"&gt;
          &lt;div id="content" /&gt;
      &lt;div/&gt;
      &lt;script src="dist/bundle/test.bundle.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I load this page, I expect it to redirect to the URL "/hello" and display the page from "example.com".</p>
  
  <p>Instead, it does nothing.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT: Some of the answers have been helpful, but none of them have worked yet.</p>
  
  <p>I've found that using the <code>Redirect</code> component renders and does the redirect, but does it in some way such that my Flask server doesn't actually serve the file. All I see is a blank screen.</p>
  
  <p>Changing the name to <code>MyRedirect</code> also did not make it work.</p>
  
  <p>Using <code>render</code> instead of <code>component</code> also did not seem to have an impact.</p>
  
  <p><strong>The redirect is still not taking place.</strong></p>
  
  <p>(I'm also still not seeing any error messages in the JS console or on the server side.)</p>