Linking search results to Dynamic Pages

Ok so it appears that I was right with my 2nd attempts.
With this code:

functionlinktolocolog(){
$w('#Shunters').onReady(()=>{
$w("#container2").onClick((event)=>{
let $item =  $w.at(event.context);
let currentItem =$item('#Shunters').getCurrentItem();
let dynamicPageID =`${currentItem.number}`
let collectionID =`${currentItem.title}`    console.log('https://www.ukraillog.co.uk/'+collectionID+'/'+dynamicPageID);  wixLocation.to('https://www.ukraillog.co.uk/'+collectionID+'/'+dynamicPageID);});})}

the link from my search result repeater to my dynamic pages works in live mode (but not in preview mode which is where I was trying it previously).

So that solves that issue but leads me to another…
My search results repeater is connected to my (‘#Shunters’) dataset and my Dynamic Pages are connected to my (‘#LocoLogs’) dataset. The Dynamic Pages ID’s are set from the ‘Number’ field which appears in both datasets. However, I have 50 separate numbers in the (‘#Shunters’) database but only 20 of these numbers appear in the (‘#LocoLogs’) database. So with the above code, if I click on a number which doesn’t have a Dynamic Page, it still tries to redirect which obviously leads to a ‘404 There’s Nothing Here’ outcome.

Would it be possible to remove the ability to click on any item where the number doesn’t have a Dynamic Page, leaving just those which have a live Dynamic Page clickable?

Thanks