[SalesForce] Lightning component for Community & Navigate to Record Detail page

I'm working on a case entry form using lightning component for partner community site (Napili template).

Form is working OK, I can create cases. However I'd like to navigate the user to case detail page after creating the case.

I tried using $A.get("e.force:navigateToURL") but it doesn't work; this function seems specific to Salesfore1.

Can someone please let me know how to navigate to record detail page in lightning component for community?

Best Answer

The beauty of component framework is events .You can make two components talk to each other via events .All you need to do is handle the event when the case record is created in another component and use Navigation to redirect to needed page

Here is sample component you need to create for that

Create a component like below

<aura:component implements="forceCommunity:availableForAllPageTypes">
  <aura:handler event="force:navigateToSObject" action="{!c.navigate}"/>
</aura:component>

The handler controller logic for same is as below

({
 navigate: function(component, event, helper) {
  var sobjectId = event.getParam("recordId");
    console.log(sobjectId);
    if (sobjectId.indexOf("500") >-1) { //Note 500 is prefix for Case Record
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
            "url": '/case/'+sobjectId,
            "isredirect" :false
        });
        urlEvent.fire();
    }
  }
})

Drag this component on the case creation screen using community builder .