Reputation: 89
<Button
variant="outlined"
color="primary"
//disabled={isDisabledSpec}
onClick={this.handleSubmit}
//onClick={this.handleSubmit.bind(this)}
>
This is the button tag, where handleSubmit being called.
handleSubmit(e) {
e.preventDefault();
//const history = useHistory();
this.props.history.push("/slider");
....}
This is handleSubmit function
Upvotes: 1
Views: 303
Reputation: 91
You can follow the following steps to solve the problem
import { withRouter } from 'react-router-dom';
onClick={this.handleSubmit.bind(this)}
handleSubmit = (e) => {
e.preventDefault();
this.props.history.push("/slider");}
export default withRouter(component_name);
Upvotes: 2
Reputation: 9779
Did you wrap your component like this? if not wrap like this
import { withRouter } from 'react-router';
class Specification extends Component {(...)}
export default withRouter(Specification);
and if you don't bind your function then use the arrow function
handleSubmit = (e) => {
e.preventDefault();
this.props.history.push("/slider");
}
Upvotes: 2