React Js Disable Browser Back button




Note: this is the problem  i have faced in React js project if you ahve the same issue u can see this
You can place below lines of code in html file. That's it no need to change any code in other files.


  <script type="text/javascript" >
          history.pushState(null, document.title, location.href);
          window.addEventListener('popstate', function (event)
          {
            history.pushState(null, document.title, location.href);
          });
  </script>


 If you want to see whole html file  then you can check below code .
 Here  is root file in which under <head> tag we have our code.
 you can see the code enclosed in <Script> tag
<!doctype html>
<html lang="en">
  <head>
  <title></title>

      <script type="text/javascript" >
          history.pushState(null, document.title, location.href);
          window.addEventListener('popstate', function (event)
          {
            history.pushState(null, document.title, location.href);
          });
      </script>

  </head>

  <body class="app header-fixed sidebar-fixed aside-menu-fixed aside-menu-hidden">
    <div id="root"></div>

  </body>
</html>


Thanks for viewing this article. Please check our other articles also

Comments