title: Next.js: How to clear browser history with Next Router?
body: <p>I created a wrapper for the pages which will bounce unauthenticated users to the login page.</p>
  <p>PrivateRoute Wrapper:</p>
  <pre><code>import { useRouter } from 'next/router'
  import { useUser } from '../../lib/hooks'
  import Login from '../../pages/login'
  
  const withAuth = Component =&gt; {
    const Auth = (props) =&gt; {
      const { user } = useUser();
      const router = useRouter();
  
      if (user === null &amp;&amp; typeof window !== 'undefined') {
        return (
          &lt;Login /&gt;
        );
      }
  
  
      return (
        &lt;Component {...props} /&gt;
      );
    };
  
    if (Component.getInitialProps) {
      Auth.getInitialProps = Component.getInitialProps;
    }
  
    return Auth;
  };
  
  export default withAuth;
  </code></pre>
  <p>That works \o/, However I noticed a behavior when I log out, using <code>Router.push('/',)</code>, to return the user to the homepage the back button contains the state of previous routes, I want the state to reset, as a user who is <strong>not</strong> authenticated should have an experience as if they're starting from scratch...</p>
  <p>Thank you in advance!</p>