wixLocation.to() is not functioning

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

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!

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?

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.