function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter Martensen 8Peter Martensen 8 

I need help with a Lightning Component button that redirects to the previous page

I need a Lightning Component button in my Community that will redirect to the previous URL.  I have a preview button that opens a pdf, and I need an easy way for the user to get to the record page.  I created the button and it shows up in my Community.  I found this code online that is supposed to redirect to the previous URL.  It isn't working.  Can someone tell me how to change it so it will take me back to the previous page?
Thanks
({
	    redirect: function (){
            var url = window.location.href; 
            var value = url.substr(0,url.lastIndexOf('/') + 1);
            window.history.back();
            return false;
        }
})

 
kartheek racherla 7kartheek racherla 7
you can use lightning navigation approach , create a lightning component with a button and on click of the button create a pagereference object as shown in the below link where in you will be specifying the object/component name to be navigated to

 https://developer.salesforce.com/docs/component-library/bundle/lightning:navigation/documentation

Note: once developed please test the component placing in a lightning page as this doesn't work on the lightning app