Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react history.push

//Whatever component that you use history in, HAS to be wrapped in <BrowserRouter>
 
//App.js
import {useHistory} from "react-router-dom";
 const history = useHistory();
 
function handleButtonClick() {
    history.push('/'); // redirect to main page
  }
 
//index.js
<BrowserRouter>
<App.js/>
</BrowserRouter>
 
PREVIOUS NEXT
Tagged: #react
ADD COMMENT
Topic
Name
4+2 =