wixlocation to not working

Hi there

I’ve got a wix project with several pages. I’d like to go from one page to another when the user clicks a button. It’s implemented in a function, which is connected to the click event on the button. Then I call wixLocation.to("/target-page") The function is called and the target-page exists; the naming is correct.
But somehow nothing happens. Just before the wixLocation-statement is called, there are several statements, which set items on the session. Could it be, that the session blocks the wixLocation-statement? Is there any advice how to solve this?
I know that there are already plenty of similar questions, but nothing helped.

Thanks for your help

It’s possible that the statements that set items on the session are causing an issue with the wixLocation.to() function. This could be due to a race condition, where the session data is not yet fully set when the wixLocation.to() function is called.

To resolve this, you can try using the async/await syntax to ensure that the session data is fully set before calling wixLocation.to(). Here’s an example:
async function goToPage() {
// set session data
await wixUsers.promptLogin(); // example statement that sets session data
// navigate to target page
wixLocation.to(“/target-page”);
}
By using the async/await syntax, the function will wait for the promptLogin() statement (or other session-setting statements) to finish before moving on to the wixLocation.to() statement.

If this doesn’t resolve the issue, you can try simplifying the code and removing any unnecessary statements that may be interfering with the wixLocation.to() function .

it will help a lot if you can update the post with your code, that way we might be able to see a syntax error or confirm you need to use Async/await as already suggested.

Hi

Thanks for your help. The async/wait keyword does the trick.