react button onClick redirect page

前端 未结 13 2273
我在风中等你
我在风中等你 2020-12-02 15:19

I am working on web application using React and bootstrap. When it comes to applying button onClick, it takes me hard time to let my page being redirect to another. if afte

13条回答
  •  我在风中等你
    2020-12-02 15:54

    if you want to redirect to a route on a Click event.

    Just do this

    In Functional Component

    props.history.push('/link')
    

    In Class Component

    this.props.history.push('/link')
    
    

    Example:

    
    

    Tested on:

    react-router-dom: 5.2.0,

    react: 16.12.0

提交回复
热议问题