mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
prevent double navigations to the same view
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user