I've been stuck on this for a solid day now. I have a large package that need to deploy which uses 3 Aura components. They navigate to each other at various times using navigateToComponent. When I moved the component into the Community the function doesn't work.
From what I've read, we have to use lightning:isUrlAddressable, navService, pageReference, and sessionStorage (if passing parameters, which I am).
I have test components I'm using for this and am managing to pass a string parameter into the target Aura component, which is good, but I have no idea how to retrieve it from the URL in the target component. From what I've looked at online, v.pageReference should be available if I am implementing lightning:isUrlAddressable, which I am. See below and let me know your thoughts.
Please note that when I debug this it is stopping at myPageRef on the target component because pageReference is null. I've tried creating this attribute in the target componet but it doesn't fix this. I need to better understand how to get the v.pageReference on the target component.
Edit 1: I removed flexipage from both components. This did NOT fix the problem.
The Aura component that is being used to launch the second via a button.
<aura:component implements="lightning:isUrlAddressable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes"
access="global" >
<lightning:navigation aura:id="navService"/>
<aura:attribute name="pageReference" type="Object" />
<lightning:button label="Click Me" onclick="{!c.click}"/>
</aura:component>
The Controller js that is being used to launch the second.
({
click : function(component, event, helper) {
event.preventDefault();
var navService = component.find("navService");
var pageReference = {
type: 'comm__namedPage',
attributes: {
pageName: "ltest2"
},
state: {
c__firstname: 'paul'
}
}
sessionStorage.setItem('pageTransfer', JSON.stringify(pageReference.state));
navService.navigate(pageReference);
}
})
The target component we are launching and passing value into firstname.
<aura:component implements="lightning:isUrlAddressable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes"
access="global" >
<aura:attribute name="firstname" type="String" default="not working" />
<aura:handler name="init" value="{!this}" action="{!c.onPageReferenceChange}"/>
<aura:handler name="change" value="{!v.pageReference}" action="{!c.onPageReferenceChange}"/>
Name: {!v.firstName}
</aura:component>
The Controller js which is meant to set v.firstname.
({
onPageReferenceChange: function(component, event, helper) {
var myPageRef = component.get("v.pageReference");
var firstname = myPageRef.state.c__firstname;
component.set("v.firstname", firstname);
}
})
I want reiterate this point next to the code: Please note that when I debug this it is stopping at myPageRef on the target component because pageReference is null. I've tried creating this attribute in the target componet but it doesn't fix this. I need to better understand how to get the v.pageReference on the target component.
Thanks in advance!!!