Route Change

forceCommunity:routeChange

Indicates that a page’s url is changed.

For Use In

Experience Builder Sites

forceCommunity:routeChange is fired 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 example listens to the event and updates a counter that denotes the number of times the route has changed.

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 updates the counter.

1handleRouteChange : function(component, event, helper) {
2    component.set('v.routeChangeCounter', component.get('v.routeChangeCounter') + 1);
3}

This event is supported in Aura-based Experience Builder sites only.

No specifications to show