Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 新组件的布线和使用道具_Javascript_Reactjs_React Router - Fatal编程技术网

Javascript 新组件的布线和使用道具

Javascript 新组件的布线和使用道具,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我有一个组件,它调用一个API,如果API返回某个结果,它应该引用/welcome页面(它是welcome.js)。为此,我想通过电子邮件。是否有一个选项,我可以重定向到其他组件,同时传递道具电子邮件 const handleLogin = () => { axios.post('localhost:3000:/login', {"email":email, "password":password}) .then(

我有一个组件,它调用一个API,如果API返回某个结果,它应该引用/welcome页面(它是welcome.js)。为此,我想通过电子邮件。是否有一个选项,我可以重定向到其他组件,同时传递道具电子邮件

const handleLogin = () => {
        axios.post('localhost:3000:/login', {"email":email, "password":password})
          .then(res => {
            console.log(res);
            console.log(res.data);
            console.log(res.status);
            if(res.status === 200) {
              setValidationWrong(true);
             // Forward to another component and pass on the email
             // <Link to="/welcome"> </Link> 
              
              
            }
          })
          .catch(error => {
            console.log(error)
            setValidationWrong(false);
        })
      };
consthandlelogin=()=>{
post('localhost:3000:/login',{“email”:email,“password”:password})
。然后(res=>{
控制台日志(res);
console.log(res.data);
控制台日志(res.status);
如果(资源状态===200){
SetValidationError(true);
//转发到另一个组件并传递电子邮件
//   
}
})
.catch(错误=>{
console.log(错误)
SetValidationError(假);
})
};
Welcome.js

import React from "react";
import Testchat from "../components/Testchat";

const Welcome = (props) => {

return (
    <div>
        <h1>Welcome{props.email}</h1>
        <Testchat></Testchat>
    </div>
);
}

export default Welcome 
从“React”导入React;
从“./components/Testchat”导入Testchat;
康斯特欢迎=(道具)=>{
返回(
欢迎{props.email}
);
}
导出默认欢迎

是的,有。使用历史API时,可以发送位置而不是字符串

e、 g。

同样的情况也适用于链接组件:


在欢迎组件中,您可以通过
props.location.state.email
访问它

const location = {
  pathname: '/welcome',
  state: { email: foo@baz.com }
};

history.push(location);
<Link
  to={{
    pathname: "/welcome",
    state: { email: foo@baz.com }
  }}
/>