var eUrl= $A.get("e.force:navigateToURL");
eUrl.setParams({
"url": url
});
eUrl.fire();
I am trying to replace above in my code as per documentation it is not recommended. I am trying to use lightning:Navigate.
Source component(where buttons are present):-
<aura:component
implements= "lightning:isUrlAddressable, force:appHostable,
forceCommunity:availableForAllPageTypes"
access="global" controller="ViewNewController">
<lightning:navigation aura:id="navService"/>
<aura:attribute name="pageReference" type="Object"/>
<aura:attribute name="url" type="String"/>
<lightning:button class="PC-save-btn slds-m-right_large" variant="brand"
label="edit" onclick="{!c.handleClick}"/>
</aura:component>
controller js
doInit: function(component, event, helper){
//NAVIGATION USING LIGHTNING
var navService = component.find("navService");
var pageReference = {
"type": "standard__component",
"attributes": {
"componentName": "c__Reg_Edit"
},
"state": {
"c__Id": 'a2R18000004rqUyEAI' ,// WILL LATER COME AS DYNAMIC
"c__NORT": 'NORT-99981347'
}
};
component.set("v.pageReference", pageReference);
var defaultUrl = "#";
navService.generateUrl(pageReference)
.then($A.getCallback(function(url) {
component.set("v.url", url ? url : defaultUrl);
}), $A.getCallback(function(error) {
component.set("v.url", defaultUrl);
}));
},
handleClick: function(component, event, helper) {
var navService = component.find("navService");
// Uses the pageReference definition in the init handler
//JSON.stringify(pageReference); - THIS DATA COMES IN DEBUG JS
//"{"type":"standard__component","attributes":
//{"componentName":"c__PC_OppReg_Edit"},"state":
//{"c__Id":"a2R18000004rqUyEAI","c__NORT":"NORT-99981347"}}"
var pageReference = component.get("v.pageReference");//DEBUG POINT HERE
event.preventDefault();
navService.navigate(pageReference);//CODE IS STUCK HERE
}
Component 2:-
(where needs to be directed to with 2 parameters
<aura:attribute name="res" type="String" />
<aura:handler name="change" value="{!v.pageReference}" action="
{!c.onPageReferenceChange}"/>
CONTROLLER JS
onPageReferenceChange: function(component, event, helper) {
var myPageRef = component.get("v.pageReference");
var firstname = myPageRef.state.c__res;
component.set("v.res", res);
},
Went through following links:-
How to navigate from one lightning component to another Lightning component
Help navigating from one lightning page to another in communities
https://force-base.com/2016/01/04/how-to-navigate-from-one-component-to-another-in-lightning/
I am getting DEBUG DATA as highligher in comments but .navigate is stuck.