Lightning App - getting URL parameter
In lightning whatever attribute you define can be passed as a query parameter .
Lets take a look with sample example
<aura:application>
<aura:attribute name="whom" type="String" default="world"/>
Hello {!v.whom}!
</aura:application>
Here is how the result will look like
Now I will add a query parameter with value as per my attribute defined whom in the URL and now the result will be as below
In very simple terms you just need to define an aura:attribute and you are good
<aura:attribute name="caseid" type="String"/>
Just adding this answer for completion of the thread with the latest release. After Summer 18 release (API version 43 and up) we can utilise lightning:isUrlAddressable
interface.
Implement lightning:isUrlAddressable
interface and use pageReference
attribute.
Example. - Component Assume url is https://<instance>.lightning.force.com/lightning/cmp/<namespace>__componentName?testAttribute=XYZ
<aura:component implements="lightning:isUrlAddressable">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" description="Handler for valueInit event fired when the component has been initialised"/>
{!v.pageReference.state.testAttribute}
</aura:component>
Component Controller
({
doInit : function(component, event, helper) {
console.log(component.get("v.pageReference").state.testAttribute);
}
})
Console output will look like: "XYZ"
There isn't any documented way of doing that, but I was able to do so using a hack.
The Salesforce Lightning URL is something like "/one/one.app#_______" . The blank contains some encoded value in the URL. The encoded value is nothing but the details of the Component/Page in Base64 encoded form.
Use the below code in Javascript in Visualforce to navigate to Lightning Components-
<script>
var compDefinition = {
"componentDef" : "c:NewContact",
"attributes" :{
"recordTypeId" : "012xxxxxxxxxxxx",
"testAttribute" : "attribute value"
}
};
// Base64 encode the compDefinition JS object
var encodedCompDef = btoa(JSON.stringify(compDefinition));
window.parent.location = "/one/one.app#"+encodedCompDef;
</script>