Programmatically navigate using react router

后端 未结 30 3160
無奈伤痛
無奈伤痛 2020-11-21 05:18

With react-router I can use the Link element to create links which are natively handled by react router.

I see internally it calls t

30条回答
  •  清歌不尽
    2020-11-21 05:22

    Update : React Router v6 with hooks

    import {useNavigate} from 'react-router-dom';
    let navigate = useNavigate();
    navigate('home');
    

    And to move across the browser history,

    navigate(-1); ---> Go back
    navigate(1);  ---> Go forward
    navigate(-2); ---> Move two steps backward.
    

提交回复
热议问题