Automatic redirect after login with react-router

后端 未结 7 2525
广开言路
广开言路 2020-12-01 07:17

I wanted to build a Facebook login into my react/react-router/flux application. I have a listener registered on the login event and would like to redirect t

7条回答
  •  青春惊慌失措
    2020-12-01 07:43

    React Router v4.2.0

    I am using React-16.2.0 & React-router-4.2.0

    And I get solution by this code this.props.history.push("/");

    My working code:

    .then(response => response.json())
    .then(data => {
        if(data.status == 200){
            this.props.history.push("/");
            console.log('Successfully Login');
      }
    })
    

    I was following this document redirect-on-login-and-logout

    I was also try by return But unlucky, this not working for me.

提交回复
热议问题