Now that aura:locationChange event no longer works with the new URL format ( effective from Summer '18 release. Reference here), is there a way to detect a change in the URL using lightning events or any other mechanism?

    handleLocationChange: function (component, event, helper) {
        var location = event.getParam("token");//this returns null now with the Summer '18 release.
        if (location != '/n/my_fav_URL') {
            //do some {!stuff}
        } else {
            //do some {!NOT(stuff)}

I see that lightning:navigation and pageReference object don't really provide a straight way to detect the URL changes like aura:locationChange did.


For Lightning communities only:

aura:handler event="forceCommunity:routeChange" action="{!c.handleRouteChange}"

allows you to do so.

For LEX, in app, I dont know if there is a clean way to do so, maybe someone else can provide feedback.

I know you can use setInterval to constantly check the url and log any url changes by leveraging Change Handlers to perform an action based on the change taking place.

  • Thanks @glls. Sorry, I should have mentioned that I am looking for LEX app, not for communities. For the setInterval comment, I think it is probably a better idea to use the aura:locationChange event instead of constantly polling the URL for a change. Fortunately, the aura:locationChange event hasn't been deprecated. It just no longer works as intended with the token returned being empty. For now, I will rely on aura:locationChange event coupled with window.location.pathname. Thank you. – Karthik May 24 '18 at 14:49

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.