# wixlocation to not working

**URL:** <https://forum.wixstudio.com/t/wixlocation-to-not-working/3283>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 16, 2023, 1:02pm UTC](https://forum.wixstudio.com/t/wixlocation-to-not-working/3283 "2023-03-16T13:02:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![badesalzloesung](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@badesalzloesung](https://forum.wixstudio.com/u/badesalzloesung)\
**Post date:** [March 16, 2023, 1:02pm UTC](https://forum.wixstudio.com/t/wixlocation-to-not-working/3283/1 "2023-03-16T13:02:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![janettabloomquist](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@janettabloomquist](https://forum.wixstudio.com/u/janettabloomquist)\
**Post date:** [March 17, 2023, 8:29am UTC](https://forum.wixstudio.com/t/wixlocation-to-not-working/3283/2 "2023-03-17T08:29:32Z")

</div>

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 [.](https://www.myhealthonline.biz/)

---

<div class="post-metadata">

**Author:** ![clsnlsen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/clsnlsen/32/9802_2.png) [@clsnlsen](https://forum.wixstudio.com/u/clsnlsen)\
**Post date:** [March 17, 2023, 9:39am UTC](https://forum.wixstudio.com/t/wixlocation-to-not-working/3283/3 "2023-03-17T09:39:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![badesalzloesung](https://avatars.discourse-cdn.com/v4/letter/b/53a042/32.png) [@badesalzloesung](https://forum.wixstudio.com/u/badesalzloesung)\
**Post date:** [March 18, 2023, 10:14am UTC](https://forum.wixstudio.com/t/wixlocation-to-not-working/3283/4 "2023-03-18T10:14:58Z")

</div>

Hi

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