function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akanksha Gupta 58Akanksha Gupta 58 

how to fetch the parameters of URL in lightning component?

Hi,

I have a URL "https://gidev-groupinsurance.cs61.force.com/MemberPortal/s/caseclaimstatus?id=5004C0000033pqlQAA" . I want to use the "id" parameter in my lightning JS controller. How to do that?
sfdcMonkey.comsfdcMonkey.com
HI try something like this :
var sURL = window.location.href;
var userId = sURL.split('id=')[1];

 alert(userId);
Thanks let us know if it helps you
http://sfdcMonkey.com
 
Raj VakatiRaj Vakati

You can do with window.location.href ;. But you can use lightning:isUrlAddressable interface to make this easy rather than using window.location 

Refer this link

https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable/documentation​


 
getUrlParameter : function(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
}