Skip to content

Commit f755991

Browse files
ADjenkovSvetoslavTsenov
authored andcommitted
fix(location-strategy): crash on going back to TabView with nested outlets (#1582)
1 parent 19040fb commit f755991

File tree

8 files changed

+79
-1
lines changed

8 files changed

+79
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<ActionBar class="action-bar">
2+
<Label class="action-bar-title" text="About Component"></Label>
3+
</ActionBar>
4+
5+
<GridLayout rows="auto, *">
6+
<Button text="Back(ActivatedRoute)" automationText="Back(ActivatedRoute)" (tap)="backActivatedRoute()"></Button>
7+
</GridLayout>
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, ViewContainerRef } from "@angular/core";
2+
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
3+
import { RouterExtensions } from "nativescript-angular/router";
4+
import { ActivatedRoute } from "@angular/router";
5+
6+
@Component({
7+
moduleId: module.id,
8+
selector: "about-page",
9+
templateUrl: "./about.component.html"
10+
})
11+
export class AboutComponent {
12+
constructor(
13+
private modal: ModalDialogService,
14+
private vcRef: ViewContainerRef,
15+
private activeRoute: ActivatedRoute,
16+
private routerExtension: RouterExtensions) { }
17+
18+
ngOnInit() {
19+
}
20+
21+
backActivatedRoute() {
22+
this.routerExtension.back({ relativeTo: this.activeRoute });
23+
}
24+
}

Diff for: e2e/nested-router-tab-view/app/app.routing.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TeamDetailComponent } from "./team/team-detail.component";
99
import { LoginComponent } from "./login/login.component";
1010
import { TabsComponent } from "./tabs/tabs.component";
1111
import { HomeComponent } from "./home/home.component";
12+
import { AboutComponent } from "./about/about.component";
1213

1314
import { ModalComponent } from "./modal/modal.component";
1415
import { NestedModalComponent } from "./modal-nested/modal-nested.component";
@@ -54,7 +55,8 @@ const routes: Routes = [
5455
{ path: "teams", component: TeamsComponent, outlet: "teamTab" },
5556
{ path: "team/:id", component: TeamDetailComponent, outlet: "teamTab" },
5657
]
57-
}
58+
},
59+
{ path: "about", component: AboutComponent }
5860
];
5961

6062
@NgModule({

Diff for: e2e/nested-router-tab-view/app/shared.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NativeScriptRouterModule } from "nativescript-angular/router";
77
import { DataService } from "./data.service";
88

99
import { HomeComponent } from "./home/home.component";
10+
import { AboutComponent } from "./about/about.component";
1011
import { PlayerComponent } from "./player/players.component";
1112
import { PlayerDetailComponent } from "./player/player-detail.component";
1213
import { TeamsComponent } from "./team/teams.component";
@@ -19,13 +20,15 @@ import { TeamDetailComponent } from "./team/team-detail.component";
1920
],
2021
declarations: [
2122
HomeComponent,
23+
AboutComponent,
2224
PlayerComponent,
2325
PlayerDetailComponent,
2426
TeamsComponent,
2527
TeamDetailComponent
2628
],
2729
exports: [
2830
HomeComponent,
31+
AboutComponent,
2932
PlayerComponent,
3033
PlayerDetailComponent,
3134
TeamsComponent,

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

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<StackLayout>
44
<GridLayout rows="auto,*">
55
<WrapLayout row="0">
6+
<Button text="Go To About Page" [nsRouterLink]="['../about']"></Button>
67
<Button text="Back()" (tap)="back()"></Button>
78
<Button text="CanGoBack(ActivatedRoute)" (tap)="canGoBack()"></Button>
89
<Button text="Back(ActivatedRoute)" (tap)="backActivatedRoute()"></Button>

Diff for: e2e/nested-router-tab-view/e2e/home-tabs.e2e-spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ describe("home-tabs:", () => {
4242
await screen.loadedTeamList();
4343
});
4444

45+
it("should navigate to Tabs then to About forward", async () => {
46+
if (driver.isIOS) {
47+
await screen.navigateToTabsPage();
48+
await screen.loadedTabs();
49+
await screen.loadedPlayersList();
50+
await screen.navigateToAboutPage();
51+
await screen.loadedAbout();
52+
}
53+
});
54+
55+
it("should go back to Tabs and then back to Home", async () => {
56+
if (driver.isIOS) {
57+
await backActivatedRoute(driver);
58+
await screen.loadedTabs();
59+
await screen.loadedPlayersList();
60+
await backActivatedRoute(driver);
61+
await screen.loadedHome();
62+
await screen.loadedPlayersList();
63+
await screen.loadedTeamList();
64+
}
65+
});
66+
4567
it("should navigate to Tabs without Players/Teams navigation", async () => {
4668
await screen.navigateToTabsPage();
4769
await screen.loadedTabs();

Diff for: e2e/nested-router-tab-view/e2e/screen.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AppiumDriver, SearchOptions } from "nativescript-dev-appium";
22
import { assert } from "chai";
33

44
const home = "Home Component";
5+
const about = "About Component";
56
const login = "Login Component";
67
const tabs = "Tabs Component";
78

@@ -16,6 +17,7 @@ const gotoNextTeam = "next team";
1617
const gotoTeams = "teams";
1718

1819
const gotoHomePage = "Go To Home Page";
20+
const gotoAboutPage = "Go To About Page";
1921
const gotoTabsPage = "Go To Tabs Page";
2022
const confirmDialog = "Ok";
2123

@@ -65,6 +67,12 @@ export class Screen {
6567
console.log(home + " loaded!");
6668
}
6769

70+
loadedAbout= async () => {
71+
const lblAbout = await this._driver.findElementByAutomationText(about);
72+
assert.isTrue(await lblAbout.isDisplayed());
73+
console.log(home + " loaded!");
74+
}
75+
6876
loadedTabs = async () => {
6977
const lblTabs = await this._driver.findElementByAutomationText(tabs);
7078
assert.isTrue(await lblTabs.isDisplayed());
@@ -113,6 +121,11 @@ export class Screen {
113121
await btnNavToHomePage.tap();
114122
}
115123

124+
navigateToAboutPage = async () => {
125+
const btnNavToAboutPage = await this._driver.findElementByAutomationText(gotoAboutPage);
126+
await btnNavToAboutPage.tap();
127+
}
128+
116129
navigateToPlayer = async (player: string) => {
117130
const btnNavPlayerPage = await this._driver.findElementByAutomationText(player);
118131
await btnNavPlayerPage.tap();

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

+6
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ export class NSLocationStrategy extends LocationStrategy {
527527
if (!lastState || !equalStateUrls) {
528528
outlet.states.push(locationState);
529529

530+
// Update last state segmentGroup of parent Outlet.
530531
if (this._modalNavigationDepth === 0 && !outlet.showingModal) {
531532
this.updateParentsStates(outlet, currentSegmentGroup.parent);
532533
}
@@ -566,6 +567,11 @@ export class NSLocationStrategy extends LocationStrategy {
566567
newOutlet.parent = parent;
567568
this.outlets.push(newOutlet);
568569

570+
// Update last state segmentGroup of parent Outlet.
571+
if (this._modalNavigationDepth === 0 && !newOutlet.showingModal) {
572+
this.updateParentsStates(newOutlet, segmentGroup.parent);
573+
}
574+
569575
return newOutlet;
570576
}
571577

0 commit comments

Comments
 (0)