【发布时间】:2018-10-24 01:23:51
【问题描述】:
如果用户名和密码匹配,我想重定向到 Dashboard.jsx。怎么做 ?我是 ReactJS 的新手。
在 If 条件中,我想添加重定向代码来重定向另一个页面。 请回复。在 stackoverflow 中,最大值是在没有 if 条件的情况下使用的,所以这就是区别。
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';/>
}
}
【问题讨论】:
-
remove the dot from redirect ,应该是
to='/Dashboard',你的问题已经在这里回答了:stackoverflow.com/questions/43230194/…
标签: javascript reactjs ecmascript-6 react-router