Code not working...

Hello everyone!

I trying to make redirect from product page (for one of products) to another page with working browser button back)

This code I have get in Wix support, but its doesn’t working…

Maybe somebody knows what the problem in this code?

import wixLocation from 'wix-location';
$w.onReady(function () {
//Code for application pages
wixLocation.onChange((location) => {
let newPath = '/' + location.path[0] + '/' + location.path[1];
console.log("New product URL: ", newPath);
if (newPath === '/product-page/Gelandewagen6x6') {
wixLocation.to('/gelik6x6');
}
});
});

Where from Wix Support did you get this code?

What exactly are you trying to accomplish? What doesn’t work?

Hello.
Here i get it)

I need to be redirected from some products to other pages, and what is very important - when you click on the back button (browser button), the person gets back to the store, and not to the redirected page.

It’s just that I already have a redirect, but when you click back, the person gets to the redirected page and redirects him again - this is not very good.

maybe you know how to solve this problem…?
I trying to fix it already about month

@logopedd85 I’m going to refer this to QA for evaluation.

@yisrael-wix thank you. I’ll waiting for your reply.

@yisrael-wix How do you think, its possible to make it by Iframe?

<script> var timer = null;
function auto_reload()

{
    if (top.location.href === 'https://www.jeeps-monsters.com/product-page/Gelandewagen6x6') {
        top.location.href = 'https://www.jeeps-monsters.com/gelik6x6';
    } else {
        console.log('all ok');
    }
 
} </script>  <body onload="timer = setTimeout('auto_reload()',0);"></body>
//geilik6x6 (Store page)

but this also not working… always returned else(