1

I have been trying to store my url states in a lightning community using the locationChange event, while testing in the Sitepreview, every time there is a change in my url, the event is fired, however, as soon as I published to production and navigation is fired in between 2 different page layouts, the locationChange event is not fired. For Example:

Button.cmp

<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <aura:handler event="aura:locationChange" action="{!c.updateUrl}"/>
    <aura:attribute name="lastUrl" type="String" />

    <div class="cBackButton showMe">
    <lightning:button variant="brand" 
                      label="Back To last page" 
                      onclick="{!c.goBack}" />
    </div>
</aura:component>

controller.js

goBack : function (component) {
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": "realtive url page within my community"
    });
    urlEvent.fire();
},

updateUrl : function (component) {
    // Update the url everytime a change occurs
    var updateUrl = window.location.href;
    component.set('v.lastUrl', updateUrl);

},

I'm not sure if this is related to the following known issue, so I was wondering if anyone might have run across a similar (or the same) behavior, and if there is some kind of workaround to this. (otherwise, all I/we can do is wait for this to be fixed ¯_(ツ)_/¯ )

1 Answer 1

1

1 workaround I was able to come up with is to basically set an interval function that constantly harasses the community Uri (I hate this). Therefore, I can accurately validate the state of my community URL regardless, and can just compare to the previous one, for example:

var refreshIntervalId = setInterval(function(){
    var currentUrl = window.location.href;
    // Do somethingm with my current Url's state
    })

If needed I can clear the interval (stop the clock) by refering to the refreshIntervalId:

clearInterval(refreshIntervalId);

I do hope someone else hass a better solution/workaround.

You must log in to answer this question.

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