title: Page NotFound on React 17 - Context API does not appear
body: <p>I know this question was asked before, but none of the solutions provided works for me and tried many else.</p>
  <p>My NotFound page does not appear on an inexistent route, or if a take it from switch it appears on every page. How can i fix this?</p>
  <p>This is a demo:
  <a href="https://stackblitz.com/edit/react-2dtprl?file=src%2FApp.js" rel="nofollow noreferrer">https://stackblitz.com/edit/react-2dtprl?file=src%2FApp.js</a></p>
  <p>Thank you in advance for any ideas.
  This is my code:</p>
  <pre><code>const App = () =&gt; {
  
      const [getSessionStorageValue] = useSessionStorage()
      const [isAuthenticated, setIsAuthenticated] = useState(Boolean(getSessionStorageValue(SESSION_ID)))
      const value = useMemo(() =&gt; ({ isAuthenticated, setIsAuthenticated }), [isAuthenticated, setIsAuthenticated]);
  
      const PrivateRoute = ({ children, ...rest }) =&gt; &lt;Route {...rest} render={() =&gt; isAuthenticated ? children : &lt;Redirect to={Urls.HOME} /&gt;} /&gt;
      const NotAuthRoute = ({ children, ...rest }) =&gt; &lt;Route {...rest} render={() =&gt; isAuthenticated ? &lt;Redirect to={Urls.HOME} /&gt; : children} /&gt;
  
      return (
          &lt;Router&gt;
              &lt;div className=&quot;main-container&quot;&gt;
                  &lt;div className=&quot;body&quot;&gt;
                      &lt;Switch&gt;
                          &lt;UserContext.Provider value={value}&gt;
  
                              &lt;ProductsContextProvider&gt;
                                  &lt;Header /&gt;
                                  &lt;Route exact path={Urls.HOME} component={Home}&gt;&lt;/Route&gt;
                                  &lt;PrivateRoute path=&quot;must-be-authenticated-1&quot;&gt;&lt;PrivateComponent1 /&gt;&lt;/PrivateRoute&gt;
                                  &lt;PrivateRoute path=&quot;must-be-authenticated-2&quot;&gt;&lt;PrivateComponent2 /&gt;&lt;/PrivateRoute&gt;
                              &lt;/ProductsContextProvider&gt;
  
                              &lt;PrivateRoute path=&quot;must-be-authenticated-3&quot;&gt;&lt;PrivateComponent3 /&gt;&lt;/PrivateRoute&gt;
  
                              &lt;NotAuthRoute path=&quot;must-not-be-authenticated&quot;&gt;&lt;NotAuthComponent1 /&gt;&lt;/NotAuthRoute&gt;
  
                              &lt;Route path=&quot;general-component&quot;&gt;&lt;FAQ /&gt;&lt;/Route&gt;
  
                          &lt;/UserContext.Provider&gt;
                          &lt;Route path=&quot;*&quot; component={NotFound}&gt;&lt;/Route&gt;
                      &lt;/Switch&gt;
                  &lt;/div&gt;
                  &lt;Footer /&gt;
              &lt;/div&gt;
          &lt;/Router&gt;
      );
  }
  </code></pre>