Sometimes, we want to reload a page with React Router.
In this article, we’ll look at how to reload a page with React Router.
How to reload a page with React Router?
To reload a page with React Router, we can call the history.go
method with 0.
For instance, we write
import { useHistory } from "react-router";
const Comp = () => {
const history = useHistory();
const reload = () => {
history.go(0);
};
//...
};
to call the useHistory
hook in the Comp
component.
And then in the reload
function, we call history.go
with 0 to reload the page.
Conclusion
To reload a page with React Router, we can call the history.go
method with 0.