Hi there,
So I’m trying yo use wixLocation.to() to redirect(from front end) based on a value received by wixFetch from API. The fetch is working well, I receive the json data and process it, but wixLocation.to() just doesn’t redirect me to the location.
Anyone have an idea why?
the code:
import wixLocation from 'wix-location';
import {fetch} from 'wix-fetch';
$w.onReady(function () {
let redirect = false;
// Fetch the user's location details
fetch('https://xxx.com/json', {
method: 'get'
})
// Check if the request was successful
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
})
.then((json) => {
const loc = json.countryCode;
console.log(loc); // Logs IL
if(loc === "IL"){
return wixLocation.to("/404-Error-Page");
}
})
.catch(e => console.log(e));
})
The If statement conditions are met. As you can see, I mentioned the the console logs IL for loc variable.
And yes, I’m trying to navigate the user to the 404 error page. I can mention that I tried other pages instead, also tried mailto:, but it still didn’t work.
I tried now the code on another wix site I own, and it behaves the same: If conditions met, but no redirect with wixLocation