Answers for "how to go back previous url from history in reactjs"

2

how to redirect back to previous page onClick react router

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

function app() {
  let history = useHistory();

  const redirect = () => {
    history.push('/your-path')
  }

  return (
    <div>
      <button onClick={redirect}>Redirect</button>
    </div>
  )
}
Posted by: Guest on February-08-2021
-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 go back previous url from history in reactjs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language