title: Prevent going to the previous page on browser back button
body: <p>I have a Next.js / React.js project I'm working on and I'm trying to redirect to a certain page when browser's back button is clicked. My approach is as follows</p>
  <pre><code>useEffect(() =&gt; {
      Router?.beforePopState(({ as }) =&gt; {
          if (as !== router.asPath) {
              handleRouteChange({ toHref: getRoutingPath('HOME') }, Router.push);
          }
          return true;
      });
          
      return () =&gt; {
          Router?.beforePopState(() =&gt; true);
      };
  }, [dispatch, router]);
  </code></pre>
  <p>And this code works. When I click the back button, it takes me to the home page as intended.</p>
  <p>But the issue is, when I click on the back button, it takes me to the previous page for a second and then redirects to the home page. How can I prevent going to the previous page at all?</p>