Skip to content

Commit 452cb8f

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committed
chore: repsect PR comments
1 parent 37f9aa4 commit 452cb8f

File tree

5 files changed

+77
-64
lines changed

5 files changed

+77
-64
lines changed

Diff for: e2e/nested-router-tab-view/app/login/login.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
<StackLayout>
66
<!-- <Button text="Go To Home Page" [nsRouterLink]="['/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button> -->
7-
<Button text="Go To Home Page" [nsRouterLink]="['/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
8-
<Button text="Go To Lazy Home Page" [nsRouterLink]="['/home-lazy/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
7+
<Button text="Go To Home Page" [nsRouterLink]="['../home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
8+
<Button text="Go To Lazy Home Page" [nsRouterLink]="['../home-lazy/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
99
</StackLayout>

Diff for: nativescript-angular/directives/dialogs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class ModalDialogService {
132132
doneCallback.apply(undefined, args);
133133
if (componentView) {
134134
componentView.closeModal();
135-
this.location._finishCloseModalNavigation();
135+
this.location._closeModalNavigation();
136136
detachedLoaderRef.instance.detectChanges();
137137
detachedLoaderRef.destroy();
138138
}

Diff for: nativescript-angular/router/ns-empty-outlet.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Page } from "tns-core-modules/ui/page";
44
// tslint:disable-next-line:component-selector
55
selector: "ns-empty-outlet",
66
moduleId: module.id,
7-
template: "<page-router-outlet isNSEmptyOutlet='true'></page-router-outlet>"
7+
template: "<page-router-outlet isEmptyOutlet='true'></page-router-outlet>"
88
})
99
export class NSEmptyOutletComponent {
1010
constructor(private page: Page) {

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

+66-56
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ export class Outlet {
1111
modalNavigationDepth: number;
1212
parent: Outlet;
1313
isPageNavigationBack: boolean;
14+
15+
// More than one key available when using NSEmptyOutletComponent component
16+
// in module that lazy loads children (loadChildren) and has outlet name.
1417
outletKeys: Array<string>;
1518
pathByOutlets: string;
16-
statesByOutlet: Array<LocationState> = [];
19+
states: Array<LocationState> = [];
1720
frame: Frame;
1821

1922
// Used in reuse-strategy by its children to determine if they should be detached too.
@@ -27,13 +30,13 @@ export class Outlet {
2730
}
2831

2932
peekState(): LocationState {
30-
if (this.statesByOutlet.length > 0) {
31-
return this.statesByOutlet[this.statesByOutlet.length - 1];
33+
if (this.states.length > 0) {
34+
return this.states[this.states.length - 1];
3235
}
3336
return null;
3437
}
3538

36-
containsLastState(stateUrl: string): boolean {
39+
containsTopState(stateUrl: string): boolean {
3740
const lastState = this.peekState();
3841
return lastState && lastState.segmentGroup.toString() === stateUrl;
3942
}
@@ -92,7 +95,6 @@ export class NSLocationStrategy extends LocationStrategy {
9295
if (state.isRootSegmentGroup) {
9396
tree.root = state.segmentGroup;
9497
} else if (changedOutlet) {
95-
// tslint:disable-next-line:max-line-length
9698
this.updateSegmentGroup(tree.root, changedOutlet, state.segmentGroup);
9799
}
98100

@@ -129,49 +131,49 @@ export class NSLocationStrategy extends LocationStrategy {
129131
// The url serializer doesn't parse this url as having a primary outlet.
130132
const rootOutlet = this.createOutlet("primary", null, null);
131133
this.currentOutlet = rootOutlet;
132-
} else {
133-
const queue = [];
134-
queue.push(urlTreeRoot);
135-
let currentTree = queue.shift();
136-
137-
while (currentTree) {
138-
Object.keys(currentTree.children).forEach(outletName => {
139-
const currentSegmentGroup = currentTree.children[outletName];
140-
currentSegmentGroup.outlet = outletName;
141-
currentSegmentGroup.root = urlTreeRoot;
142-
143-
let outletKey = this.getSegmentGroupFullPath(currentTree) + outletName;
144-
let outlet = this.findOutletByKey(outletKey);
145-
const parentOutletName = currentTree.outlet || "";
146-
const parentOutletKey = this.getSegmentGroupFullPath(currentTree.parent) + parentOutletName;
147-
const parentOutlet = this.findOutletByKey(parentOutletKey);
148-
149-
const containsLastState = outlet && outlet.containsLastState(currentSegmentGroup.toString());
150-
if (!outlet) {
151-
// tslint:disable-next-line:max-line-length
152-
outlet = this.createOutlet(outletKey, currentSegmentGroup, parentOutlet, this._modalNavigationDepth);
153-
this.currentOutlet = outlet;
154-
} else if (this._modalNavigationDepth > 0 && outlet.showingModal && !containsLastState) {
155-
// Navigation inside modal view.
156-
this.upsertModalOutlet(outlet, currentSegmentGroup);
157-
} else {
158-
outlet.parent = parentOutlet;
134+
return;
135+
}
136+
137+
const queue = [];
138+
let currentTree = <any>urlTreeRoot;
139+
140+
while (currentTree) {
141+
Object.keys(currentTree.children).forEach(outletName => {
142+
const currentSegmentGroup = currentTree.children[outletName];
143+
currentSegmentGroup.outlet = outletName;
144+
currentSegmentGroup.root = urlTreeRoot;
145+
146+
let outletKey = this.getSegmentGroupFullPath(currentTree) + outletName;
147+
let outlet = this.findOutletByKey(outletKey);
148+
const parentOutletName = currentTree.outlet || "";
149+
const parentOutletKey = this.getSegmentGroupFullPath(currentTree.parent) + parentOutletName;
150+
const parentOutlet = this.findOutletByKey(parentOutletKey);
159151

160-
if (this.updateStates(outlet, currentSegmentGroup)) {
161-
this.currentOutlet = outlet; // If states updated
162-
}
152+
const containsLastState = outlet && outlet.containsTopState(currentSegmentGroup.toString());
153+
if (!outlet) {
154+
// tslint:disable-next-line:max-line-length
155+
outlet = this.createOutlet(outletKey, currentSegmentGroup, parentOutlet, this._modalNavigationDepth);
156+
this.currentOutlet = outlet;
157+
} else if (this._modalNavigationDepth > 0 && outlet.showingModal && !containsLastState) {
158+
// Navigation inside modal view.
159+
this.upsertModalOutlet(outlet, currentSegmentGroup);
160+
} else {
161+
outlet.parent = parentOutlet;
162+
163+
if (this.updateStates(outlet, currentSegmentGroup)) {
164+
this.currentOutlet = outlet; // If states updated
163165
}
166+
}
164167

165-
queue.push(currentTree.children[outletName]);
166-
});
168+
queue.push(currentSegmentGroup);
169+
});
167170

168-
currentTree = queue.shift();
169-
}
171+
currentTree = queue.shift();
170172
}
171173
}
172174

173175
replaceState(state: any, title: string, url: string, queryParams: string): void {
174-
const states = this.currentOutlet && this.currentOutlet.statesByOutlet;
176+
const states = this.currentOutlet && this.currentOutlet.states;
175177

176178
if (states && states.length > 0) {
177179
if (isLogEnabled()) {
@@ -195,7 +197,7 @@ export class NSLocationStrategy extends LocationStrategy {
195197
this.currentOutlet = outlet || this.currentOutlet;
196198

197199
if (this.currentOutlet.isPageNavigationBack) {
198-
const states = this.currentOutlet.statesByOutlet;
200+
const states = this.currentOutlet.states;
199201
// We are navigating to the previous page
200202
// clear the stack until we get to a page navigation state
201203
let state = states.pop();
@@ -231,14 +233,14 @@ export class NSLocationStrategy extends LocationStrategy {
231233
" state is not page - just pop");
232234
}
233235

234-
this.callPopState(this.currentOutlet.statesByOutlet.pop(), true);
236+
this.callPopState(this.currentOutlet.states.pop(), true);
235237
}
236238
}
237239
}
238240

239241
canGoBack(outlet?: Outlet) {
240242
outlet = outlet || this.currentOutlet;
241-
return outlet.statesByOutlet.length > 1;
243+
return outlet.states.length > 1;
242244
}
243245

244246
onPopState(fn: (_: any) => any): void {
@@ -279,7 +281,7 @@ export class NSLocationStrategy extends LocationStrategy {
279281
let result = [];
280282

281283
this.outlets.forEach(outlet => {
282-
const outletStates = outlet.statesByOutlet;
284+
const outletStates = outlet.states;
283285
const outletLog = outletStates
284286
// tslint:disable-next-line:max-line-length
285287
.map((v, i) => `${outlet.outletKeys}.${i}.[${v.isPageNavigation ? "PAGE" : "INTERNAL"}].[${outlet.modalNavigationDepth ? "MODAL" : "BASE"}] "${v.segmentGroup.toString()}"`)
@@ -336,9 +338,9 @@ export class NSLocationStrategy extends LocationStrategy {
336338
this._modalNavigationDepth++;
337339
}
338340

339-
public _finishCloseModalNavigation() {
341+
public _closeModalNavigation() {
340342
if (isLogEnabled()) {
341-
routerLog("NSLocationStrategy.finishCloseModalNavigation()");
343+
routerLog("NSLocationStrategy.closeModalNavigation()");
342344
}
343345
this._modalNavigationDepth--;
344346

@@ -365,7 +367,7 @@ export class NSLocationStrategy extends LocationStrategy {
365367
if (isLogEnabled()) {
366368
routerLog("NSLocationStrategy._beginPageNavigation clearing states history");
367369
}
368-
this.currentOutlet.statesByOutlet = [lastState];
370+
this.currentOutlet.states = [lastState];
369371
}
370372

371373
this._currentNavigationOptions = undefined;
@@ -412,7 +414,13 @@ export class NSLocationStrategy extends LocationStrategy {
412414

413415
while (segmentGroup) {
414416
const url = segmentGroup.toString();
415-
fullPath = fullPath ? (url ? url + "/" : url) + fullPath : url;
417+
418+
if (fullPath) {
419+
fullPath = (url ? url + "/" : "") + fullPath;
420+
} else {
421+
fullPath = url;
422+
}
423+
416424
segmentGroup = segmentGroup.parent;
417425
}
418426

@@ -496,9 +504,9 @@ export class NSLocationStrategy extends LocationStrategy {
496504
}
497505

498506
private updateStates(outlet: Outlet, currentSegmentGroup: UrlSegmentGroup): boolean {
499-
const isNewPage = outlet.statesByOutlet.length === 0;
500-
const lastState = outlet.statesByOutlet[outlet.statesByOutlet.length - 1];
501-
const equalStateUrls = outlet.containsLastState(currentSegmentGroup.toString());
507+
const isNewPage = outlet.states.length === 0;
508+
const lastState = outlet.states[outlet.states.length - 1];
509+
const equalStateUrls = outlet.containsTopState(currentSegmentGroup.toString());
502510

503511
const locationState: LocationState = {
504512
segmentGroup: currentSegmentGroup,
@@ -507,7 +515,7 @@ export class NSLocationStrategy extends LocationStrategy {
507515
};
508516

509517
if (!lastState || !equalStateUrls) {
510-
outlet.statesByOutlet.push(locationState);
518+
outlet.states.push(locationState);
511519

512520
if (this._modalNavigationDepth === 0 && !outlet.showingModal) {
513521
this.updateParentsStates(outlet, currentSegmentGroup.parent);
@@ -553,7 +561,7 @@ export class NSLocationStrategy extends LocationStrategy {
553561
isPageNavigation: true // It is a new OutletNode.
554562
};
555563

556-
newOutlet.statesByOutlet = [locationState];
564+
newOutlet.states = [locationState];
557565
newOutlet.parent = parent;
558566
this.outlets.push(newOutlet);
559567

@@ -571,6 +579,9 @@ export class NSLocationStrategy extends LocationStrategy {
571579
if (childrenCount && segmentGroup.children[currentPath]) {
572580
segmentGroup = segmentGroup.children[currentPath];
573581
} else {
582+
// If no child outlet found with the given name - forget about all previously found outlets.
583+
// example: seaching for 'primary-second-primary' shouldn't return 'primary-second'
584+
// if no 'primary' child available on 'second'.
574585
segmentGroup = null;
575586
break;
576587
}
@@ -580,10 +591,9 @@ export class NSLocationStrategy extends LocationStrategy {
580591
}
581592

582593
// Traversal and replacement of segmentGroup.
583-
private updateSegmentGroup(rootNode, oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup) {
594+
private updateSegmentGroup(rootNode: any, oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup) {
584595
const queue = [];
585-
queue.push(rootNode);
586-
let currentTree = queue.shift();
596+
let currentTree = rootNode;
587597

588598
while (currentTree) {
589599
Object.keys(currentTree.children).forEach(outletName => {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
109109

110110
private outlet: Outlet;
111111
private name: string;
112-
private isNSEmptyOutlet: boolean;
112+
private isEmptyOutlet: boolean;
113113
private viewUtil: ViewUtil;
114114
private frame: Frame;
115115

@@ -150,7 +150,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
150150
private parentContexts: ChildrenOutletContexts,
151151
private location: ViewContainerRef,
152152
@Attribute("name") name: string,
153-
@Attribute("isNSEmptyOutlet") isNSEmptyOutlet: boolean,
153+
@Attribute("isEmptyOutlet") isEmptyOutlet: boolean,
154154
private locationStrategy: NSLocationStrategy,
155155
private componentFactoryResolver: ComponentFactoryResolver,
156156
private resolver: ComponentFactoryResolver,
@@ -160,7 +160,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
160160
private routeReuseStrategy: NSRouteReuseStrategy,
161161
elRef: ElementRef
162162
) {
163-
this.isNSEmptyOutlet = isNSEmptyOutlet;
163+
this.isEmptyOutlet = isEmptyOutlet;
164164
this.frame = elRef.nativeElement;
165165
if (isLogEnabled()) {
166166
log(`PageRouterOutlet.constructor frame: ${this.frame}`);
@@ -360,6 +360,9 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
360360
});
361361
}
362362

363+
// Find and mark the top activated route as an activated one.
364+
// In ns-location-strategy we are reusing components only if their corresponing routes
365+
// are marked as activated from this method.
363366
private markActivatedRoute(activatedRoute: ActivatedRoute) {
364367
const queue = [];
365368
queue.push(activatedRoute.snapshot);
@@ -409,7 +412,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
409412
}
410413

411414
// Named lazy loaded outlet.
412-
if (!outlet && this.isNSEmptyOutlet) {
415+
if (!outlet && this.isEmptyOutlet) {
413416
const parentOutletKey = this.locationStrategy.getRouteFullPath(topActivatedRoute.parent);
414417
outlet = this.locationStrategy.findOutletByKey(parentOutletKey);
415418

0 commit comments

Comments
 (0)