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?
2 Answers
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
}
-
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. 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– gllsSep 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. Sep 8, 2017 at 15:26
-
-
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.