Wixlocation.to() with dynamic page not working.

Hi,
I’m trying to cause the default Store Product-page to redirect to an alternative dynamic Products (Slug) page I’ve created.
I’ve tried to do what’s described in an old post here .

let path = wixLocation.path;
console.log("path before shift: " + path);
// remove "/product-page/"
path.shift();
//let toUrl = "/products/" + path.join("/"); // this is the original version
console.log("path after shift: " + path);
let toUrl = "/products/" + path ;
console.log("url to go to:" + toUrl);
wixLocation.to(toUrl);

The final console.log prints a path which is just fine and works if I manually paste it in the live site. However, I get a non-descriptive error from the .to()

Any hints as to why this doesn’t work, or how it should?

@giri-zano any ideas why the above shouldn’t work?

@brett-haralson maybe something is broken on your end? Could you have someone have a look at it? Here’s my editor link: https://editor.wix.com/html/editor/web/renderer/edit/83354e7d-0e49-40bf-a4a6-951c8ecfd49f?metaSiteId=3ada8814-771f-490f-bf40-2b9c3fd2a086&editorSessionId=ab593175-b30c-4d48-a193-2586f92a7002&referralInfo=dashboard

While this is a link to an experimental site, it’s actually something I need for a customer (on a different site of course)

Hey,
Move your code (except the import statement) inside the onReady() function and it should work.
HTH,
Tova

1 Like

@talyaro , thank you, that does work. I can’t mark it as the best answer, as it’s a reply to a reply. If you’ll add this as a reply to the original question, I’ll be happy to mark it.
Although the redirect solution is suboptimal now that it needs to load the old page first. It’s not a good user experience. Really, it would be better to use routing to redirect it in the first place. But I don’t see a way to create a router for the original product pages. Is this possible?