Page Reference in Lightning

Page Reference in Lightning | Salesforce Lightning Tutorial

The force:navigateToComponent tag will be deprecated after Summer 18 because it is no longer in use. From now on, You may now control which Lightning components can be opened programmatically using the lightning:isUrlAddressable interface. You can also utilise the v.pageReference attribute to collect URL parameters and use the parameter values in your component. Define a pageReference object for navigating to a custom component that implements lightning:isUrlAddressable and set whatever properties the component permits with the lightning:navigation component. When compared to the now deprecated force:navigateToComponent for conventional navigation Lightning apps, using lightning:navigation with pageReference has the following advantages: – 

Control and manage which URL parameters your component makes use of. 

Protects your apps from changes in URL format in the future. 

For these components, creates a user-friendly URL. 

dont miss out iconDon't forget to check out: Implementing Salesforce Path in Lightning

A page reference is a link to another page. 

var pageReference = { 
    type: 'standard__objectPage', 
    attributes: { 
        objectApiName: 'Account', 
        actionName: 'list' 
    }, 
    state: { 
        filterName: "MyAccounts" 
    } 
};
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes"> 
    <aura:attribute name="url" type="String"/> 
    <aura:attribute name="pageReference" type="Object"/> 
    <aura:handler name="init" value="{! this }" action="{! c.init }"/> 
    <lightning:navigation aura:id="navService"/> 
    <a href="{!v.url}">Link</a> 
</aura:component>

pageReference or generate a URL from a pageReference using the lightning:navigation component A PageReference object in JavaScript represents a page's URL. Instead of attempting to interpret or generate URLs directly, use a PageReference. If Salesforce changes URL formats in the future, this strategy will help you avoid damaged navigation. PageReference provides a well-defined format for describing page types and their associated properties. A PageReference object is made up of key-value pairs that specify the page type you're on.  

dont miss out iconCheck out another amazing blog by Arpit here: Object Records Creation Using CSV File | Salesforce Guide

Types Of Lightning:Navigation

(type: standard component) Lightning Component 

Standard knowledgeArticlePage (type: standard knowledgeArticlePage) is a type of knowledge article. 

Standard namedPage (type: standard namedPage) is a type of named page. 

Standard navItemPage (type: standard navItemPage) is a navigation item page. 

standard objectPage is a sort of object page. 

Standard recordPage (type: standard recordPage) is a type of record page. 

Standard recordRelationshipPage (type: standard recordRelationshipPage) is a type of record relationship page. 

The NavigationMixin extends your component's class with two APIs. These APIs must be invoked with this reference because they are class methods. 

[NavigationMixin.Go](pageReference, [replace]): To navigate to another page in the application, a component calls this[NavigationMixin.Navigate]. 

[NavigationMixin.GenerateUrl] 

(pageReference): To get a promise that resolves to the resultant URL, a component calls this[NavigationMixin.GenerateUrl]. The URL can be used in the href attribute of an anchor by the component. It can also use the URL to launch a new window with the help of the window. open(url) is a browser API that allows you to open a URL in your browser. 

Responses

Popular Salesforce Blogs