Skip to content

Commit b063566

Browse files
committed
fix(router): fix nested ion-nav router
1 parent 3df5989 commit b063566

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

ionic/components/nav/nav-router.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,28 @@ import {ViewController} from './view-controller';
1717
})
1818
export class NavRouter extends RouterOutlet {
1919
private _lastUrl: string;
20+
private _nav: Nav;
21+
private _parent: Router;
2022

2123
constructor(
2224
elementRef: ElementRef,
2325
loader: DynamicComponentLoader,
24-
private parentRouter: Router,
26+
parentRouter: Router,
2527
@Attribute('name') nameAttr: string,
26-
private _nav: Nav
28+
nav: Nav
2729
) {
30+
if (nav.parent) {
31+
parentRouter = parentRouter.childRouter(nav);
32+
}
2833
super(elementRef, loader, parentRouter, nameAttr);
2934

35+
this._nav = nav;
36+
this._parent = parentRouter;
37+
3038
// register this router with Ionic's NavController
3139
// Ionic's NavController will call this NavRouter's "stateChange"
3240
// method when the NavController has...changed its state
33-
_nav.registerRouter(this);
41+
nav.registerRouter(this);
3442
}
3543

3644
stateChange(direction: string, viewCtrl: ViewController) {
@@ -57,7 +65,7 @@ export class NavRouter extends RouterOutlet {
5765

5866
this._lastUrl = url;
5967

60-
this['_parentRouter'].navigateByInstruction(instruction);
68+
this._parent.navigateByInstruction(instruction);
6169

6270
console.debug('NavRouter, stateChange, name:', viewCtrl.name, 'id:', viewCtrl.id, 'url:', url);
6371
}
@@ -68,7 +76,7 @@ export class NavRouter extends RouterOutlet {
6876
var previousInstruction = this['_currentInstruction'];
6977
this['_currentInstruction'] = nextInstruction;
7078
var componentType = nextInstruction.componentType;
71-
var childRouter = this['_parentRouter'].childRouter(componentType);
79+
var childRouter = this._parent.childRouter(componentType);
7280

7381
// prevent double navigations to the same view
7482
let instruction = new ResolvedInstruction(nextInstruction, null, null);
@@ -92,7 +100,7 @@ export class NavRouter extends RouterOutlet {
92100

93101
getPathRecognizerByComponent(componentType) {
94102
// given a componentType, figure out the best PathRecognizer to use
95-
let rules = this.parentRouter.registry['_rules'];
103+
let rules = this._parent.registry['_rules'];
96104

97105
let pathRecognizer = null;
98106
rules.forEach((rule) => {

ionic/components/nav/test/nested/index.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {Page, Config, IonicApp} from 'ionic-angular';
1313
`
1414
})
1515
export class Login {
16-
constructor(nav: NavController) {
17-
this.nav = nav;
18-
}
16+
constructor(private nav: NavController) {}
1917

2018
goToAccount() {
2119
this.nav.push(Account);
@@ -48,9 +46,9 @@ export class Login {
4846
`
4947
})
5048
export class Account {
51-
constructor(app: IonicApp, menu: MenuController) {
52-
this.app = app;
53-
this.menu = menu;
49+
rootPage;
50+
51+
constructor(private app: IonicApp, private menu: MenuController) {
5452
this.rootPage = Dashboard;
5553
}
5654

@@ -87,10 +85,8 @@ export class Account {
8785
`
8886
})
8987
export class Dashboard {
90-
constructor(app: IonicApp, nav: NavController) {
91-
this.app = app;
92-
this.nav = nav;
93-
}
88+
constructor(private app: IonicApp, private nav: NavController) {}
89+
9490
goToProfile() {
9591
this.nav.push(Profile);
9692
}
@@ -118,10 +114,8 @@ export class Dashboard {
118114
`
119115
})
120116
export class Profile {
121-
constructor(app: IonicApp, nav: NavController) {
122-
this.app = app;
123-
this.nav = nav;
124-
}
117+
constructor(private app: IonicApp, private nav: NavController) {}
118+
125119
goToDashboard() {
126120
this.nav.push(Dashboard);
127121
}
@@ -138,6 +132,8 @@ export class Profile {
138132
template: `<ion-nav id="root-nav" [root]="rootPage" swipeBackEnabled="false"></ion-nav>`
139133
})
140134
class E2EApp {
135+
rootPage;
136+
141137
constructor() {
142138
this.rootPage = Login;
143139
}

0 commit comments

Comments
 (0)