1

I have implemented a signup view with backend validation, and I want to redirect to Login view after successfull signup. Here is my dispatching method:

    export const initSignup = (details) => {
    return (dispatch) => {
        axios.post("http://localhost:8080/auth/signup", {
            email: details.email,
            password: details.password
        }).then((result) => {
            console.log(result);
            return dispatch(_signup(result));
        })
         .catch((err) => {
                //use err.response to get our custom err response from backend
                //since once we send 400+ response status it goes to catch block
                console.log(err);
                dispatch(_signupError(err.response));
            })
    }
}

const _signup = (result) => {
    return {
        type: SIGNUP,
        result: result
    }
}

const _signupError = (err) => {
    return {
        type: ERROR,
        error: err
    }
}

After disptach _signup I want to redirect to "/login". Can someone help me here.

Ayush Rai
  • 9
  • 2
  • Does this resolve your doubt? https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage – mappie Aug 15 '20 at 11:39

1 Answers1

0

You need to use routes with paths and history prop

const { from } = { from: { pathname: "/myPath" } };
this.props.history.push(from);