buli
2023-04-20 44f866419cde0ff12a91d9c1d92daf9e36b063e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
}