title: Why am I outside the <Router> after rendering inside it?
body: <p>Im building a Reactjs App. I don't understand why doing this is wrong and lead me to this error :</p>
  <blockquote>
  <p><code>Error: Invariant failed: You should not use &lt;Redirect&gt; outside a &lt;Router&gt;</code></p>
  </blockquote>
  <p>Here is the code :</p>
  <p>A simple router in index.js</p>
  <pre><code>ReactDOM.render(
      &lt;Router&gt;
          &lt;Switch&gt;
              &lt;Route exact path=&quot;/&quot; component={(props) =&gt; &lt;AppContainer&gt;&lt;HomePage {...props}/&gt;&lt;/AppContainer&gt;}/&gt;
              &lt;Route exact path=&quot;/register&quot; component={(props) =&gt; &lt;AppContainer&gt;&lt;RegisterPage1 {...props}/&gt;&lt;/AppContainer&gt;}/&gt;
          &lt;/Switch&gt;
      &lt;/Router&gt;, document.getElementById('root')
  );
  </code></pre>
  <p>The AppContainer is just a simple div with id :</p>
  <pre><code>export default function AppContainer({children}) {
      return (
          &lt;div id=&quot;appContainer&quot;&gt;{children}&lt;/div&gt;
      );
  }
  </code></pre>
  <p>Inside RegisterPage1, I trigger a Render on &quot;appContainer&quot; after some process. This should render a new component inside the router.</p>
  <pre><code>ReactDOM.render(&lt;RegisterPage2 data={res}/&gt;, document.getElementById('appContainer'));
  </code></pre>
  <p>Inside RegisterPage2, I'm using  and I get the above error.</p>
  <pre><code>
  if (redirectHome) return (&lt;Redirect to={&quot;/&quot;}/&gt;)
  else {
      return (
  //RegisterPage2Components
      )
  }
  </code></pre>
  <p>Since I'm rendering inside the Router, I dont understand why I can use Redirect in RegisterPage1 and cannot in RegisterPage2. I checked in RegisterPage2 and the router is still here (by adding some random text between the Router and the Switch).
  If rendering like this is wrong, what is the correct way without adding a new route ?</p>
  <p>Codesandbox :
  <a href="https://codesandbox.io/s/autumn-leftpad-7s5sy?file=/src/index.js" rel="nofollow noreferrer">https://codesandbox.io/s/autumn-leftpad-7s5sy?file=/src/index.js</a></p>