How to Navigate Home Page on button click in LWC – Lightning Web Component | How to use Navigation Service (NavigationMixin.Navigate) to Home Page in Lightning Web Component – LWC

31 views

Hey guys, today in this post we are going to learn about How to Navigate Home Page on button click in LWC (Lightning Web Component) Salesforce.

Here are the steps to use the navigation service.

  • Navigation service uses a PageReference.And a page reference is JavaScript that describes its page type, its attributes, and the state of the page.
  • First, we need to import the lightning/navigation module.
  • Use this Syntax:- Import {NavigationMixin} from ‘lightning/navigation;

 

Apply the NavigationMixin function to your component’s base Class.

Why Should You Attend It?

🎯 If You Are Facing Any Of These 6 Challenges. This Masterclass Is For You.

  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 

 

Final Output →

 

Other related post that would you like to learn in Salesforce

 

Create HTML Page →

Step 1:- Create HTML Page : navigationPageLwc.html

navigationPageLwc.html [HTML PAGE]

  1.    <template>
  2.  
  3.     <!-- Navigate to Home Page -->
  4.  
  5.     <lightning-card title="Navigate to Home Page">
  6.  
  7.         <div class="slds-m-around_medium">
  8.             <TABLE class="slds-table slds-table_bordered slds-table_col-bordered">
  9.                 <tr>
  10.                     <td STYLE="width:50%;">Navigation TO Home Page</td>
  11.                     <td STYLE="width:50%;"><lightning-button variant="brand" label="Navigation to Home" onclick={actionToNavigateHome}></lightning-button></td>
  12.                 </tr>   
  13.  
  14.  
  15.             </table>
  16.         </div>
  17.  
  18.     </lightning-card>
  19.  
  20.  
  21. </template>

 

h3 style=”color:#ff0000″>Create JavaScript.js →

Step 2:- Create JavaScript Page : function.js

function.js [JavaScript Page]

  1.  
  2.  import { LightningElement, api } FROM 'lwc';
  3. import {NavigationMixin} FROM 'lightning/navigation';
  4.  
  5. export DEFAULT class NavigationPageLwc extends NavigationMixin(LightningElement) {
  6.     @api recordId='0015i000017iZ5sAAE';
  7.  
  8.  
  9.   /// Navation FOR Home Page
  10.  
  11.   actionToNavigateHome(){
  12.  
  13.    this[NavigationMixin.Navigate]({
  14.       TYPE:'standard__namedPage',
  15.       attributes:{
  16.         pageName:'home'
  17.  
  18.       }
  19.    });
  20.  
  21.   }   
  22.  
  23. }

 

Create Lightning Web Component Meta XML

Step 3:- Create Lightning Web Component : navigationPageLwc-meta.xml

SFDX:Lightning Web Component >> New >> navigationPageLwc-meta.xml

navigationPageLwc-meta.xml [LWC Meta Data XML]

  1.      <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>59.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets>
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10.  
  11. </LightningComponentBundle>

 

 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

How do I navigate from one LWC component to another?

Lightning components can be navigated directly via URL by adding the lightning:isUrlAddressable interface. We use the Navigation service in LWC. Nav the Lightning web component to the Aura component and then in the Aura component, we will open our LWC component.

What is navigate structure?

The navigation structure of a website describes how different pages on your site are organized and connected to one another. For example, some pages and content can only be reached by visiting a specific page. Designers and web developers often plan the navigation structure when making a new website.

What is navigating the interface?

Users are navigated via an interface with a number of interactive elements such as buttons, switches, links, tabs, bars, menus, fields, and the like, some of which will be described more in detail below.

 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net