Redirect using navigate() to the same URL updating the state in react

‘/’URL Login handler function

const loginHandler = (e) => {
        e.preventDefault();
        Services.login(email, password)
          .then((Res) => {
            if(Res.data==="success"){
              navigate('/home')
            }
            else {
              navigate('/',{
                state: {
                  msg: Res.data,
                }})
            }
          })
          .catch((error) => {
            console.log(error);
          });
      };

On Res.data other than success I want to redirect to the same /Url by updating the state of a component so that I can display proper error message on the same page and prevent user to navigate to /home Url . How can I do that?