title: React-router v6 private route not working well
body: <p>I want to implement private and public routes with react-router V6, I have tried all the available solutions on StackOverflow, it does not seem to work. That's why I needed clarifications.</p>
  <pre><code>// App.tsx 
  &lt;Suspense
            fallback={
              &lt;Flex height={&quot;90vh&quot;} justifyContent=&quot;center&quot; alignItems={&quot;center&quot;}&gt;
                &lt;Spinner colorScheme={&quot;primary.400&quot;} /&gt;
              &lt;/Flex&gt;
            }
          &gt;
            &lt;Routes&gt;
              &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;
              &lt;Route
                path=&quot;/dashboard&quot;
                element={
                  &lt;PrivateRoute&gt;
                    &lt;Dashboard /&gt;
                  &lt;/PrivateRoute&gt;
                }
              /&gt;
              &lt;Route
                path=&quot;/product/:id&quot;
                element={
                  &lt;PrivateRoute&gt;
                    &lt;ProductDetails /&gt;
                  &lt;/PrivateRoute&gt;
                }
              /&gt;
              &lt;Route path=&quot;/login&quot; element={&lt;Login /&gt;} /&gt;
              &lt;Route
                path=&quot;/upload&quot;
                element={
                  &lt;PrivateRoute&gt;
                    &lt;Upload /&gt;
                  &lt;/PrivateRoute&gt;
                }
              /&gt;
            &lt;/Routes&gt;
          &lt;/Suspense&gt;
  
  
  // PrivateRoute.tsx
      export const PrivateRoute = ({ children }: any) =&gt; {
        const user = localStorage.getItem(&quot;user&quot;);
      
        if (user) {
          console.log(&quot;Yes, user exist&quot;);
        } else {
          console.log(&quot;No user&quot;);
        }
      
        if (!user) {
          return &lt;Navigate to=&quot;/login&quot; /&gt;;
        }
      
        return children;
      };
  </code></pre>
  <p>When I'm logged in, I can still navigate manually to the login page, and it renders, instead of pushing me to the dashboard page. Why??</p>