import { LightningElement,wire } from 'lwc'; import { CurrentPageReference, NavigationMixin } from 'lightning/navigation'; const NAVIGATION_ITEMS = [ { label: 'Home', pageId: 'home', isCurrentPage: false }, { label: 'PageA', pageId: 'pageA', isCurrentPage: false }, { label: 'PageB', pageId: 'pageB', isCurrentPage: false }, { label: 'PageC', pageId: 'pageC', isCurrentPage: false }, ]; export default class ParentComponentTest extends NavigationMixin(LightningElement) { startCounter = 0; handleStartChange(event) { this.startCounter = parseInt(event.target.value); } handleMaximizeCounter() { this.template.querySelector('c-child-component-test').maximizeCounter(); } //Navigation Start currentPageReference; selectedPageId; newPageId = 'home'; navigationItems = NAVIGATION_ITEMS; get newPageReferenceUrlParams() { return { c__ids: this.selectedPageId }; } get newPageReference() { return Object.assign({}, this.currentPageReference, { state: Object.assign({}, this.currentPageReference.state, this.newPageReferenceUrlParams) }); } navigateToNewPage() { this[NavigationMixin.Navigate]( this.newPageReference, false // if true js history is replaced without pushing a new history entry onto the browser history stack ); // if false new js history entry is created. User will be able to click browser back/forward buttons } handleNavigate(event) { this.selectedPageId = event.target.name; this.navigateToNewPage(); } @wire(CurrentPageReference) setCurrentPageReference(currentPageReference) { if (currentPageReference) { this.currentPageReference = currentPageReference; this.setCurrentPageIdBasedOnUrl(); } } setCurrentPageIdBasedOnUrl() { this.newPageId = this.currentPageReference.state.c__ids; } ////Navigation End }