function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hitendar Singh 9Hitendar Singh 9 

Lightning:Navigation with page reference issue

Hi all

I am using <lightning:navigation>component and page reference to navigate the user from one component to another component. Basically I am displaying a list of items in first component and the detail in second component. Now if I click on first item, it navigates to second component and displays the details. It works fine for the first time. When the user clicks the another item the second time, the detail of first item is displayed as the second component's INIT METHOD NOT EXECUTED. 

Did anyone has faced similar issue? Please let me know if you have any solution.

Thanks
Ganesh Hembram 21Ganesh Hembram 21
Hi Hitendar,

Could you please share code snippet?

Thanks & Regards,
Ganesh Hembram
sumithasumitha
Hi Hitendar,

Hope this link helps you.
https://salesforce.stackexchange.com/questions/115663/how-to-navigate-to-the-record-get-the-record-id-in-auraiteration

Thanks,
Sumitha P
Hitendar Singh 9Hitendar Singh 9
SampleComponentNavigation1.cmp
------------------------
<aura:component implements="flexipage:availableForAllPageTypes,lightning:isUrlAddressable" access="global" >
    <lightning:navigation aura:id="navService"/>
    <aura:attribute name="StringList" type="String[]" default="{'1','2'}"/>
    <aura:iteration items="{!v.StringList}" var="seg" indexVar="i" >
        <h4 class="slds-theme_default" onclick="{!c.navigate}" id="{!i}">Sample Link{!i}</h4>
    </aura:iteration>
</aura:component>
---------------------------

SampleComponentNavigation1Controller.js
---------------------------
({
    navigate : function(component, event, helper) {
        console.log('Enter Here');
        var index = event.currentTarget.getAttribute('id');
        var navService = component.find("navService");
        var pageReference = {
            "type": "standard__component",
            "attributes": {
                "componentName": "c__SampleComponentNavigation2",
                
            }, 
            "state": {
                "c__index":index
            }
        };
         
        navService.navigate(pageReference);
    }
})
------------------------------

SampleComponentNavigation2.cmp
-------------------------------
<aura:component implements="flexipage:availableForAllPageTypes,lightning:isUrlAddressable" access="global" >
    <lightning:navigation aura:id="navService"/>
    <aura:attribute name="pageReference" type="Object"/>
    <aura:attribute name="index" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <div class="slds-theme_default">
        Nothing in this page.<br/>
        Index..........{!v.index}
        <lightning:button label="Go Back" onclick="{!c.goBack}"/>
    </div>
</aura:component>
------------------------------------

SampleComponentNavigation1Controller.js
-------------------------------------
({
    doInit : function(component, event, helper) {
        console.log('in init');
        var pageReference = component.get("v.pageReference");
        console.log('index***'+pageReference.state.c__index);
        component.set("v.index",pageReference.state.c__index);
    },
    goBack : function(component, event, helper) {
        var navService = component.find("navService");
        var pageReference = {
            "type": "standard__component",
            "attributes": {
                "componentName": "c__SampleComponentNavigation1",
                
            }
        };
         
        navService.navigate(pageReference);
    }
})
-------------------------------------

@ganesh
Above is the code.

@Sumitha
The solution in the link did not help as I am using Lighning:Navigation component to achieve this functionality
Andy Rouse 7Andy Rouse 7
Hey Hitendar,

I'm having the same issue - a second navigation to a Lightnign Component doesn't re-initialise it. Did you find a solution to this issue?

With thanks,
Andy
Neetu Agrawal 5Neetu Agrawal 5
Hello All,
Did this solution work for anyone. I am trying to implement the same thing, but not able to navigate?

Thanks,
Neetu