1

With respect to my Previous question, this custom refresh lightning component is on home page of the community. But, this is refreshing all my entire community no matter what page I am on. How to get rid of this? Like, how to make only the home page get refreshed?

1
  • check for location.href and set a condition for the home page
    – glls
    Sep 8, 2017 at 15:11

2 Answers 2

2

you can set a variable for the current url, for example:

var currentUrl = window.location.href;
if(currentUrl.includes("home"){
    //execute your callback function
}
else{
    //don't do it =P
}
8
  • In the URL for Home page, I only see: sandbox.cs30.force.com/projName/s. And every other page is like the extension for this home page's URL. How to have a conditional check here.
    – SatyaV
    Sep 8, 2017 at 15:22
  • instead of home you can set the condition to match the url, doesnt need to be includes("home"), the above is just for reference purposes =P
    – glls
    Sep 8, 2017 at 15:24
  • lol. I can do that. But, this should be standard even if I deploy this component to Production. I shouldn't be going back to code and make a change for the URL :) Thus wondering.
    – SatyaV
    Sep 8, 2017 at 15:26
  • use a regex for patterns then ;)
    – glls
    Sep 8, 2017 at 15:26
  • Don't you think that's complicated? At least for me. (-'- . -'-)
    – SatyaV
    Sep 8, 2017 at 15:29
1

With the help of my friend, @glls, I got the idea to make a condition by utilizing window.location.href; and also added some extra effort: if(currentUrl.endsWith("/s/") to get it stick to the home page alone. Here is complete working code:

var currentUrl = window.location.href;
    console.log(currentUrl);
    if(currentUrl.endsWith("/s/")) {
          //Callback function
   } else {
         //do something 
  }

Note: Make sure to use unrender to stop/kill the setInterval method whenever you leave the component's page. That way, every time you navigate to a different page, setInterval gets killed and will not trigger on your newly opened page/window. Hope this helps someone who visits this post.

You must log in to answer this question.

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