# wixLocation.to() is not functioning

**URL:** <https://forum.wixstudio.com/t/wixlocation-to-is-not-functioning/57247>\
**Category:** Ask the community\
**Tags:** wix-location-frontend, wix-editor, code, wix-stores, question\
**Created:** [March 15, 2024, 4:21pm UTC](https://forum.wixstudio.com/t/wixlocation-to-is-not-functioning/57247 "2024-03-15T16:21:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MyMicroZoo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mymicrozoo/32/89740_2.png) [@MyMicroZoo](https://forum.wixstudio.com/u/MyMicroZoo)\
**Post date:** [March 15, 2024, 4:21pm UTC](https://forum.wixstudio.com/t/wixlocation-to-is-not-functioning/57247/1 "2024-03-15T16:21:57Z")

</div>

## **Question:** How do I get Wixlocation.to() to work? I cannot get wixLocation() to work. I have been using the following code:

```javascript
import {Getlink} from 'backend/MyParcelFidlab';
import wixLocation from 'wix-location';

let url;

async function openlink() {
    try {
        //Store response of getlink in responseData
        const responseData = await Getlink();
        //storing the url from the response in the var url
        url = responseData?.data?.download_url?.link;
        //Check if URL is a string
        if (typeof url === 'string') {
            console.log('URL is a string');
        } else {
            console.log('URL is not a string');
        }
        //log in console. Extra check 
        console.log("URL",url);
        
        //open url in new window
        wixLocation.to(url); 
             
    } catch (error) {
        console.error("Error:",error);
    }
}

$w.onReady(function () {
    wixLocation.to("https://google.com");
    openlink().then(() => {
        wixLocation.to(url);
    }).catch(error => {
        console.error("Error:", error);
    });
});

```

**Product:**  
WixWebsiteEditor

**What are you trying to achieve:**  
The backend functions works and the returned url is a string (the url is variable, hence the backend function).  
However, the wixLocation.to never functions. Also not if I place it in the onReady function. how can I troubleshoot this?  
Ideally I want people coming to the site to be redirected as soon as possible. Optionally I can add a button on which they are redirected to the var url

**What have you already tried:**  
I tried all variations I could think of with a verified url. I tried googling and looking at alternatives.

I am a newby, so all help is much appreciated!

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [March 15, 2024, 4:39pm UTC](https://forum.wixstudio.com/t/wixlocation-to-is-not-functioning/57247/2 "2024-03-15T16:39:16Z")

</div>

> [@MyMicroZoo](#):
>
> `wixLocation.to("https://google.com");`

Are you trying to trigger the backend code to retrieve the URL and then immediately redirect to that URL?

Or is the redirect supposed to be triggered by a specific action?

Why do you have this Google line here?

---

<div class="post-metadata">

**Author:** ![MyMicroZoo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mymicrozoo/32/89740_2.png) [@MyMicroZoo](https://forum.wixstudio.com/u/MyMicroZoo)\
**Post date:** [March 18, 2024, 7:43am UTC](https://forum.wixstudio.com/t/wixlocation-to-is-not-functioning/57247/3 "2024-03-18T07:43:00Z")

</div>

Hi code queen,

Thank you for responding. I do indeed want to retrieve a URL from the backend code that opens immediately (preferred) or on the click of a button (if direct opening is impossible). The retrieved file is a JSON with three levels (responseData?.data?.download\_url?.link;).  
I was using Google to try the code without the retrieved URL to troubleshoot with a URL that is 100% correct.
