binxie
2023-06-26 1b3fb93f787b8b546a307bf063183f5295d183f8
force-app/main/default/lwc/parentComponentTest/parentComponentTest.js
New file
@@ -0,0 +1,62 @@
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
}