title: window.location.pathname not working as expected in react
body: <p>I have this code where I want to hide the header from specific components like the login and register one. I've done this by using the window.location.pathname. It works for the login component but for the register one it doesn't work because the header is shown.</p>
  <pre><code>import './App.css';
  import './index.css'
  import App from './App'
  import Main from './main.js'
  import {
    BrowserRouter as Router,
    Switch,
    Route,
    Link
  } from &quot;react-router-dom&quot;;
  import Dashboard from './dashboard.js'
  import Clients from './Clients.js'
  import AddClient from './clientform.js'
  import EditClient from './editclient.js'
  import Landing from './landing.js'
  import AddDiet from './addDiet.js'
  import CalendarSection from './calendar.js'
  import Login from './login.js'
  import { useAuth0 } from &quot;@auth0/auth0-react&quot;;
  import Register from './register.js'
  
  
  
  export default function MainApp() {
  
    let HideHeader = window.location.pathname === '/login' &amp;&amp; '/register' ? null : &lt;Main /&gt;
  
    return (
          &lt;Router&gt;
            {HideHeader}
        &lt;Switch&gt;
        &lt;Route path=&quot;/login&quot;&gt;
            &lt;Login /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/register&quot;&gt;
            &lt;Register /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/dashboard&quot;&gt;
          &lt;Dashboard /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/Clients&quot;&gt;
          &lt;Clients /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/addClient&quot;&gt;
            &lt;AddClient /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/Calendar&quot;&gt;
            &lt;CalendarSection /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/Clients/:id&quot;&gt;
            &lt;EditClient /&gt;
          &lt;/Route&gt;
          &lt;Route exact path=&quot;/Clients/:id/addDiet&quot;&gt;
            &lt;AddDiet /&gt;
          &lt;/Route&gt;
        &lt;/Switch&gt;    
        &lt;/Router&gt;
    )
    }
  </code></pre>