Monday, September 3, 2018

lightning:isUrlAddressable Interface: Way to get URL parameters in Lightning Components

In Summer'18 release, Salesforce introduces new interface for lightning components which can be used to fetch URL parameters in lightning components.

Before this, we have to write logic in controller.js function to get current URL and split the url parameters.

If we are using lightning tab and displaying lightning component, then we can fetch URL param by using "{!v.PageReference.state.xxxxx}" where xxxxx is URL parameter name.

I have created a lightning component "SK_URLParamCmp.cmp" in order to explain the usage of this interface. Below is code snapshot:

Now I have created a lightning tab "SK_URLParam_Tab", which will open this lightning component.  Pass any value in URL as "accname" as parameter. Below is sample URL:

"/lightning/n/SK_URLParam_Tab?accname=sunil"

Below is UI snapshot:


Hope this will help!!

Note:

If changes to lightning Components are not reflecting immediately in lightning tabs, then you have to disable the "Enable secure and persistent browser caching to improve performance" option under Caching section in Session settings.

For more details on this setting, please refer below URL:
Improved Performance with Secure Client-Side Caching

3 comments:

  1. when am i navigating to another component, tab header is showing 'Loading.....'
    Can you please help me in changing to user friendly.

    ReplyDelete