title: How to intercept back button in a React SPA using function components and React Router v5
body: <p>I'm working in a SPA in React that doesn't use React Router to create any Routes; I don't need to allow users to navigate to specific pages. (Think multi-page questionnaire, to be filled in sequentially.)</p>
  
  <p>But, when users press the back button <strong>on the browser</strong>, I don't want them to exit the whole app; I want to be able to fire a function when the user presses the back button that simply renders the page as it was before their last selection. (Each page is a component, and they're assembled in an array, tracked by a <code>currentPage</code> state variable (from a state hook), so I can simply render the <code>pages[currentPage -1]</code>. </p>
  
  <p>Using (if necessary) the current version of React Router (v5), function components, and Typescript, how can I access the back-button event to both disable it and replace it with my own function? </p>
  
  <p>(Other answers I've found either use class components, functions specific to old versions of React Router, or specific frameworks, like Next.js.)</p>
  
  <p>Any and all insight is appreciated. </p>