Go back to stored search results

Hello,

Thanks once more for the great platform. I have search on the INTERVIEWEES page of my site and would like to be able to store search results so users can return to the search results (via a back button or the back button of the browser?) once they’ve clicked on an individual item. How can I do that? The page is: https://www.refugeevoices.co.uk/interviewees. My code on that page is:

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import { local } from ‘wix-storage’;

const linkField = “link-RefugeeVoices-title”;

$w.onReady( function () {
$w(“#dataset1”).onReady(() => {
const numberOfItems = $w(“#dataset1”).getTotalCount();

    $w("#dataset1").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);
});
});
$w(“#repeaterResults”).onItemReady(($w, dataItem, index) => {
let linkToDynamicPage = dataItem[“link-RefugeeVoices-title”];
$w(‘#buttonResults’).onClick(() => {
wixLocation.to(linkToDynamicPage);
});
});
$w(‘#repeaterResults’).onItemReady(($w, itemData, index) => {
$w(“#buttonResults”).label = itemData.title;
});

});

export function button4_click(event, $w) {
let searchValue = $w(‘#input2’).value;
wixData.query(‘1RefugeeVoices’)
.contains(‘interviewSummary’, $w(‘#input2’).value)
.or(wixData.query(‘1RefugeeVoices’).contains(‘title’, $w(‘#input2’).value))
.or(wixData.query(‘1RefugeeVoices’).contains(‘placeOfBirth’, $w(‘#input2’).value))
.find()
.then(res => {
$w(‘#repeaterResults’).data = res.items;
$w(“#repeaterAB”).hide();
$w(“#repeaterResults”).show();
});
}

What code should I put on the results page?

So many thanks!

The Back Button example will get you started in the right direction.

Thanks v much. This enables me to return to the Interviewees page, but not to access the previous state of the page (once it has returned search results). How can I store the search results and return to them? Thank you…

See the Saved Search example to see how to save your search parameters.