anonn023432 anonn023432 - 4 years ago 140
HTML Question

Pass react router path in onClick function

I have a React form which has the following form submission button:

<Link
className="btn btn-secondary btn-width-200 search-submit"
to={{pathname: '/booking/search', query: this.state.filters}}>
Search

</Link>


In the above
link
I want to call a function
handleSubmit(evt)
on button click.

handleSubmit(evt) {
evt.preventDefault();
this.setState({form_submitted: true});
}

<Link className="btn btn-secondary btn-width-200 search-submit" to={{pathname: '/booking/search', query: this.state.filters}} onClick={this.handleSubmit.bind(this)}>Search</Link>


But the following ignores the
to={{pathname: '/booking/search', query: this.state.filters}}
and just takes
handleSubmit
function into consideration

Is there anyway to add
to={{pathname: '/booking/search', query: this.state.filters}}
to the
handleSubmit
function? Or is there anyway to resolve this issue?

Answer Source

This

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download