wixlocation to not working

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 .