Basic question about data hooks and routers

Apologies in advance for the very simple nature of my question but I have searched everywhere and can’t find an answer…

I have a static page containing repeaters connected to databases. When users click the links in those repeaters they are taken to dynamic pages. In a couple of cases cases I’d like to intercept the loading of those dynamic pages and take users to bespoke static pages. How would I go about doing this?

Many thanks indeed,

Susanna

You can do it using code.

For example:

let linkReplacement = [
{title: 'the title of the item', newLink: '/my-static-page'},
{title: 'another title',  newLink: '/another-static-page'}
]
$w.onReady(() => {
$w('#repeater1').onItemReady(($i, iData) => {
let objectInArr = linkReplacement.find(e => e.title === iData.title);
if(objectInArr){
$i('#buton1').link = objectInArr.newLink;
}
})
})

You can also set the replacement in a separate field in you collection and adjust the code in accordance.

[EDITED]

Thanks very much! I shall try it out…

This so nearly works…
But I am getting an ‘unexpected token’ error, see screenshot. Have fiddled around to no avail… can you help again? Many many thanks.

Remove the extra ) . It’s a typo.

I removed the extra ) and got a new error! I tried publishing anyway but it didn’t work… Any other ideas? Thanks so much

Sorry for that. I see I wrote the code too fast.
On line 7, change it to:

$w.onReady(() => {

Just to be clear, this will only work if the user uses the link in the repeater. If the user enters the page from outside the repeater link it would not trigger. Where using an an actual hook/router would. Just depends on the use case.

Thanks v much. Still haven’t got it to work but I’m sure it’s issues on my end…

Thanks for explaining this