Hello, I am looking to redirect any record using it's unqiue Wix ID to a URL saved in the (URL) field called 'URL'
example:
https://www.abc.com/redirect/127c37f1-d5e9-4b0d-b27f-750dbf77aa55
would redirect to:
I have gotten the basic static code below to work:
import wixLocation from 'wix-location';
$w.onReady(function () {
wixLocation.to("https://www.xyz.com");
})
So dynamic code would need to be something like:
import wixLocation from 'wix-location';
$w.onReady(function () {
wixLocation.to('URL');
})
This works! Thanks so much for the guidance. Much appreciated. Is there any technique to not have the Wix page show or load during the redirect? I think when I used to use old HTML redirects like <metahttp-equiv="refresh"content="time; URL=new_url" /> the page would not show, but just redirect to new page.
Yes you do need to import wixLocation, and the final code should be within the onReady for the page. Let me know if this works, or we may have to find another method.
import wixLocation from'wix-location'; $w.onReady(function() { $w("#dataset1").onReady(() => { let currentItem = $w("#dataset1").getCurrentItem(); let link = currentItem.url; wixLocation.to(url); }); })
Do I need this on line #1?
import wixLocation from 'wix-location';
OK, I realized my code didn't match your sample code. So I updated to below and still error message during preview. But live the page loads but does not redirect. I put the text of the URL field and ID field on the page and they both show on the page.
$w("#dataset1").onReady(() => { let currentItem = $w("#dataset1").getCurrentItem(); let link = currentItem.url; wixLocation.to(link); })
Yes, they land on dynamic page. I used the below code and got this error. The BoatData (ID) is referencing Collection name and Field name of each Wix ID for each record.
ReferenceError: wixLocation is not defined
(Line 4)
BoatData (ID)
$w("#dataset1").onReady(() => { let currentItem = $w("#dataset1").getCurrentItem(); let link = currentItem.url; wixLocation.to(url); })
I have a digital boating magazine on Issuu.com (converted PDF to their format). Each boat is also in a searchable database/collection on my Wix site. There's over 300 boats, so I automate the layout of the PDF file (like a mail merge) and place a URL under each boat photo in the format of https://www.mysite.com/boat/127c37f1-d5e9-4b0d-b27f-750dbf77aa55.
Currently, when a user clicks the link on Issuu.com page it goes to a boat detail page on my site with more photos, etc. I would like to change it so that when a user clicks the link it goes to a redirect page like https://www.mysite.com/redirect/127c37f1-d5e9-4b0d-b27f-750dbf77aa55 and then redirects the user to the URL saved in a URL field for that boat record, which is the local boat dealer's detail page with photos, etc., like https://www.boatdealer.com/24-sea-ray-2011
Hi there 👋🏻 I do something similar on my site, but just want to clarify what you're trying to accomplish. What's your setup like? Is this on a dynamic page, or a repeater? Does this happen when a user presses a button?