Skip to content

Commit d9ffb83

Browse files
authored
fix(location-strategy): crash when going back on nested named lazy loaded module (#1618)
1 parent 1b1226a commit d9ffb83

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

Diff for: nativescript-angular/router/ns-location-strategy.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export class Outlet {
1616
// in module that lazy loads children (loadChildren) and has outlet name.
1717
outletKeys: Array<string>;
1818

19+
// More than one frame available when using NSEmptyOutletComponent component
20+
// in module that lazy loads children (loadChildren) and has outlet name.
21+
frames: Array<Frame> = [];
1922
// The url path to the Outlet.
2023
// E.G: the path to Outlet3 that is nested Outlet1(home)->Outlet2(nested1)->Outlet3(nested2)
2124
// will be 'home/nested1'
2225
path: string;
2326
pathByOutlets: string;
2427
states: Array<LocationState> = [];
25-
frame: Frame;
2628

2729
// Used in reuse-strategy by its children to determine if they should be detached too.
2830
shouldDetach: boolean = true;
@@ -35,6 +37,10 @@ export class Outlet {
3537
this.path = path;
3638
}
3739

40+
containsFrame(frame: Frame): boolean {
41+
return this.frames.indexOf(frame) > -1;
42+
}
43+
3844
peekState(): LocationState {
3945
if (this.states.length > 0) {
4046
return this.states[this.states.length - 1];
@@ -244,7 +250,7 @@ export class NSLocationStrategy extends LocationStrategy {
244250
const topmostFrame = this.frameService.getFrame();
245251
this.currentOutlet = this.getOutletByFrame(topmostFrame);
246252
}
247-
this.currentOutlet.frame.goBack();
253+
this.currentOutlet.frames[this.currentOutlet.frames.length - 1].goBack();
248254
} else {
249255
// Nested navigation - just pop the state
250256
if (isLogEnabled()) {
@@ -423,7 +429,9 @@ export class NSLocationStrategy extends LocationStrategy {
423429
}
424430

425431
updateOutletFrame(outlet: Outlet, frame: Frame) {
426-
outlet.frame = frame;
432+
if (!outlet.containsFrame(frame)) {
433+
outlet.frames.push(frame);
434+
}
427435
this.currentOutlet = outlet;
428436
}
429437

@@ -436,10 +444,10 @@ export class NSLocationStrategy extends LocationStrategy {
436444
}
437445

438446
// Remove outlet from the url tree.
439-
if (currentOutlet.frame === frame && !isEqualToCurrent) {
447+
if (currentOutlet.containsFrame(frame) && !isEqualToCurrent) {
440448
this.callPopState(null, true, currentOutlet);
441449
}
442-
return currentOutlet.frame !== frame;
450+
return !currentOutlet.containsFrame(frame);
443451
});
444452
}
445453

@@ -528,7 +536,7 @@ export class NSLocationStrategy extends LocationStrategy {
528536
for (let index = 0; index < this.outlets.length; index++) {
529537
const currentOutlet = this.outlets[index];
530538

531-
if (currentOutlet.frame === frame) {
539+
if (currentOutlet.containsFrame(frame)) {
532540
outlet = currentOutlet;
533541
break;
534542
}

Diff for: nativescript-angular/router/page-router-outlet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
391391
let outletKeyForRoute = this.locationStrategy.getRouteFullPath(nodeToMark);
392392
let outlet = this.locationStrategy.findOutletByKey(outletKeyForRoute);
393393

394-
if (outlet && outlet.frame) {
394+
if (outlet && outlet.frames.length) {
395395
nodeToMark[pageRouterActivatedSymbol] = true;
396396
if (isLogEnabled()) {
397397
log("Activated route marked as page: " + routeToString(nodeToMark));

Diff for: tests/app/tests/modal-dialog.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("modal-dialog", () => {
9797

9898
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
9999
parentView = parentView.page && parentView.page.frame;
100-
outlet.frame = parentView;
100+
outlet.frames.push(parentView);
101101
locStrategy._getOutlets().push(outlet);
102102

103103
locStrategy.pushState(null, "test", "/test", null);
@@ -119,7 +119,7 @@ describe("modal-dialog", () => {
119119

120120
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
121121
parentView = parentView.page && parentView.page.frame;
122-
outlet.frame = parentView;
122+
outlet.frames.push(parentView);
123123
locStrategy._getOutlets().push(outlet);
124124

125125
locStrategy.pushState(null, "test", "/test", null);

Diff for: tests/app/tests/ns-location-strategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function simulatePageNavigation(strategy: NSLocationStrategy, url: string, frame
143143
strategy.pushState(null, null, url, null);
144144

145145
const outlet: Outlet = strategy.findOutletByOutletPath(outletName);
146-
outlet.frame = frame;
146+
outlet.frames.push(frame);
147147
strategy._beginPageNavigation(frame);
148148
}
149149

0 commit comments

Comments
 (0)