React Router v4 Redirect not working

前端 未结 6 1508
北恋
北恋 2020-12-13 04:17

I have a route which redirects after checking a condition like this

(
Store.isFirstTime ? 

        
6条回答
  •  天命终不由人
    2020-12-13 04:30

    You should render only Redirect in your render method:

    render() {
      return ();
    }
    

    but here is my favorite solution without using the Redirect component

    1. import import { withRouter } from 'react-router-dom';
    2. export default withRouter(MyComponent);
    3. Finally, in your action method, assume that handlingButtonClick
    handlingButtonClick = () => {
      this.props.history.push("/") //doing redirect here.
    }
    

提交回复
热议问题