1.登录成功后,后台返回的数据到fetch的data里,然后怎么用路由跳转到其他组件呢
2.如果不用路由,可以用window.location.href来跳转到组件吗
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);
})
}
});
}
如果不使用路由,你可以把要跳转的组件引入进来,然后把当前的组件替换掉
fetch成功之后那数据放到state里面,然后在render下面if判断一下根据数据来显示不同的组件