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!