Pass Data One Page to Another Page using Lightning in Community

Lightning Componet:- "ValidationComponent"

<aura:component implements="force:appHostable,lightning:isUrlAddressable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:actionOverride" access="global" >
<lightning:navigation aura:id="navService" />
<lightning:layout >
<lightning:layoutItem flexibility="auto" size="4" smallDeviceSize="12" mediumDeviceSize="6" largeDeviceSize="4" padding="horizontal-large">
<lightning:input type="text" value="" label="Name" aura:id="NameId" required="true" messageWhenValueMissing="Name Required!!!" maxlength= "10" class="font"/>
</lightning:layoutItem>
</lightning:layout>
<div style="text-align:center">
<lightning:button aura:id="btnSubmit" variant="brand" label="Submit" onclick="{!c.Submit}"/>
</div>
</aura:component>
ValidationComponentController.js

({
Submit : function(component, event, helper) {
debugger;
var nameVal=component.find("NameId").get("v.value"); // get value
if($A.util.isEmpty(nameVal)){
helper.validate(component, event, helper);
return;
}
var navService = component.find("navService"); // its Lightning Navigation auraID
var pageReference = {
type: "standard__namedPage", //Its standard Properties.
attributes: {
pageName: 'navigatepage2' // Community URL Page Name.
},
state: {
name : nameVal,
}
};
navService.navigate(pageReference);
}
})

“ValidationComponentHelper.js”

({
validate : function(component, event, helper){
debugger;
var inputField = component.find("NameId");
inputField.setCustomValidity('Name is Required!!!');
inputField.reportValidity();
},

})
"Lightning Component:- ValidationComponent2"

<aura:component implements="force:appHostable,lightning:isUrlAddressable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:actionOverride" access="global">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="attributeName" type="String"/>
</aura:component>
"ValidationComponent2Controller.js"

({
doInit : function(component, event, helper) {
debugger;
var hostName = window.location.hostname; //Check isLightning or Classic.
var attributeName= window.location.search.substring(1); //get attribute Value from URL
attributeName=attributeName.substring(5, attributeName.length);
alert(attributeName);
}
})
OutPut:-

Leave a Reply