React logs in with fetch, how to jump to the component after success

1. After the login is successful, the data returned by the backend is sent to the data of fetch, and then how to use routing to jump to other components
2. If routing is not needed, can I use window.location.href to jump to the component
handleSubmit = (e) = > {

    e.preventDefault();
    // let history = this.context.router.history;
    this.props.form.validateFields((err, values) => {
        if (!err) {
            fetch("/api/login",{
                method:"POST",
                headers: {
                    "Accept": "application/json",
                    "Content-Type":"application/json;charset=UTF-8"
                },
                body:JSON.stringify({"email":values.email,"password":values.password}),
            }).then(function (res) {
                return res.json();
            }).then(function(data){
                console.log(data)
                // window.location.href="/usercenter";
             
                }
            ).catch(function (err) {
                console.log(err);
            })
        }
    });
}
Mar.02,2021

if you don't use routing, you can bring in the component to be redirected, and then replace the current component with
after the fetch is successful, put the data into state, and then under render, if determines that different components are displayed according to the data


    import { withRouter } from 'react-router-dom';  // react-routerreact-router4withRouterhistoryhistory
    this.props.history.push('/usercenter');
.
Menu