【问题标题】:× TypeError: Cannot read property 'history' of undefined× TypeError:无法读取未定义的属性“历史”
【发布时间】:2021-07-18 11:08:28
【问题描述】:

已登录用户,但重定向不起作用。如何解决这些问题?这里是

登录组件代码:

const Login = ({ props }) => {
    const [email, setEmail] = useState();
    const [password, setPassword] = useState();

    const alert = useAlert();
    const dispatch = useDispatch();

    const { isAuthenticated, error, loading } = useSelector(
      (state) => state.auth
    );

    useEffect(() => {
      if (isAuthenticated) {
        props.history.push("/");
      }

      if (error) {
        alert.error(error);
        dispatch(clearErrors());
      }
    }, [dispatch, alert, error, loading, props, isAuthenticated]);

    const submitHandler = (e) => {
      e.preventDefault();
      dispatch(login(email, password));
    };  
    return ()
}

错误:

TypeError: Cannot read property 'history' of undefined

【问题讨论】:

  • ({ props }) => { ----> ( props ) => {

标签: reactjs


【解决方案1】:

你从道具中解构道具?也许你的意思是({ history, aProp, bProp })

【讨论】:

    猜你喜欢
    • 2018-02-04
    • 1970-01-01
    • 2019-05-04
    • 2019-07-25
    • 2017-09-24
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多