Programmatically navigate using react router

后端 未结 30 2315
無奈伤痛
無奈伤痛 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:49

    You can also use the useHistory hook in a stateless component. Example from the docs.

    import { useHistory } from "react-router"
    
    function HomeButton() {
      const history = useHistory()
    
      return (
        
      )
    }
    

    Note: Hooks were added in react-router@5.1.0 and require react@>=16.8

提交回复
热议问题