I'm building a community on LWR. I would like to share information between 2 pages through sessionStorage.
Page1
handleSelection(event){
this.selectedContactId = event.target.dataset.id;
sessionStorage.setItem("selectedContact", this.selectedContactId);
this[NavigationMixin.Navigate]({
type: "comm__namedPage",
attributes: {
name: "Dashboard__c"
}
});
}
Page2
connectedCallback(){
console.log(sessionStorage.getItem("selectedContact"));
//output: null
}
Observations
- NavigateMixin redirect well from Page1 to Page2, however the sessionStorage is always returning null value
- If I refresh page2 manually sessionStorage works and return the right value.
Workaround
I am using window.open("./dashboard","_self");
but I would really like to use NavigationMixin which does a smoother transition between pages.
renderedCallback
, or wait a tic usingawait Promise.resolve()
inconnectedCallback
?