Issue with page not showing and jumping to a different page

I have a repeater that shows events in my database. On the events item page I have some text fields with an onclick event.

export function SeeAdvancedTxt_click(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
 let eventId = eventItem._id;
    console.log(eventId);
    session.setItem("EventId", eventId);
    session.setItem("PhotoClass", "A")
    wixLocation.to("/events-gallery");
}

As can be seen from the code 2 session storage items are set and the page is changed to the Events Gallery page all this page has on it is a slide deck gallery and a dataset. The dataset is linked to a table called photographs. The photographs table has a reference field to the Events table. The page is meant to filter the photographs using the stored session information set in the previous page . The code to do this is shown below.

import wixData from 'wix-data';
import {session} from 'wix-storage';
var eventId;
var photoClass;
$w.onReady(function () {
 // Write your JavaScript here
    eventId = session.getItem('EventId');
    photoClass = session.getItem('PhotoClass');

    console.log('Id =' + eventId)
    console.log('Class = ' + photoClass)
    $w('#photographsDS').onReady(() =>{
        filterPhotos();
    });
 // To select an element by ID use: $w("#elementID")

 // Click "Preview" to run your code
});

function filterPhotos()
{
    console.log('in filterPhotos')
 let filter = wixData.filter().isEmpty('_id') // this will ensure that there are no photos in the dataset
 if(eventId.length > 0) // filter all photos for an event
    {
        filter = wixData.filter().eq('event',eventId);
        console.log('Filter event id');
    }
 if (photoClass.length > 0)
    {
 if(eventId.length > 0) // filter by event and class
        {
            filter = wixData.filter().eq('event',eventId).eq('type',photoClass);
            console.log('Filter event id and photoclass');
        }
 else // filter by class only
        {
            filter = wixData.filter().eq('type',photoClass);
            console.log('Filter photo class');
        }
    }
    $w('#photographsDS').setFilter(filter).then(() => {console.log('Filter is set')});
}

When I test this I open the events item page select an event that I know has photographs linked to it and click on one of the text fields that write the session information and redirect the the Events Gallery page. From the debugger I can see that the page is loaded, the session information is retrieved and the filter is set a snippet of the debugger pane is shown below


The issue is that instead of the Gallery Events page opening instead a dynamic repeater page linked to my photographs is opened instead. The images are the 2 default images I have filtered for that pages dataset not the images from the event. If I go back to the editor select the Events Gallery page and preview it the correct images are shown in the slide deck gallery.

Can somebody tell me why my page does not load when it is opened from a link and how a completely different page loads instead.