From 646d736d0767ca87d7c87dc54d6ea3ec164c3787 Mon Sep 17 00:00:00 2001 From: AndreasGassmann Date: Wed, 3 May 2017 19:15:23 +0200 Subject: [PATCH] fix(navcontrollerbase): popToRoot should not remove root view --- src/navigation/nav-controller-base.ts | 2 +- src/navigation/test/nav-controller.spec.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/navigation/nav-controller-base.ts b/src/navigation/nav-controller-base.ts index 03c1f94a276..48d07affb9f 100644 --- a/src/navigation/nav-controller-base.ts +++ b/src/navigation/nav-controller-base.ts @@ -331,7 +331,7 @@ export class NavControllerBase extends Ion implements NavController { if (ti.removeCount < 0) { ti.removeCount = (viewsLength - ti.removeStart); } - ti.leavingRequiresTransition = ((ti.removeStart + ti.removeCount) === viewsLength); + ti.leavingRequiresTransition = (ti.removeCount > 0) && ((ti.removeStart + ti.removeCount) === viewsLength); } if (ti.insertViews) { diff --git a/src/navigation/test/nav-controller.spec.ts b/src/navigation/test/nav-controller.spec.ts index 4feaacdbbcb..59f897c5f1c 100644 --- a/src/navigation/test/nav-controller.spec.ts +++ b/src/navigation/test/nav-controller.spec.ts @@ -622,6 +622,25 @@ describe('NavController', () => { }); }, 10000); + it('should not pop first view if it\'s the only view', (done: Function) => { + let view1 = mockView(MockView1); + mockViews(nav, [view1]); + + nav.popToRoot(null, trnsDone).then(() => { + let hasCompleted = true; + let requiresTransition = false; + expect(trnsDone).toHaveBeenCalledWith( + hasCompleted, requiresTransition, undefined, undefined, undefined + ); + expect(nav.length()).toEqual(1); + expect(nav.getByIndex(0).component).toEqual(MockView1); + done(); + }).catch((err: Error) => { + fail(err); + done(err); + }); + }, 10000); + }); describe('remove', () => {