1

Essentially I am trying to create a back button on my navigation lightning component tab so that when the button is pressed it redirects to the previous url. As it stands I have the follows:

Component

<button class="button1" onclick="{!c.redirect}"> Back </button>

Controller

redirect: function (){
            var url = window.location.href; 
            var value = url.substr(0,url.lastIndexOf('/') + 1);
            value= value;
            console.log(value);
            window.open(value, '_self');
           return false;

    } 

I am assuming on the controller i have to add value = value + (previous url), I'm just not sure how to return the previous url, anyone dealt with this issue before?

3

Ok so i figured it out I needed to parse the function like so:

    redirect: function (){
            var url = window.location.href; 
            var value = url.substr(0,url.lastIndexOf('/') + 1);
            window.history.back();
            return false;

    }
1
  • seems it's just window.history.back(); not sure if this works on both browser and SF1. – Pasan Eeriyagama Aug 31 '17 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.