Change Slider with Sessions

@ahmadnasriya Updated code is here.

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

let currentIndex;

$w.onReady(function () {
    setCurrentSlide();
    $w("#mySlideshow").onChange(setSlideSession);

    // wixLocation.onChange(setSlideSession);
});

function setCurrentSlide() {
    let maxIx = $w("#mySlideshow").slides.length - 1;
    let temp = session.getItem("slide");
    if (temp !== undefined) {
        currentIndex = parseInt(temp) + 1;
    } else {
        currentIndex = 0;
    }
    if (currentIndex > maxIx) {
        currentIndex = 0;
    }
    $w("#mySlideshow").play();
    $w("#mySlideshow").changeSlide(currentIndex);
}

function setSlideSession() {
    
    let ci = $w("#mySlideshow").currentIndex;
    session.setItem("slide", ci.toString());
    
}

But when I navigate between pages, slideshow moves to the previous slides. What can be done?