[SalesForce] Fast js navigation in Communities using Lightning/Napili

We are using Community Builder to create pages in a Napili based community. This allows us to use less code and more declarative page maintenance. We've noticed that using regular links clicked by users navigates very quickly between these pages e.g. using a tab navigation bar. It appears to do some kind of partial page refresh.

We also need to programatically navigate after an Apex save. The only way we know to do this is to change window.location but this navigation method is much slower (3-5 times slower) because it does a full page refresh instead of the fast partial refresh described above. Of course we want all our navigations to be fast.

Does anyone know of another technique to navigate (using javascript) using the fast Napili mechanism?

I've already tried:

  • a hidden link and using javascript to click the link (same full page refresh)
  • firing a navigateToURL event (only works on S1)

The hidden link idea is strange. If I make it visible and click it, the navigation is fast but if javascript .click() is used, the navigation is slow.

Any suggestions would be much appreciated and useful for all Napili developers in future.

Best Answer

The entire Napili is based on Lightning Component Framework and all the events available on SF1 is also available inside the Napili template .Its just not well documented I believe .

Here is a small code to help you with navigation inside Napili

<ui:button aura:id="button" buttonTitle="Contact Support" label="Contact Support" press="{!c.navigate}" class="uiButton forceCommunityAskCommunity"/>

Here is a small JS controller with event firing

({

 navigate : function(component, event, helper) {

    //Find the text value of the component with aura:id set to "address"
    var address = component.get("/url");
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": address,
      "isredirect" :false
    });
    urlEvent.fire();
  }
})

Also since its lightning based ,you can always call server side aura enabled method and inside the response returned you can perform client side interactions