prevent double navigations to the same view

This commit is contained in:
Adam Bradley
2015-09-14 23:20:17 -05:00
parent ffc6bf4c76
commit 8039eae2d2
2 changed files with 33 additions and 0 deletions

View File

@@ -49,6 +49,11 @@ export class NavRouter extends RouterOutlet {
var componentType = nextInstruction.componentType;
var childRouter = this._parentRouter.childRouter(componentType);
// prevent double navigations to the same view
var lastView = this.nav.last();
if (lastView && lastView.componentType === componentType && lastView.params.data === nextInstruction.params) {
return Promise.resolve();
}
// tell the ViewController which componentType, and it's params, to navigate to
return this.nav.push(componentType, nextInstruction.params);

View File

@@ -640,6 +640,34 @@ export class ViewController extends Ion {
util.array.remove(this.items, itemOrIndex);
}
/**
* First view item in this view controller's stack. This would
* not return an item which is about to be destroyed.
* @returns {TODO} TODO
*/
first() {
for (let i = 0, l = this.items.length; i < l; i++) {
if (!this.items[i].shouldDestroy) {
return this.items[i];
}
}
return null;
}
/**
* Last view item in this view controller's stack. This would
* not return an item which is about to be destroyed.
* @returns {TODO} TODO
*/
last() {
for (let i = this.items.length - 1; i >= 0; i--) {
if (!this.items[i].shouldDestroy) {
return this.items[i];
}
}
return null;
}
/**
* TODO
* @param {TODO} item TODO