Hey guys, today in this post we are going to learn about How to use Navigation Service (NavigationMixin.Navigate) to Navigate LWC Page in LWC.
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.
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]
<template>
<!-- Navigate to LWC Page-->
<lightning-card title="Navigate to LWC Page">
<div class="slds-m-around_medium">
<TABLE class="slds-table slds-table_bordered slds-table_col-bordered">
<tr>
<td STYLE="width:50%;">Navigation TO LWC Page</td>
<td STYLE="width:50%;">
<lightning-button variant="brand" label="Navigation to LWC Page" onclick={actionToNavigateLWCPage}></lightning-button>
</td>
</tr>
</table>
</div>
</lightning-card>
</template>
Create navigationPageLwc.js β
Step 2:- Create JavaScript Page : function.js
navigationPageLwc.js [JavaScript Page]
import { LightningElement, api } FROM 'lwc';
import {NavigationMixin} FROM 'lightning/navigation';
export DEFAULT class NavigationPageLwc extends NavigationMixin(LightningElement) {
// Navigate TO External Web Page
actionToNavigateExternalPage(){
this[NavigationMixin.Navigate]({
TYPE:'standard__webPage',
attributes:{
url:'https://www.w3web.net/'
}
});
}
}
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]
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Further post that would you like to learn in Salesforce
Further post that would you like to learn in Salesforce
How do I navigate to another page in LWC?
The navtab component can be used at the bottom of each page to let the user navigate through the app. The c-nav-tab component customizes the lightning-button component to navigate to the next page in the app. The consumer specifies a tab-name and a label . The lwc-recipes repo has lots of navigation examples.
What is currentpagereference lwc?
Gets the current page reference from the router container. This wire is also available in Lightning Experience.
What is navigation service in LWC?
Navigation Service in Lightning Web Components are used to navigate to Record Pages, Web Pages, Objects, List Views, Custom Tabs, Related Lists, Files etc. Navigation Service uses a PageReference rather than a URL.
Related Topics | You May Also Like
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 |