WIX-Router: Request Path Issue

Hi all,

I’m using wix-router to redirect visitors from my site’s specific path to another site with the same path.
However, when I use:

let path = request.path;

It returns the path with comma sign (,) rather than slash sign (/).
So, when I am routed from /level1/level2/level3 It takes me to /level1,level2,level3 and not to /level1/level2/level3.

I need to find a way to get the path as a string with “/” or a way to replace all the “,” with “/”.

Any ideas?

Hi Shahaf

You might want to revisit the documentation on this api here:

Note: that path is an array not a string. as the example shows…


Note in the comment it shows [“mammals”, “elephant”] as the value of path.
So path[0] = “mammals”; and path[1] = “elephant”;

Make sense?

Thanks!
Yes. It makes a perfect sense.

I would be glad to understand if there is a way to convert the array into a string…
Or should I accomplished my task in a whole different way…
Any workaround will be appreciated.

The best thing to do is use the baseUrl and the url properties.

So something like

let targetPath = request.url.substring(request.baseUrl.length);
let redirectUrl = 'https://www.newDomain.com/'+targetPath;
return redirect(redirectUrl);

Thanks! works great for me…