Create a Standard Page with the name “Sample”:
Sample Code:
Component1 cmp:
Component1 cmp:
- <aura:component implements=“forceCommunity:availableForAllPageTypes” access=“global” >
- <aura:attribute name=“Txt” type=“String” default=“”/>
- <div class=“slds-box slds-theme_default”>
- This is component 1.<br/><br/>
- <lightning:input type=“text” value=“{!v.Txt}” label=“Enter some text”/><br/>
- <lightning:navigation aura:id=“navService”/>
- <lightning:button label=“Navigate” onclick=“{!c.navigateToComTwo}”/>
- </div>
- </aura:component>
Component1 JavaScript Controller:
- ({
- navigateToComTwo : function(component, event, helper) {
- event.preventDefault();
- var navService = component.find( “navService” );
- var pageReference = {
- type: “comm__namedPage”,
- attributes: {
- pageName: “sample”
- },
- state: {
- sampleVar: component.get( “v.Txt” )
- }
- };
- sessionStorage.setItem(‘pageTransfer’, JSON.stringify(pageReference.state));
- navService.navigate(pageReference);
- }
- })
Component2 cmp:
- <aura:component implements=“forceCommunity:availableForAllPageTypes” access=“global” >
- <aura:attribute name=“Text” type=“String” default=“”/>
- <aura:handler name=“init” value=“{!this}” action=“{!c.doInit}”/>
- <div class=“slds-box slds-theme_default”>
- This is component two.<br/><br/>
- Text is {!v.Text}.<br/><br/>
- </div>
- </aura:component>
Component3 JavaScript Controller:
- ({
- doInit : function( component, event, helper ) {
- var resultMsg = sessionStorage.getItem( ‘pageTransfer’ );
- component.set( “v.Text”, JSON.parse( resultMsg ).sampleVar );
- }
- })
Output:
This did not work when i tried in developer edition Community
I tried the same in my developer edition. It worked. Make sure the Page name is correct.
Hi,
I have requirement like moving from one lightning component to another lightning component in community ,how can we do this?
This example is from Lightning community.
One more way is to use a parent component with multiple components in it and use hide and show.
how can we pass the type list from the comp1 to comp2…and how possible we can access that in the comp2 with iteration?
Yes. You can pass list. Check the below link for example
http://www.infallibletechie.com/2020/05/navigating-to-page-in-lightning.html
How to open the page in new tab?
You have to use generateURL() to open in new tab.
Check this – https://developer.salesforce.com/docs/component-library/bundle/lightning:navigation/documentation
i am using the navigationin community using LWC but getting app:9 [webruntime] Routing error: (LWR4007) A URL cannot be created to navigate to route "comm__namedPage" .Please help on this
Hi,
https://developer.salesforce.com/docs/atlas.en-us.exp_cloud_lwr.meta/exp_cloud_lwr/get_started_comp_navigation.htm
Aura templates support comm__namedPage schemas that use the name attribute (added in Spring ’20) and the pageName attribute (deprecated in Spring ’20).
So, do not use pageName attribute.