In this tutorial we will see how we can navigate to list view in lightning,
Salesforce
recommended us to stop using anchor tag for redirection because of security
concerns.
That's why for
redirection I used events trigger and but you need to take care because it will
not work if we will use it without tabs, home page etc.
So for
make it work I have created one component Named NavigateEventComponentExample and used that component on tab. below
is code snippet for component.
<aura:component implements="force:appHostable" controller="NavigateEventController"> <h1 class="slds-m-around_small">Redirect to List View</h1> <lightning:button class="slds-m-around_small" label="Go" onclick="{!c.goToListView}"> </lightning:button> </aura:component>
Let’s understand above component
1. I used implements="force:appHostable" to make it available for tabs.
2. Go Button that will help us to trigger event firing.
When we will click on above button then goToListView function in controller of NavigateEventComponentExample will call.
Below is
code snippet for controller
({ goToListView : function(component, event, helper){ var listViewRedirectEvent = $A.get('e.force:navigateToList'); listViewRedirectEvent.setParams({ "listViewId": '00B6A000007jQu0UAE', "listViewName": 'All_Leads', "scope": "Lead" }); listViewRedirectEvent.fire(); } })
In above component
1. We have created object for event and by use of e.force:navigateToList we tell event to redirect us to list view when fire.
2. Set event parameters i.e. List view Id, Name and scope(In our case scope is Lead).
3. Fire the event.
Once event get fire then user will redirect to list view of given Id and object.
Let me know if you found any issue in above code snippet and understanding.