mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
fix(router): fix nested ion-nav router
This commit is contained in:
@ -17,20 +17,28 @@ import {ViewController} from './view-controller';
|
|||||||
})
|
})
|
||||||
export class NavRouter extends RouterOutlet {
|
export class NavRouter extends RouterOutlet {
|
||||||
private _lastUrl: string;
|
private _lastUrl: string;
|
||||||
|
private _nav: Nav;
|
||||||
|
private _parent: Router;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
elementRef: ElementRef,
|
elementRef: ElementRef,
|
||||||
loader: DynamicComponentLoader,
|
loader: DynamicComponentLoader,
|
||||||
private parentRouter: Router,
|
parentRouter: Router,
|
||||||
@Attribute('name') nameAttr: string,
|
@Attribute('name') nameAttr: string,
|
||||||
private _nav: Nav
|
nav: Nav
|
||||||
) {
|
) {
|
||||||
|
if (nav.parent) {
|
||||||
|
parentRouter = parentRouter.childRouter(nav);
|
||||||
|
}
|
||||||
super(elementRef, loader, parentRouter, nameAttr);
|
super(elementRef, loader, parentRouter, nameAttr);
|
||||||
|
|
||||||
|
this._nav = nav;
|
||||||
|
this._parent = parentRouter;
|
||||||
|
|
||||||
// register this router with Ionic's NavController
|
// register this router with Ionic's NavController
|
||||||
// Ionic's NavController will call this NavRouter's "stateChange"
|
// Ionic's NavController will call this NavRouter's "stateChange"
|
||||||
// method when the NavController has...changed its state
|
// method when the NavController has...changed its state
|
||||||
_nav.registerRouter(this);
|
nav.registerRouter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
stateChange(direction: string, viewCtrl: ViewController) {
|
stateChange(direction: string, viewCtrl: ViewController) {
|
||||||
@ -57,7 +65,7 @@ export class NavRouter extends RouterOutlet {
|
|||||||
|
|
||||||
this._lastUrl = url;
|
this._lastUrl = url;
|
||||||
|
|
||||||
this['_parentRouter'].navigateByInstruction(instruction);
|
this._parent.navigateByInstruction(instruction);
|
||||||
|
|
||||||
console.debug('NavRouter, stateChange, name:', viewCtrl.name, 'id:', viewCtrl.id, 'url:', url);
|
console.debug('NavRouter, stateChange, name:', viewCtrl.name, 'id:', viewCtrl.id, 'url:', url);
|
||||||
}
|
}
|
||||||
@ -68,7 +76,7 @@ export class NavRouter extends RouterOutlet {
|
|||||||
var previousInstruction = this['_currentInstruction'];
|
var previousInstruction = this['_currentInstruction'];
|
||||||
this['_currentInstruction'] = nextInstruction;
|
this['_currentInstruction'] = nextInstruction;
|
||||||
var componentType = nextInstruction.componentType;
|
var componentType = nextInstruction.componentType;
|
||||||
var childRouter = this['_parentRouter'].childRouter(componentType);
|
var childRouter = this._parent.childRouter(componentType);
|
||||||
|
|
||||||
// prevent double navigations to the same view
|
// prevent double navigations to the same view
|
||||||
let instruction = new ResolvedInstruction(nextInstruction, null, null);
|
let instruction = new ResolvedInstruction(nextInstruction, null, null);
|
||||||
@ -92,7 +100,7 @@ export class NavRouter extends RouterOutlet {
|
|||||||
|
|
||||||
getPathRecognizerByComponent(componentType) {
|
getPathRecognizerByComponent(componentType) {
|
||||||
// given a componentType, figure out the best PathRecognizer to use
|
// given a componentType, figure out the best PathRecognizer to use
|
||||||
let rules = this.parentRouter.registry['_rules'];
|
let rules = this._parent.registry['_rules'];
|
||||||
|
|
||||||
let pathRecognizer = null;
|
let pathRecognizer = null;
|
||||||
rules.forEach((rule) => {
|
rules.forEach((rule) => {
|
||||||
|
@ -13,9 +13,7 @@ import {Page, Config, IonicApp} from 'ionic-angular';
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class Login {
|
export class Login {
|
||||||
constructor(nav: NavController) {
|
constructor(private nav: NavController) {}
|
||||||
this.nav = nav;
|
|
||||||
}
|
|
||||||
|
|
||||||
goToAccount() {
|
goToAccount() {
|
||||||
this.nav.push(Account);
|
this.nav.push(Account);
|
||||||
@ -48,9 +46,9 @@ export class Login {
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class Account {
|
export class Account {
|
||||||
constructor(app: IonicApp, menu: MenuController) {
|
rootPage;
|
||||||
this.app = app;
|
|
||||||
this.menu = menu;
|
constructor(private app: IonicApp, private menu: MenuController) {
|
||||||
this.rootPage = Dashboard;
|
this.rootPage = Dashboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,10 +85,8 @@ export class Account {
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class Dashboard {
|
export class Dashboard {
|
||||||
constructor(app: IonicApp, nav: NavController) {
|
constructor(private app: IonicApp, private nav: NavController) {}
|
||||||
this.app = app;
|
|
||||||
this.nav = nav;
|
|
||||||
}
|
|
||||||
goToProfile() {
|
goToProfile() {
|
||||||
this.nav.push(Profile);
|
this.nav.push(Profile);
|
||||||
}
|
}
|
||||||
@ -118,10 +114,8 @@ export class Dashboard {
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class Profile {
|
export class Profile {
|
||||||
constructor(app: IonicApp, nav: NavController) {
|
constructor(private app: IonicApp, private nav: NavController) {}
|
||||||
this.app = app;
|
|
||||||
this.nav = nav;
|
|
||||||
}
|
|
||||||
goToDashboard() {
|
goToDashboard() {
|
||||||
this.nav.push(Dashboard);
|
this.nav.push(Dashboard);
|
||||||
}
|
}
|
||||||
@ -138,6 +132,8 @@ export class Profile {
|
|||||||
template: `<ion-nav id="root-nav" [root]="rootPage" swipeBackEnabled="false"></ion-nav>`
|
template: `<ion-nav id="root-nav" [root]="rootPage" swipeBackEnabled="false"></ion-nav>`
|
||||||
})
|
})
|
||||||
class E2EApp {
|
class E2EApp {
|
||||||
|
rootPage;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rootPage = Login;
|
this.rootPage = Login;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user