如果用户名和密码匹配,我想重定向到Dashboard.jsx.怎么做 ?我是ReactJS的新手.
在If条件中我想添加重定向代码以重定向另一个页面.请回应.在stackoverflow中,最大值是在没有条件的情况下使用,所以这里是差异.
var users={
name:'bddebashis',
password:'debashis111249'
}
class Home extends Component {
constructor() {
super();
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
fetch('/api/form-submit-url', {
method: 'POST',
body: data,
});
if(data.get('usr')==users.name && data.get('paswd')==users.password){
<Redirect to='./Dashboard';/>
}
}
Run Code Online (Sandbox Code Playgroud)