1

i am making a validation form , with a function that checks for password and email , if true it should navigate to a separate website (not to a path within the web). But it is not working

This is my code below:

function validate() {
    if (email==='[email protected]' && password==="123456"){
        console.log(email);
 history('http://www.dummy.com/webmail')
}
}

return{
.
.
.
<Button className={stylesAuth.submitButton} variant="warning" onClick={validate}>
}

How should I do so?

1 Answer 1

1

Since you're redirecting to an external website, you can simply use plain old JavaScript and do a:

window.location.href = "https://www.dummy.com/webmail";

For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Location/href.

A little bit more information: using history doesn't make sense in this case, it is only meant for internal navigation within your web application. In fact, you cannot even push an external URL onto the history stack:

The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception. https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

Sign up to request clarification or add additional context in comments.

1 Comment

Yes got it! it worked thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.