react登录成功后页面跳转

可直接在验证成功后,用his.props.history.push("/")写上想要跳转的路由

getConnect() {
        let text = {user: this.state.user, password: this.state.password};//获取数据
        // console.log(text);
        let send = JSON.stringify(text);//将对象转成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("验证失败,用户名或密码错误")
            }
        )
    }

你可能感兴趣的:(react登录成功后页面跳转)