feat(router): allow multiple routers

Custom routers could be add to update LocalStorage, API updates,
database changes, etc.
This commit is contained in:
Adam Bradley
2016-04-05 15:36:35 -05:00
parent 7679ac08f5
commit 3733ebc55e

View File

@ -6,8 +6,7 @@ import {Ion} from '../ion';
import {IonicApp} from '../app/app'; import {IonicApp} from '../app/app';
import {Keyboard} from '../../util/keyboard'; import {Keyboard} from '../../util/keyboard';
import {NavParams} from './nav-params'; import {NavParams} from './nav-params';
import {NavRouter} from './nav-router'; import {pascalCaseToDashCase, isBlank} from '../../util/util';
import {pascalCaseToDashCase, isTrueProperty, isBlank} from '../../util/util';
import {Portal} from './nav-portal'; import {Portal} from './nav-portal';
import {raf} from '../../util/dom'; import {raf} from '../../util/dom';
import {SwipeBackGesture} from './swipe-back'; import {SwipeBackGesture} from './swipe-back';
@ -131,7 +130,7 @@ export class NavController extends Ion {
/** /**
* @private * @private
*/ */
router: NavRouter; routers: any[] = [];
/** /**
* @private * @private
@ -1254,9 +1253,12 @@ export class NavController extends Ion {
this._app && this._app.setEnabled(true); this._app && this._app.setEnabled(true);
this.setTransitioning(false); this.setTransitioning(false);
if (this.router && direction !== null && hasCompleted) { if (direction !== null && hasCompleted && this._portal) {
// notify router of the state change if a direction was provided // notify router of the state change if a direction was provided
this.router.stateChange(direction, enteringView); // multiple routers can exist and each should be notified
this.routers.forEach(router => {
router.stateChange(direction, enteringView);
});
} }
// see if we should add the swipe back gesture listeners or not // see if we should add the swipe back gesture listeners or not
@ -1630,10 +1632,9 @@ export class NavController extends Ion {
/** /**
* @private * @private
* @param {TODO} router TODO
*/ */
registerRouter(router) { registerRouter(router: any) {
this.router = router; this.routers.push(router);
} }
/** /**