简体   繁体   English

如何在与 react-redux 的反应中使用导航

[英]how to use navigate in react with react-redux

I am making a login foam on react using react-redux, kindly suggest to me how I will use navigate here我正在使用 react-redux 制作登录泡沫,请向我建议我将如何使用导航

const { isAuthenticated, error, loading} = useSelector(state =>state.auth);
  useEffect(()=>{
    if(isAuthenticated){
      navigate("/dashboard");
    }
    if(error){
      // alert.error(error);
      dispatch(clearErrors());
    }
  },
  // [dispatch,alert,isAuthenticated,error,navigate]
  [dispatch,isAuthenticated,error,navigate]
  )

在此处输入图像描述

Did you import useNavigate at the top of the file like this?您是否像这样在文件顶部导入了useNavigate

import { useNavigate } from "react-router-dom";

Then, to use it, assign it to a variable:然后,要使用它,请将其分配给一个变量:

let navigate = useNavigate();

then use it like you have in the code: navigate("/dashboard");然后像在代码中一样使用它: navigate("/dashboard");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM