UNPKG

service-utilities

Version:

Utility Package for FIORI UI5

85 lines (77 loc) 2.73 kB
/** * @module RouterExpansion * @description Utility class for router related methods * @author jpanti * @version 1.0.0 * @created 2025-08-01 * @lastModified 2025-08-01 * @license ISC */ sap.ui.define( [ "sap/ui/core/routing/History", "sap/m/library", "./AbstractController", "./EventRadio", ], (History, mobileLibrary, AbstractController, EventRadio) => { "use strict"; const defaultCallback = (oEvent) => {}; // default callback const eventRadio = new EventRadio("router"); class RouterExpansion extends AbstractController { // Private Property Declaration ===================== #oRouter; // ================================================== // Initialization =================================== constructor(oController) { super(oController); this.#oRouter = this.getController().getOwnerComponent().getRouter(); } getRouter = () => this.#oRouter; getEventRadio = () => eventRadio; // ================================================== // Router-based Methods ============================= onRedirect = (url) => mobileLibrary.URLHelper.redirect(url, true); backTo(targetRoute, oDetails = {}) { var oHistory = History.getInstance(); var sPreviousHash = oHistory.getPreviousHash(); if (sPreviousHash !== undefined) { window.history.go(-1); } else this.goTo(targetRoute, oDetails, true); } goTo(targetRoute, oDetails = {}) { this.getRouter().navTo(targetRoute, oDetails); return this; } attachRouteMatched(callback = defaultCallback) { if (callback !== defaultCallback) this.getRouter().attachRouteMatched(callback, this); return this; } attachBeforeRouteMatched(callback = defaultCallback) { if (callback !== defaultCallback) this.getRouter().attachBeforeRouteMatched(callback); return this; } attachBypassed(callback = defaultCallback) { if (callback !== defaultCallback) this.getRouter().attachBypassed(callback); return this; } attachRoutePatternMatched(callback = defaultCallback) { if (callback !== defaultCallback) this.getRouter().attachRoutePatternMatched(callback); return this; } attachPatternMatched(routeName, callback = defaultCallback) { if (callback !== defaultCallback) this.getRouter() .getRoute(routeName) .attachPatternMatched(callback, this.getController()); return this; } // ================================================== } return RouterExpansion; } );