react-router go back a page how do you configure history?

前端 未结 21 1258
说谎
说谎 2020-11-30 18:30

Can anyone please tell me how I can go back to the previous page rather than a specific route?

When using this code:

var BackButton = React.createCla         


        
21条回答
  •  再見小時候
    2020-11-30 19:06

    Go back to specific page:

      import { useHistory } from "react-router-dom";
    
      const history = useHistory();
      
      const routeChange = () => {
        let path = '/login';
        history.push(path);
      };
    

    Go back to previous page:

      import { useHistory } from "react-router-dom";
    
      const history = useHistory();
      
      const routeChange = () => {
        history.goBack()
      };
    

提交回复
热议问题