Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions nativescript-angular/router/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@ export class NSLocationStrategy extends LocationStrategy {
this.currentUrlTree = urlSerializer.parse(url);
const urlTreeRoot = this.currentUrlTree.root;

// Handle case where the user declares a component at path "/".
// The url serializer doesn't parse this url as having a primary outlet.
if (!Object.keys(urlTreeRoot.children).length) {
// Handle case where the user declares a component at path "/".
// The url serializer doesn't parse this url as having a primary outlet.
const rootOutlet = this.createOutlet("primary", null, null);
this.currentOutlet = rootOutlet;
const segmentGroup = this.currentUrlTree && this.currentUrlTree.root;
const outletKey = this.getSegmentGroupFullPath(segmentGroup) + "primary";
const outlet = this.findOutletByKey(outletKey);

if (outlet && this.updateStates(outlet, segmentGroup)) {
this.currentOutlet = outlet; // If states updated
} else if (!outlet) {
const rootOutlet = this.createOutlet("primary", segmentGroup, null);
this.currentOutlet = rootOutlet;
}

this.currentOutlet.peekState().isRootSegmentGroup = true;
return;
}

Expand Down Expand Up @@ -543,21 +553,12 @@ export class NSLocationStrategy extends LocationStrategy {
}

private createOutlet(outletKey: string, segmentGroup: any, parent: Outlet, modalNavigation?: number): Outlet {
let isRootSegmentGroup: boolean = false;

if (!segmentGroup) {
// Handle case where the user declares a component at path "/".
// The url serializer doesn't parse this url as having a primary outlet.
segmentGroup = this.currentUrlTree && this.currentUrlTree.root;
isRootSegmentGroup = true;
}

const pathByOutlets = this.getPathByOutlets(segmentGroup);
const newOutlet = new Outlet(outletKey, pathByOutlets, modalNavigation);

const locationState: LocationState = {
segmentGroup: segmentGroup,
isRootSegmentGroup: isRootSegmentGroup,
isRootSegmentGroup: false,
isPageNavigation: true // It is a new OutletNode.
};

Expand Down
1 change: 1 addition & 0 deletions tests/app/tests/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class FakeFrame extends View implements Frame {
actionBarVisibility: "always" | "auto" | "never";
transition: any;
_currentEntry: any;
_executingEntry: any;

canGoBack(): boolean {
return true;
Expand Down