Navigation Service in LWC (Lightning Web Components)



Introduction

Navigation Service in LWC simplifies navigating between the pages within the applications. Utilizing the navigation service in LWC you can create a smooth and seamless navigation experience for users within your Salesforce application. In this blog post, we will deep dive into the steps on how to use the Navigation Service.

What is a Navigation Service?

Navigation Service is a built-in module in LWC that enables developers to navigate different pages and components within the Salesforce ecosystem. This service provides you with a set of methods that helps you navigate different web pages, record pages, or other Lightning Components. 

Using the Navigation Service

1. Import the Navigation Service from the lightning/navigation module.



2. Apply the NavigationMixin function to the base class.



3. Create a JS PageReference object that defines the page.



4. Call the navigation service's [NavigationMixin.Navigate](pageReference) to dispatch the navigation request.



5. In steps 3 and 4 we saw how to navigate to a Record Page using NavigationMixin. You can also navigate to the URL using the navigation service. You can use standard__webPage type in the navigate method and provide the URL to navigate to any specific web page.



6. In addition to URLs and Standard Record Pages, you can also navigate to custom Lightning Pages using NavigationMixin. To navigate to a custom lightning page, provide standard__navItemPage as the type and the API name of the custom lightning page to which you want to navigate.





A short Demonstration 👇








For more insight on Navigation refer to the Salesforce Official Documentation on Navigation.


Thank you and see you in the next blog. 

Comments

Popular posts from this blog

Display Maps in LWC

Calling Apex method from LWC