1

I have a custom lwc that calls an edit pop-up for Event records like this:

this[NavigationMixin.Navigate]({
        type: "standard__recordPage",
        attributes: {
            recordId: this.recordId,
            objectApiName: "Event",
            actionName: "edit"
        }
    });
}

And everything is working fine but I want to do a refresh of my lwc when the edit pop-up is being closed (no matter if it's due to the cancel or save button)

I've checked the documentation and found nothing related to this topic.

Is this even possible? I don't mind if it's via NavigationMixin.Navigate params with an event listener.

UPDATE

I've checked with @wire to the current page reference but it's not working. This is my piece of code:

wInitResult;
@wire(CurrentPageReference) refreshedURL(pageRef) {
    console.log('***pageRef', pageRef);
    refreshApex(this.wInitResult);
  }
@wire(initData, { recordID : '$recordId' }) winitData (response){
    console.log('***wire', response);
    this.wInitResult = response;
    if(response.data){
        //do some actions
    }
    else if(response.error){
        //display some errors
    }
}
handleGenerateEditVisitURL(){
    this[NavigationMixin.Navigate]({
        type: "standard__recordPage",
        attributes: {
            recordId: this.recordId,
            objectApiName: "Event",
            actionName: "edit"
        }
    });
}

But I see the ***pageRef log only for the first iteration and not also when I open the edit modal. Is there something I'm missing?

Regards,

1

2 Answers 2

0

Probably not the best solution, but since calling Navigate there does modify the URL of the page, you could do something like

_interval;
doNavigate(){
  ... your call to navigate
  if (this._interval)
    clearInterval(this._interval);
  
  this._interval = setInterval(()=>{
    // check url for what you'd expect when modal closes
    // if url matches, clear interval and run whatever else you want.   
  },1000);
}

*edit, make sure to clear interval on disconnectedCallback as well

1
  • 1
    P.S. calling clearInterval with an invalid ID is a "no-op", so you don't need to safeguard against it (if (this._interval) is unnecessary).
    – sfdcfox
    Commented Sep 6, 2022 at 18:19
0

You can use CurrentPageReference to detect URL changes from NavigationMixin.Navigate within your component:

import { CurrentPageReference } from 'lightning/navigation';

...

@wire(CurrentPageReference) urlUpdated(pageReference) {
  refreshApex(this.wiredData);
}

You can inspect the pageReference if you want to make sure you're on a specific page, etc. You can read more in lightning-navigation.

1
  • Hi @sfdcfox I've tried your solution but it's not working for me. I've also updated the question with my full code in order to be more comprehensible. Can you tell me if there's something I'm missing here? Thanks in advance!
    – molinet
    Commented Sep 7, 2022 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .