Sunday, May 30, 2021

Navigation Service in LWC(Lightning Web Components)

To navigate in Lightning Experience, Lightning Communities, and the Salesforce app, use the navigation service, lightning/navigation.

We need to flow below steps for impplemention :-

  • we need to import the lightning/navigation module.
             import { NavigationMixin } from 'lightning/navigation';
  • Apply the NavigationMixin function to your component’s base class.
            export default class MyCustomElement extends NavigationMixin(LightningElement) {}
  • Create a plain JavaScript PageReference object that defines the page
     To dispatch the navigation request, call the navigation service’s [NavigationMixin.Navigate]        (pageReference, [replace])

      navigateNext() {
       this[NavigationMixin.Navigate]({
           type: 'standard__navItemPage',
           attributes: {
               apiName: this.tabName,
           },
          });
       }
The NavigationMixin adds two APIs to your component’s class.
 Since these APIs are methods on the class, they must be invoked with this reference.

No comments: