可直接在驗(yàn)證成功后代承,用his.props.history.push("/")寫(xiě)上想要跳轉(zhuǎn)的路由
getConnect() {
let text = {user: this.state.user, password: this.state.password};//獲取數(shù)據(jù)
// console.log(text);
let send = JSON.stringify(text);//將對(duì)象轉(zhuǎn)成json字符串
fetch("http://localhost:8080/login", {
method: "POST",
headers: {"Content-Type": "application/json;charset=utf-8"},
body: send
}).then(res => res.json()).then(
data => {
if (data.success){
this.props.history.push("/")
}else window.alert("驗(yàn)證失敗窗市,用戶(hù)名或密碼錯(cuò)誤")
}
)
}