Answer the question
In order to leave comments, you need to log in
How to follow a link inside an event handler in react?
So far, only this code works:
But the page reloads with this approach. How can I follow a link without reloading, and preferably using react-router? document.location.href = "/cources";
Answer the question
In order to leave comments, you need to log in
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class Example extends Component {
handler = () => {
this.props.history.push('/cources');
};
render() { /* ... */ }
}
export default withRouter(Example);
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Example extends Component {
render() {
return <Link to="/cources" />;
}
}
export default Example;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question