Programmatically navigate using react router

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

    In React-Router v4 and ES6

    You can use withRouter and this.props.history.push.

    import {withRouter} from 'react-router-dom';
    
    class Home extends Component {
    
        componentDidMount() {
            this.props.history.push('/redirect-to');
        }
    }
    
    export default withRouter(Home);
    

提交回复
热议问题