how to access history object in new React Router v4

前端 未结 3 478
抹茶落季
抹茶落季 2020-12-29 09:07

I have tried all the suggested ways in other threads and it is still not working which is why I am posting the question.

So I have history.js looking li

3条回答
  •  粉色の甜心
    2020-12-29 09:47

    use the hook: useHistory

    import { useHistory } from "react-router-dom";
    
    function HomeButton() {
      let history = useHistory();
    
      function handleClick() {
        history.push("/home");
      }
    
      return (
        
      );
    }
    

提交回复
热议问题