[SalesForce] How to redirect between lightning components in communities

I have 2 components that I wish to use in a lightning community.

The first component produces a list of records and if the user clicks on the name of the record i want to redirect them to another lightning component.

Here's the code I'm using to redirect and it works when not in the community

    newRedirect: function (component, event, helper) {    
    console.log('get ready to navigate');
    var navService = component.find("navService");
    var pageReference = {
        "type": "standard__component",
        "attributes": {
            "componentName": "CS_Inventory_v2"
        }, 
        "state": {}
    };

    navService.navigate(pageReference);

}

It feels like I'm missing a setting…….

Best Answer

Couple of things:

This pageReference feature is supported only in Salesforce Lightning and the Salesforce Mobile App. It does not work for components that are embedded in a flexipage.

Neither does it state supporting lightning communities.

If the component is in the same community page, you might have to add your components in a wrapper component and manage the logic in it using lightning events.

If the initial list component is on 1 page, and the other is in on another, then you will have to use lightning Navigate ToURL event to navigate between views.

Related Topic