Hey guys, today in this post we are going to learn about How to Navigate to External Web Page 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 External Web Page-->
<lightning-card title="Navigate to External Web 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 External Web Page</td>
<td STYLE="width:50%;">
<lightning-button variant="brand" label="Navigation to External Web Page" onclick={actionToNavigateExternalPage}></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
How do I redirect to a specific section of another page?
You need to add an 'id attribute' to the section you want to show and use the same id in the href attribute with '#' in the anchor tag. So that, on clicking a particular link, you will be redirected to the section that has the same ID mentioned in the anchor tag.
How do I go from one web page to another?
The way through which a user can move from one web page to another on a website is via the use of hyperlinks. A hyperlink is an element of a html page which links to a external or internal location of the web page. A hyperlink can point towards either an external or an internal source.
How do I automatically go to another page in HTML?
To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.
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 |