diff --git a/package.json b/package.json index 60a0f04..7eda030 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bhoos/react-kit", - "version": "2.0.12", + "version": "2.0.14", "description": "Bhoos React Library", "main": "dist/index.js", "module": "es6/index.js", diff --git a/src/router/Router.ts b/src/router/Router.ts index afc8450..5409d9a 100644 --- a/src/router/Router.ts +++ b/src/router/Router.ts @@ -26,6 +26,7 @@ export class Router { private childListeners: Array = []; private ConfirmTransitions: Array = []; private currentTransition: Array | null = null; + private onRouteTransition: (route: string) => Promise; /** * Create a router for handling route changes, with a * custom url mapper that is used by `setUrl`, for mapping @@ -48,6 +49,10 @@ export class Router { if (initialUrl) this.setUrl(initialUrl); }; + setOnRouteTransition = (transitionHandler: (route: string) => Promise) => { + this.onRouteTransition = transitionHandler; + } + private getRecentUrl(): string | null { if (this.recentUrl) return this.recentUrl; if (this.parentRouter) return this.parentRouter.getRecentUrl(); @@ -210,6 +215,10 @@ export class Router { }; private async updateUrl(url: string, op: (route: Route) => void): Promise { let newRoute: Route; + if (this.onRouteTransition) { + await this.onRouteTransition(url); + } + if (this.mapUrl) { newRoute = this.mapUrl(url || '', this.setChildUrl); op(newRoute);