Skip to content

Commit

Permalink
Merge pull request aurelia#455 from jwx/explicit-navigation-flags
Browse files Browse the repository at this point in the history
feat(router) add isExplicitNavigation and isExplicitNavigationBack
  • Loading branch information
EisenbergEffect authored Feb 1, 2017
2 parents 164ec3f + f9cf4ea commit 507015e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ function resolveInstruction(instruction, result, isInnerInstruction, router) {
let eventArgs = { instruction, result };
if (!isInnerInstruction) {
router.isNavigating = false;
router.isExplicitNavigation = false;
router.isExplicitNavigationBack = false;

let eventName;

if (result.output instanceof Error) {
Expand Down
14 changes: 14 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -178,6 +191,7 @@ export class Router {
* Navigates back to the most recent location in history.
*/
navigateBack(): void {
this.isExplicitNavigationBack = true;
this.history.navigateBack();
}

Expand Down

0 comments on commit 507015e

Please sign in to comment.