Default store product page re-direction

Question:
How can I use JavaScript to redirect from a default dynamic product page to a custom dynamic product page derived from a different collection, where the custom page has the same name and link slug?

Product:
Wix Studio Editor

What are you trying to achieve:
I want to maintain functionality in the default store, but due to the minimal amount you can edit the structure of the default product page i have created my own and based it on a custom collection. I need to redirect users from the default product page to a specific page in my custom collection named “Product-Page-1”. Each item in this collection shares the same name and slug as on the default product page.

What have you already tried:
I used the following JavaScript code snippet but it’s not functioning as expected. I alos undertsnad that I can in theory use the tools once the site is published to re-direct users, but I have been specifically told not to pubish the site until its 100%.
Any help would be appreciated. I can give more details on the collections if neccicary but they are pretty standard. I also apologise if the answer is obvious.


import wixLocationFrontend from 'wix-location-frontend';

$w.onReady(async function () {
   const product = await $w("#productPage1").getProduct();
   console.log(product);
   wixLocationFrontend.to(`/product-page-1/${product.slug}`)
}); 

Did you use the Preview mode to test your implementation? I am asking because the to() function mentions the following in the documentation:

Note: The to() function does not work while previewing your site.

thank you i was unaware, the code was working the entire time.
Seperate question I have (I can put this as a seperate topic) is as follows:

Now i have a dynamic page displaying a product, i have a button which i want to link to a seperate dynamic page displaying further information related to that product. I assume that functionality is built in but i can’t work it out :confused:

1 Like

No worries! :slightly_smiling_face:

If the Dynamic Page displaying the product has a reference to route you want the Button element to link to (inside of the page’s CMS Item), you can use getCurrentItem() to get the route.

Then you can use add the url to the Button element using the .link property.

Since there is multiple ways to go about this, feel free to open a new thread around this topic if this implementation doesn’t meet your requirements!