4

I have lightning component which I put into lightning page using App Builder. The component display table with field history tracking like in the Salesforce Classic. Also there is a button on component: "Go to all history records". If user clicks it, he must see new lightning page with ONLY my component (and also I must say to component, that it need to display, for example, 1000 records, and to say to it id of sobject, which history user were looked on previous page). All this stuff stored in attribute in component. So, I need to redirect to new page with only my component and set attributes, when user click button on page. I have read about this already:

var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
   "url": someurl   
});
urlEvent.fire();

But I don`t know, how to set parameters to component in new page. Please, help solve this problem.

1 Answer 1

2

Ideally from winter 17 release you should be able to use the new event force:navigateToComponent to achieve the Navigation with passing Ids or other attributes between two components .

For now you can simply pass the parameters via query variables like below

var urlEvent = $A.get("e.force:navigateToURL");
 urlEvent.setParams({
   "url": someurl + 'id=xyz' + '&var1=xyz' ;
 });
urlEvent.fire();

And then in the destination component you can use window.location.href to fetch the key values .

The JS function in the helper will be like below

function getParam(param) {
   var url =   window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i=0;i<url.length;i++) {
      var params = url[i].split("=");
      if(params[0] == param)
       return params[1];
      }
  return false;
 }

You will just pass the key and retrieve value from the URL.

8
  • I have try to add simple parameters to url, but my page I want to redirect to has following url: https://margaritabarabash-dev-ed.lightning.force.com/one/one.app#eyJjb21wb25lbnREZWYiOiJvbmU6ZmxleGlwYWdlIiwiYXR0cmlidXRlcyI6eyJ2YWx1ZXMiOnsiZmxleGlQYWdlRGV2ZWxvcGVyTmFtZSI6IkFsbF9GaWVsZF9IaXN0b3J5X1JlY29yZCIsImxhYmVsIjoiQWxsIEZpZWxkIEhpc3RvcnkgUmVjb3JkIiwiaWNvblVybCI6Imh0dHBzOi8vbWFyZ2FyaXRhYmFyYWJhc2gtZGV2LWVkLm15LnNhbGVzZm9yY2UuY29tL2ltZy9pY29uL3Q0djM1L2N1c3RvbS9jdXN0b20yMV8xMjAucG5nIiwiaWNvbkNvbG9yIjoiOGE3YWVkIn19LCJ0IjoxNDczNjkyNjUxMTk4fQ%3D%3D I have got an error
    – Margarita
    Commented Sep 12, 2016 at 15:05
  • Sorry i did not get you .If you could elaborate might be able to help you Commented Sep 12, 2016 at 15:06
  • What are you trying to do with this base 64 URL ?This seems to be base64 encode string in # paramter Commented Sep 12, 2016 at 15:08
  • How you can see, this strange url has # in it and I can not do anything with it. When I added parameters to the end of url, I have got error. Is it more understandable?
    – Margarita
    Commented Sep 12, 2016 at 15:10
  • What does it mean? base64
    – Margarita
    Commented Sep 12, 2016 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .