使用mobx在Reactjs重定向后,组件不会重新渲染

时间:2019-04-13 16:20:27

标签: reactjs react-router mobx

我在reactJS上使用mobx存储创建了注册页面。
填写信息后提交时,
如果有错误,它将像history.push一样运行重定向。
因此,当我像首页网址一样使用history.push('/')时,
效果很好。
但是当我由于相同的电子邮件检查而要在同一网址上重新呈现时,
它发送到重定向的网址,如history.push('/ signup')。
与“ /”不同,它不会重新呈现。这样重复的前电子邮件就留在上面了。
由于我在componentwillUnmount上重置了电子邮件状态, 输入的电子邮件必须像按F5一样消失。
您能推荐一些解决方案吗?非常感谢!

 // In mobx store,

 @action submitSignUp = () => {
    const joinData = {
      userName: this.initialState.register.userName,
      email: this.initialState.register.email,
      password: this.initialState.register.password,
      passwordConfirm: this.initialState.register.passwordConfirm,
    };
    axios
      .post('user/join', joinData)
      .then((response) => {
          if (response.data === true) {
          history.push('/signup'); 
        }
      })
      .catch((error) => {
        console.log(error);
      });
  };

0 个答案:

没有答案