I am trying to redirect to new page via onclick
function of a button, but its not redirecting.
Here is my code-
import React from 'react'; import { withRouter } from 'react-router-dom'; class Pricing extends React.Component { constructor(props){ super(props); document.title = "Pricing"; this.setPlanId = this.setPlanId.bind(this); } setPlanId(p_id){ localStorage.setItem('plan_id', p_id); //BrowserRouter.push('/do-payment'); this.props.history.push("/do-payment"); } render(){ return( <div> <div className="pricing bottommargin clearfix"> <Link to="#" className="btn btn-danger btn-block btn-lg bgcolor border-color" onClick={this.setPlanId(somevalue)}>Contunue</Link> </div> </div> ); } } export default Pricing;
Please let me know, what I am doing wrong.
onClick={this.setPlanId}
. Then are you sure you can useBrowserRouter
this way?import { withRouter} from 'react-router-dom';
andthis.props.history.push("/do-payment");
in respective function. .............but its redirecting automatically without on click event...