Hey guys, today in this post we are going to learn about How to Navigate Chatter 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.
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 Chatter Page -->
<lightning-card title="Navigate to Chatter 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 Chatter Page</td>
<td STYLE="width:50%;"><lightning-button variant="brand" label="Navigation to Chatter" onclick={actionToNavigateChatter}></lightning-button></td>
</tr>
</table>
</div>
</lightning-card>
</template>
h3 style=”color:#ff0000″>Create JavaScript.js →
Step 2:- Create JavaScript Page : function.js
function.js [JavaScript Page]
import { LightningElement, api } FROM 'lwc';
import {NavigationMixin} FROM 'lightning/navigation';
export DEFAULT class NavigationPageLwc extends NavigationMixin(LightningElement) {
@api recordId='0015i000017iZ5sAAE';
/// Navigation TO chatter
actionToNavigateChatter(){
this[NavigationMixin.Navigate]({
TYPE:'standard__namedPage',
attributes:{
pageName:'chatter'
}
});
}
}
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
How do I navigate to a different page in LWC?
Use the navigation service, lightning/navigation , to navigate to many different page types, like records, list views, and objects. In the component's JavaScript class, import the `NavigationMixin` function from the lightning/navigation module.
How do I redirect to another page?
Redirecting pages in HTML can be effectively achieved using either the meta tag or the anchor tag. The meta tag method is ideal for automatic redirection with a time delay, while the anchor tag method is useful for user-initiated navigation.
How do I navigate between two pages in HTML?
HTML links are hyperlinks. You can click on a link and jump to another document. When you move the mouse over a link, the mouse arrow will turn into a little hand. Note: A link does not have to be text.
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 |