title: React Router - useNavigation based upon last Page
body: <p>I am trying to do something very simple in a React app. I want a &quot;Back&quot; button to take the user to the previous page UNLESS the user has arrived from a specific page, and in that case &quot;Back&quot; will route them to a different page - something like:</p>
  <pre><code>  const navigate = useNavigate();
  
      if (lastPage === XYZ) {
          navigate('/home');
      } else {
          navigate(-1);
      }
  </code></pre>
  <p>My issue is that I can't work out how to get hold of the lastPage  in react-router-dom v6 (where useHistory has been depricated).
  Thanks!</p>