Previous / Next Button on Dynamic Page - works on preview, not on published site

Hi,

I added previous and next buttons for a dynamic item page following this tutorial: https://support.wix.com/en/article/velo-tutorial-creating-previous-and-next-buttons-for-a-dynamic-item-page-with-code
It works fine in preview mode but on the published version, something weird happens. It does work sometimes but not all the time.

Here is my index page :

where I added this code:

import {local} from 'wix-storage';

const linkField = "link-lesoon-page-title"; 

$w.onReady(function () {
  $w("#dynamicDataset").onReady(() => {
    const numberOfItems = $w("#dynamicDataset").getTotalCount();
  
    $w("#dynamicDataset").getItems(0, numberOfItems)
      .then( (result) => { 
        const dynamicPageURLs = result.items.map(item => item[linkField]);
        local.setItem('dynamicPageURLs', dynamicPageURLs);
      } )
      .catch( (err) => {
        console.log(err.code, err.message);
      } );
  } );
} );

That’s the item page - in this case the buttons are working fine:

Here is another item page - here the buttons are not working properly, the next button (suivante) is greyed whereas there are items after this one and the previous button (précédente) redirects back to the last page of the collection

Here is the code I used on the item page:

import {local} from 'wix-storage';
import wixLocation from 'wix-location';

$w.onReady(function () {
  $w("#previous").disable();
  $w("#next").disable();
 
  if (local.getItem('dynamicPageURLs')) {
    const dynamicPageURLs = local.getItem('dynamicPageURLs').split(',');

    const currentPage = '/' + wixLocation.prefix + '/' + wixLocation.path.join('/');
    const currentPageIndex = dynamicPageURLs.indexOf(currentPage);

    if (currentPageIndex > 0) {
      $w("#previous").link = dynamicPageURLs[currentPageIndex - 1];
      $w("#previous").enable();
    }

    if (currentPageIndex < dynamicPageURLs.length - 1) {
      $w("#next").link = dynamicPageURLs[currentPageIndex + 1];
      $w("#next").enable();
    }
  }
} );

Is it maybe due to the URL form of that specific element of the collection?
I would appreciate any help!

Thanks,
Elsa

Have you tried using console.log() statements to see what the URLs look like? Maybe there’s something wrong with the resulting URL structure, or special characters that aren’t recognized in URLs.

Hi,
Thanks, I found the problem.
It was due to special characters that were not recognized in URLs (: ? & etc.)

Thanks for the help!