function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mahamed raheemmahamed raheem 

I have to navigate LWC to Aura component, so in this scenario how to pass recordId LWC to aura component can any one help me on this.

Hi,
I have to navigate LWC to Aura component, so in this scenario how to pass recordId LWC to aura component
can any one help me on this.
Best Answer chosen by mahamed raheem
Ankit RathorAnkit Rathor
Hi Mahamed,

Please try this code:

LWC js file:

navigateToComponent() {
    this[NavigationMixin.Navigate]({
        "type": "standard__component",
        "attributes": {
            "componentName": "c__navigateAura", 
        },
        state: {
            c__recordId: this.recordId
        }
    });
}

Aura Component:

navigateAura.cmp

<aura:component implements="lightning:isUrlAddressable,force:hasRecordId" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="test" type="string"/>
    {!v.recordId} --->this record Id comping Null.
</aura:component>


navigateAura.js:
({
    doInit : function(component, event, helper) {
        var myPageRef = component.get("v.pageReference");
        var recordId = myPageRef.state.c__recordId;
        component.set("v.recordId", recordId);
    }
})

I hope it helps you.

Please let me know if you have any other query and If this solution is helpful then please mark it as Best Answer.

Thanks,
Ankit Rathor

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Mahamed,

Greetings to you!

You need to use lightning/navigation in LWC. If you are navigating to Lightning Component from LWC, you need to implement the lightning:isUrlAddressable interface in your Lightning Component.

Please refer to the below links which might help you further with the above requirement.

https://www.salesforcecodecrack.com/2019/06/navigation-service-in-lightning-web.html

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_navigate

https://developer.salesforce.com/docs/component-library/bundle/lightning-navigation/documentation

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
mahamed raheemmahamed raheem
Hi Anas,
I  used lightning:isUrlAddressable interface in my lighting aura component
But am unable get the record Id from LWC
please find below LWC code

NavigateToViewAll(){
this[NavigationMixin.Navigate]({
"type": "standard__component",
"attributes": {
"componentName": "c__li_ObjectHistory_ViewAll",-->this my aura component
"recordId": this.recordId
}
});

Aura Component:
<aura:component implements="lightning:isUrlAddressable,force:hasRecordId" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="recordId" type="id"/>
    <aura:attribute name="test" type="string"/>
    {!v.recordId} --->this record Id comping Null.
</aura:component>


Please help me.
Ankit RathorAnkit Rathor
Hi Mahamed,

Please try this code:

LWC js file:

navigateToComponent() {
    this[NavigationMixin.Navigate]({
        "type": "standard__component",
        "attributes": {
            "componentName": "c__navigateAura", 
        },
        state: {
            c__recordId: this.recordId
        }
    });
}

Aura Component:

navigateAura.cmp

<aura:component implements="lightning:isUrlAddressable,force:hasRecordId" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="test" type="string"/>
    {!v.recordId} --->this record Id comping Null.
</aura:component>


navigateAura.js:
({
    doInit : function(component, event, helper) {
        var myPageRef = component.get("v.pageReference");
        var recordId = myPageRef.state.c__recordId;
        component.set("v.recordId", recordId);
    }
})

I hope it helps you.

Please let me know if you have any other query and If this solution is helpful then please mark it as Best Answer.

Thanks,
Ankit Rathor
This was selected as the best answer
mahamed raheemmahamed raheem
Thank You, Ankit
 
Ankit RathorAnkit Rathor
Thanks for choosing my answer as the best answer. Please do let me know if you need any further assistance.
Mahak_bMahak_b
Thank you Ankit. Your solution worked for me . :)