[SalesForce] Lightning App – getting URL parameter

We are planning to convert some of our VF pages to Lightning apps. Some our VF pages, particularly surveys are URL parameter-driven, since we send survey links directly to users, i.e. https://[vf_instance].force.com/apex/CaseSurvey?caseid=xxxxx

Say we convert the VF page to an Lightning app, we would probably be sending the Lightning survey like this https://[vf_instance].lightning.force.com/c/CaseSurvey.app?caseid=xxxxx

Problem:

In VF page controller, PageReference.getParameters() contains the much needed caseid

However, in Lightning component controller, PageReference.getParameters() does not contain any URL parameters.

How can I get the URL parameter in Lightning app/component apex controller?

THANKS!

Best Answer

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

enter image description here

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

enter image description here

In very simple terms you just need to define an aura:attribute and you are good

 <aura:attribute name="caseid" type="String"/>
Related Topic