I have a datatable with a new button that uses the NavigationMixin.Navigate functionality in LWC.
After the record is created it default navigates to the record, I had to add "navigationLocation: 'RELATED_LIST'" to the state to make it stay on the original record page where the component is placed.However, after the dialoge is done and new record has been created, it stops running. I want to refresh the datatable to display the new record but I can't run any code after NavigationMixin. Is there anyway to solve this?import { NavigationMixin, CurrentPageReference } from 'lightning/navigation';
Code run when clicking new:
createNew() {
let defaultFieldValues = '';
this.loading = true;
if(this.parentFieldName !== null) {
defaultFieldValues = this.parentFieldName +"="+this.recordId;
}
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: this.objectName,
actionName: 'new'
},
state : {
nooverride: '1',
defaultFieldValues: defaultFieldValues,
navigationLocation: 'RELATED_LIST',
recordTypeId: this.recordTypeId
}
}).then(result => {
console.log(result);
return refreshApex(this.wiredResult);
}).catch(error => {
console.log(error);
});
}