score:1

Accepted answer

Use react-router-dom

You can use react-router-dom (npm package)

In React Class you can use this: this.props.history.push('/login')

And in React Hooks you can use useHistory from react-router-dom:

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

export default function SomeFunction() {

  const history = useHistory();

  const trigerFunction = () => history.push('/login');

  return (
     <div onClick={trigerFunction}></div>
  )
}

BTW

window.location.reload(); it's only refresh the page.

You can save in local storage some that after refresh you know what page to render (but I don't recomend this, and the refresh is unnecessary)

score:0

You can change:

window.location.reload();

this.props.history.push("desired Address");


Related Query

More Query from same tag