I have a route which redirects after checking a condition like this
(
Store.isFirstTime ?
You should render only Redirect in your render method:
render() {
return ( );
}
but here is my favorite solution without using the Redirect component
import { withRouter } from 'react-router-dom';export default withRouter(MyComponent);handlingButtonClickhandlingButtonClick = () => {
this.props.history.push("/") //doing redirect here.
}