Skip to content

Commit

Permalink
feat(router) add isExplicitNavigation and isExplicitNavigationBack
Browse files Browse the repository at this point in the history
The added properties are useful when deciding on behaviour during the routing lifecycle.

Closes aurelia#449.
  • Loading branch information
jwx committed Jan 11, 2017
1 parent 97e2419 commit 95df138
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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 95df138

Please sign in to comment.