use of com.vaadin.flow.router.internal.ConfiguredRoutes in project flow by vaadin.
the class SessionRouteRegistry method addRoutesChangeListener.
/**
* Adds the given route change listener to the registry.
* <p>
* For the session scoped registry also changes to the application scoped
* registry will be delegated to the listener if the added or removed route
* was not masked by a registration in the session scope.
*
* @param listener
* listener to add
* @return registration to remove the listener
*/
@Override
public Registration addRoutesChangeListener(RoutesChangedListener listener) {
final Registration parentRegistration = getParentRegistry().addRoutesChangeListener(event -> {
ConfiguredRoutes configuration = getConfiguration();
List<RouteBaseData<?>> addedVisible = event.getAddedRoutes().stream().filter(routeData -> !configuration.hasTemplate(routeData.getTemplate())).collect(Collectors.toList());
List<RouteBaseData<?>> removedVisible = event.getRemovedRoutes().stream().filter(routeData -> !configuration.hasTemplate(routeData.getTemplate())).collect(Collectors.toList());
// Only fire an event if we have visible changes.
if (!(addedVisible.isEmpty() && removedVisible.isEmpty())) {
fireEvent(new RoutesChangedEvent(event.getSource(), addedVisible, removedVisible));
}
});
final Registration registration = super.addRoutesChangeListener(listener);
return () -> {
registration.remove();
parentRegistration.remove();
};
}
Aggregations