Newer Version Available

This content describes an older version of this product. View Latest

forceCommunity:routeChange

The system fires the forceCommunity:routeChange event when a page’s URL changes. Custom Lightning components can listen to this system event and handle it as required—for example, for analytics or SEO purposes.

This event is supported in template-based communities only.

Note

This sample component listens to the system event.
1<aura:component implements="forceCommunity:availableForAllPageTypes">
2    <aura:attribute name="routeChangeCounter" default="0" type="Integer" required="false"/>
3    <aura:handler event="forceCommunity:routeChange" action="{!c.handleRouteChange}"/>
4    <h1>Route was changed: {!v.routeChangeCounter} times</h1>
5</aura:component>
This client-side controller example handles the system event.
1({handleRouteChange : function(component, event, helper) {
2    component.set('v.routeChangeCounter', component.get('v.routeChangeCounter') + 1);
3    }
4})