Skip to content

Commit fbd4960

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committed
fix(router): handle nested primary p-r-o
1 parent 4aefd0c commit fbd4960

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

nativescript-angular/router/ns-location-strategy.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ export class Outlet {
5353
const lastState = this.peekState();
5454
return lastState && lastState.segmentGroup.toString() === stateUrl;
5555
}
56+
57+
// Search for frame that can go back.
58+
// Nested 'primary' outlets could result in Outlet with multiple navigatable frames.
59+
getFrameToBack(): Frame {
60+
let frame = this.frames[this.frames.length - 1];
61+
62+
if (!this.isNSEmptyOutlet) {
63+
for (let index = this.frames.length - 1; index >= 0; index--) {
64+
const currentFrame = this.frames[index];
65+
if (currentFrame.canGoBack()) {
66+
frame = currentFrame;
67+
break;
68+
}
69+
}
70+
71+
return frame;
72+
}
73+
}
5674
}
5775

5876
export interface NavigationOptions {
@@ -251,7 +269,7 @@ export class NSLocationStrategy extends LocationStrategy {
251269
const topmostFrame = this.frameService.getFrame();
252270
this.currentOutlet = this.getOutletByFrame(topmostFrame);
253271
}
254-
this.currentOutlet.frames[this.currentOutlet.frames.length - 1].goBack();
272+
this.currentOutlet.getFrameToBack().goBack();
255273
} else {
256274
// Nested navigation - just pop the state
257275
if (isLogEnabled()) {
@@ -448,6 +466,12 @@ export class NSLocationStrategy extends LocationStrategy {
448466
if (currentOutlet.containsFrame(frame) && !isEqualToCurrent) {
449467
this.callPopState(null, true, currentOutlet);
450468
}
469+
470+
if (!currentOutlet.isNSEmptyOutlet) {
471+
currentOutlet.frames = currentOutlet.frames.filter(currentFrame => currentFrame !== frame);
472+
return currentOutlet.frames.length;
473+
}
474+
451475
return !currentOutlet.containsFrame(frame);
452476
});
453477
}

nativescript-angular/router/page-router-outlet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
423423
if (modalNavigation > 0) { // Modal with 'primary' p-r-o
424424
outlet = this.locationStrategy.findOutletByModal(modalNavigation);
425425
} else {
426+
const pathByOutlets = this.locationStrategy.getPathByOutlets(topActivatedRoute);
426427
outlet = this.locationStrategy.findOutletByKey(outletKey);
428+
outlet = outlet || this.locationStrategy.findOutletByOutletPath(pathByOutlets);
427429
}
428430

429431
// Named lazy loaded outlet.

0 commit comments

Comments
 (0)