1

I am trying to call an LWC and pass the Id. However the second LWC variable is undefined.

First LWC:

this[NavigationMixin.Navigate]({
            type: 'standard__navItemPage',
            attributes: {
                apiName: 'secondLWC',
            },
            state: {
                c__recordId: 'someId...'
            }
        });

The second LWC Opens but when RenderedCallback runs "recordId" us undefined

recordId;

renderedCallback() {
    console.log('In renderedCallback');
    console.log('recordId: ', this.recordId); //undefined
}

1 Answer 1

3

You need to get recordId from the URL.

@wire(CurrentPageReference)
getStateParameters(currentPageReference) {
   if (currentPageReference) {
       this.recordId = currentPageReference.state?.c__recordId;
   }
}

More details here https://beyondthecloud.dev/blog/get-url-parameters-in-lwc

You must log in to answer this question.

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