0

Im on a lightning community, i have a lightning component and i want to open another component with this code:

navigateToMyComponent : function(component, event, helper) {
    console.log('1');
    var evt = $A.get("e.force:navigateToComponent");
    console.log('2');
    evt.setParams({
        componentDef : "c:CompetenciaComponent"
    });
    console.log('3');
    evt.fire();
    console.log('4');
}

this its the console log: enter image description here

NOTHINGS HAPPEND AND I DONT KNOW WHY

salesforce-sas
  • 24,161
  • 5
  • 41
  • 78

1 Answers1

1

In communities, if you observe the url, all the navigation is in terms of pages (standard or custom). So whether you use force:navigateToComponent or lightning:navigation with pageReference of lightning component, it will not work as such type of navigation is invalid in communities.

You need to create new custom page in community, then embed your component in it and after that you can use lightning:navigation with pageReference comm__namedPage.

Below is the page reference you need to use in lightning:navigation.

{
    type: "comm__namedPage",
    attributes: {
        pageName: "--YOUR_CUSTOM_PAGE_NAME--"
    }
}
salesforce-sas
  • 24,161
  • 5
  • 41
  • 78
  • It works, is there any way to pass a parameter with this method? i tried different internet examples but I still cant do it
            attributes: {
                pageName: "create-competition-display",
    
    
            },
            state: {
                idRegistro : idMu
            }
    

    this works but i cant receive the parameter in the other component

    –  Jul 26 '19 at 11:40
  • you can refer to https://salesforce.stackexchange.com/questions/270772/getting-pagereference-is-not-working-in-community – salesforce-sas Jul 26 '19 at 11:42