[英]Can't redirecting to another page using relative path
I want to use JS async function redirect to another page, but it don't work.我想使用 JS 异步 function 重定向到另一个页面,但它不起作用。
The following is my code:以下是我的代码:
var myAccount = document.getElementById("account1");
var myPwd = document.getElementById("pwd");
async function validate_form(){
this.redirectUrl = await eel.sign_in(myAccount.value, myPwd.value)();
console.log('rendering page...,redirectUrl:'+this.redirectUrl);
window.location.replace(this.redirectUrl);
}
I had try another way, but that was still fail我尝试了另一种方法,但仍然失败
async function validate_form(){
this.redirectUrl = await eel.sign_in(myAccount.value, myPwd.value)();
console.log('rendering page...,redirectUrl:'+this.redirectUrl);
try{
await Promise.all([window.location.replace(this.redirectUrl)]) ;
}
catch (error){
// Check for login session
const response = Object.assign({}, error);
if (response.response.status === 401 || response.response.status === 401) {
alert(response);
}
}
}
The command await eel.sign_in(myAccount.value, myPwd.value)()
would get value home.html
.命令
await eel.sign_in(myAccount.value, myPwd.value)()
将获得价值home.html
。 Could anyone knows how to solve this problem?谁能知道如何解决这个问题?
Thanks谢谢
As you are specifying a relative path, You need to add /
before the url you declared in this.redirectUrl
.当您指定相对路径时,您需要在 this.redirectUrl 中声明的
this.redirectUrl
之前添加/
。 Update your URL
from:从以下位置更新您的
URL
:
this.redirectUrl = 'home.html';
to this:对此:
this.redirectUrl = '/home.html';
Or to this:或对此:
this.redirectUrl = `${location.hostname}/home.html`;
Hopefully this should help you.希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.