You can use the useNavigate hook from React Router. By calling navigate(-1), you can achieve a behavior similar to clicking the browser's back button. This allows you to go back to the previous page in the history stack.
For example:
import React from 'react';
import { useNavigate } from 'react-router-dom';
const MyComp = () => {
  const navigate = useNavigate();
  const goBack = () => {
    navigate(-1);  // This takes the user back to the previous page
  };
  return <button onClick={goBack}>Go Back</button>;
};
export default MyComp;