From 95df138879740f9c1d6d923075c1c3de5ef697eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Wenzel?= Date: Wed, 11 Jan 2017 06:22:07 +0100 Subject: [PATCH] feat(router) add isExplicitNavigation and isExplicitNavigationBack The added properties are useful when deciding on behaviour during the routing lifecycle. Closes aurelia/router#449. --- src/app-router.js | 2 ++ src/router.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/app-router.js b/src/app-router.js index b59c3dff..7c6c7728 100644 --- a/src/app-router.js +++ b/src/app-router.js @@ -201,6 +201,8 @@ function resolveInstruction(instruction, result, isInnerInstruction, router) { if (!isInnerInstruction) { router.isNavigating = false; + router.isExplicitNavigation = false; + router.isExplicitNavigationBack = false; let eventArgs = { instruction, result }; let eventName; diff --git a/src/router.js b/src/router.js index 20ea7978..2e550a10 100644 --- a/src/router.js +++ b/src/router.js @@ -37,6 +37,16 @@ export class Router { */ isNavigating: boolean; + /** + * True if the [[Router]] is navigating due to explicit call to navigate function(s). + */ + isExplicitNavigation: boolean; + + /** + * True if the [[Router]] is navigating due to explicit call to navigateBack function. + */ + isExplicitNavigationBack: boolean; + /** * The navigation models for routes that specified [[RouteConfig.nav]]. */ @@ -86,6 +96,8 @@ export class Router { this.baseUrl = ''; this.isConfigured = false; this.isNavigating = false; + this.isExplicitNavigation = false; + this.isExplicitNavigationBack = false; this.navigation = []; this.currentInstruction = null; this._fallbackOrder = 100; @@ -158,6 +170,7 @@ export class Router { return this.parent.navigate(fragment, options); } + this.isExplicitNavigation = true; return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); } @@ -178,6 +191,7 @@ export class Router { * Navigates back to the most recent location in history. */ navigateBack(): void { + this.isExplicitNavigationBack = true; this.history.navigateBack(); }