In my component, I have an api setter method for recordId and I am generating a URL based on the given recordId inside the setter. I am storing the generated URL and using it as href value like this <a href={recordPageUrl}>...</a>.
The component is inherited from
... extends NavigationMixin(LightningElement) {
@api
set recordId(value) {
this._recordId = value;
this[NavigationMixin.GenerateUrl]({
type: 'standard__recordPage',
attributes: {
recordId: '0050R00000AVZsgQAH',
actionName: 'view'
}
}).then((url) => {
this.recordPageUrl = url;
console.log(url)
});
}
The promise is returning JavaScript:void(0) instead of URL. I tried to remove the setter and move this[NavigationMixin.GenerateUrl]({...}) to connectedCallback then it is working fine and the promise is returning a valid URL.
I have looked into the documentation of PageReference Types and I am not missing any required attribute. On the other hand, salesforce documentation is always using the GenerateUrl inside the connectedCallback.
Summary: Any idea why NavigationMixin.GenerateUrl is not working inside the setter?
<a>