I expanded the example for you, take a look onto it and check the LOGS in CONSOLE…
This is the running code on MASTER-PAGE…
import wixLocation from 'wix-location';
import {session} from 'wix-storage-frontend';
$w.onReady(()=> {let memoryData = JSON.parse(session.getItem('memoryData'));
if(memoryData) {
memoryData.prevPageURL = memoryData.curPageURL
memoryData.curPageURL = wixLocation.url;
session.setItem("memoryData", JSON.stringify(memoryData));
console.log('Mem-Data: ', memoryData);
}
else {let memoryData = {};
memoryData.curPageURL = wixLocation.url;
session.setItem("memoryData", JSON.stringify(memoryData));
}
//--------------------------
$w('#btnA').onClick(()=>{wixLocation.to('https://russian-dima.wixstudio.io/test-site-repeater/pagea')});
$w('#btnB').onClick(()=>{wixLocation.to('https://russian-dima.wixstudio.io/test-site-repeater/pageb')});
$w('#btnC').onClick(()=>{wixLocation.to('https://russian-dima.wixstudio.io/test-site-repeater/pagec')});
//-------------------------
});
→ navData —> is now —> memoryData → including current and previous URL of a navigated page.
This code is running on master-page.
This way → YOU ALWAYS KNOW WHICH IS THE CURRENT LOCATION AND WHICH ONE WAS THE PREVIOUS ONE.
To create a → BACK-BUTTON ← all you will have to do is to get the previous-URL out of the MEMORY-OBJECT and navigate to this URL.
I implemented a → BACK-BUTTON-FUNCTION only on → PAGE-B…
import wixLocation from 'wix-location';
import {session} from 'wix-storage-frontend';
$w.onReady(()=>{let memoryData = JSON.parse(session.getItem('memoryData'));
$w('#btn2Back').onClick(()=>{wixLocation.to(memoryData.prevPageURL)});
});
Check it out…
https://russian-dima.wixstudio.io/test-site-repeater/pagea