简体   繁体   中英

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.

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 . 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 . Update your URL from:

this.redirectUrl = 'home.html';

to this:

this.redirectUrl = '/home.html';

Or to this:

this.redirectUrl = `${location.hostname}/home.html`;

Hopefully this should help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM