我正在制作一個驗證表單,具有檢查密碼和電子郵件的功能,如果為真,它應該導航到一個單獨的網站(而不是網路中的路徑)。但它不起作用
這是我的代碼如下:
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}>
}
我該怎么做?
uj5u.com熱心網友回復:
由于您要重定向到外部網站,因此您可以簡單地使用普通的舊 JavaScript 并執行以下操作:
window.location.href = "https://www.dummy.com/webmail";
有關更多資訊,請參閱https://developer.mozilla.org/en-US/docs/Web/API/Location/href。
多一點資訊:history在這種情況下使用沒有意義,它僅用于 Web 應用程式中的內部導航。實際上,您甚至無法將外部 URL 推送到歷史堆疊中:
新 URL 必須與當前 URL 同源;否則,pushState() 將拋出例外。 https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/366610.html
