# Wixlocation.to() with dynamic page not working.

**URL:** <https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823>\
**Category:** Ask the community\
**Tags:** wix-stores, question, code\
**Created:** [September 30, 2020, 7:19pm UTC](https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823 "2020-09-30T19:19:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![experimentnoxx](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/experimentnoxx/32/10304_2.png) [@experimentnoxx](https://forum.wixstudio.com/u/experimentnoxx)\
**Post date:** [September 30, 2020, 7:19pm UTC](https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823/1 "2020-09-30T19:19:04Z")

</div>

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](https://www.wix.com/corvid/forum/community-discussion/redirecting-the-url-for-wix-store-product-pages) .

```javascript
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?

---

<div class="post-metadata">

**Author:** ![experimentnoxx](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/experimentnoxx/32/10304_2.png) [@experimentnoxx](https://forum.wixstudio.com/u/experimentnoxx)\
**Post date:** [September 30, 2020, 7:40pm UTC](https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823/2 "2020-09-30T19:40:13Z")

</div>

@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](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)

---

<div class="post-metadata">

**Author:** ![talyaro](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/talyaro/32/5746_2.png) [@talyaro](https://forum.wixstudio.com/u/talyaro)\
**Post date:** [October 1, 2020, 12:52pm UTC](https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823/3 "2020-10-01T12:52:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![experimentnoxx](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/experimentnoxx/32/10304_2.png) [@experimentnoxx](https://forum.wixstudio.com/u/experimentnoxx)\
**Post date:** [October 12, 2020, 12:09pm UTC](https://forum.wixstudio.com/t/wixlocation-to-with-dynamic-page-not-working/33823/4 "2020-10-12T12:09:15Z")

</div>

@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?
