From 1b3fb93f787b8b546a307bf063183f5295d183f8 Mon Sep 17 00:00:00 2001 From: binxie <137736985@qq.com> Date: 星期一, 26 六月 2023 16:53:25 +0800 Subject: [PATCH] merge --- force-app/main/default/lwc/parentComponentTest/parentComponentTest.js | 62 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/force-app/main/default/lwc/parentComponentTest/parentComponentTest.js b/force-app/main/default/lwc/parentComponentTest/parentComponentTest.js new file mode 100644 index 0000000..30c8595 --- /dev/null +++ b/force-app/main/default/lwc/parentComponentTest/parentComponentTest.js @@ -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 +} \ No newline at end of file -- Gitblit v1.9.1