Answers for "how to get the previous url in react js"

1

react router last page

import { useHistory } from "react-router-dom";

function demo () {
    let history = useHistory();
    const goToPreviousPath = () => {
        history.goBack()
    }
    return (
      <div>
        <Button
          onClick={goToPreviousPath}
        >
          Back
        </Button>
      </div>
    ):
}
Posted by: Guest on September-08-2020
-1

react history listen get previous location

let prevLocation;

history.listen(nextLocation => {
  console.log(prevLocation);
  // ...
  prevLocation = nextLocation;
});
Posted by: Guest on January-20-2021

Code answers related to "how to get the previous url in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language