0

I have a simple parent child component. This is surfaced in the community, and for some reason, the parent component is not able to call the child component via the lightning:navigation service. I have below a small code excerpts. It is my understanding that the lightning:navigation is now supported in communities.

ParentComponent

<aura:component implements="lightning:isUrlAddressable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickAction,forceCommunity:availableForAllPageTypes,force:appHostable">

    <lightning:navigation aura:id="navService" />
    <lightning:button  aura:id="mybtn" name="mybtn" variant="base" onclick="{!c.openChildComponent }" label="Open Child"/>


</aura:component>


openChildComponent : function (component, event, helper) {
                    component.find("navService").navigate({
                        "type": "standard__component",
                        "attributes": {
                            "componentName": "c__ChildComponent" },
                        "state": {} 
                    }, true); // replace = true      
            }

ChildComponent

<aura:component controller="myController" access="global" implements="lightning:isUrlAddressable,forceCommunity:availableForAllPageTypes">

   <aura:attribute name="pageReference" type="Object" access="global" />

</aura:component>
0

i found 2 issues with your code.

  1. you should use "comm__namedPage" instead "standard__component" for communities.
  2. you need create one community page and drag and drop your component into that page.

then use below code, it works for me.

    openChildComponent : function (component, event, helper) {
var navservice = component.find("navService");
var pageReference = {
         "type": "comm__namedPage",
                        "attributes": {
                            "pageName": "yourcommunitypage" },
                        "state": {"parameter1":'abc",
                                  "parameter2":'abc",} 
    };
     sessionStorage.setItem('localTransfer', JSON.stringify(pageReference.state));    
     
     
    navService.navigate(pageReference);

you can read parameters in child component init function

doInit : function(component, event, helper) {
       
        var localStuff = sessionStorage.getItem('localTransfer');
    console.log("localStuff =>"+localStuff);
    if(localStuff){
        var state = JSON.parse(localStuff);
        console.log(state.parameter1);
        console.log(state.parameter2);
        
    }   
    },
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.