Trying to use wixLocation.to without success

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));
})

What is the response-result?

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) => {console.log(httpResponse.json())
           if (httpResponse.ok) {
               return httpResponse.json();
           }
     })
     .then((json) => {console.log(json)
           const loc = json.countryCode;
           console.log("LOC = " + loc)
           if(loc === "IL"){
           return wixLocation.to("/404-Error-Page"); //<--????
        }
     })
     .catch(e => console.log(e));
})

What’S that?
You want to navigate to —> “/404-Error-Page” ???

return wixLocation.to("/404-Error-Page"); 

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 :confused:

Hi there :raised_hand_with_fingers_splayed:

Try removing the return since to() function doesn’t return anything.

wixLocation.to("/404-Error-Page");

Tried without the return. Still doesn’t work :confused:

Welcome back ^^

@russian-dima You know I’ve never left … just watching :eyes: :sweat_smile:

@ahmadnasriya
I know ^^

facing the same issue, not able to redirect to WixLocation.to(/error-page); if a condition is met.

I have found the solution.