Skip to content
Permalink
Browse files

fix(angular): back button goes back to proper tab (#18005)

fixes #17278 
fixes #15216
  • Loading branch information...
liamdebeasi committed Apr 10, 2019
1 parent 0d17e05 commit 52e5a8d3e318d6415e170fa82c4ed8d9825897ab
@@ -101,7 +101,23 @@ export class StackController {
return Promise.resolve(false);
}
const view = views[views.length - deep - 1];
return this.navCtrl.navigateBack(view.url).then(() => true);
let url = view.url;

const viewSavedData = view.savedData;
if (viewSavedData) {
const primaryOutlet = viewSavedData.get('primary');
if (
primaryOutlet &&
primaryOutlet.route &&
primaryOutlet.route._routerState &&
primaryOutlet.route._routerState.snapshot &&
primaryOutlet.route._routerState.snapshot.url
) {
url = primaryOutlet.route._routerState.snapshot.url;
}
}

return this.navCtrl.navigateBack(url).then(() => true);
});
}

@@ -130,6 +130,25 @@ describe('tabs', () => {
expect(await tab.$('ion-back-button').isDisplayed()).toBe(false);
});
});

describe('enter url - /tabs/contact/one', () => {
beforeEach(async () => {
await browser.get('/tabs/contact/one');
});

it('should return to correct tab after going to page in different outlet', async () => {
const tab = await getSelectedTab();
await tab.$('#goto-nested-page1').click();

await testStack('app-nested-outlet ion-router-outlet', ['app-nested-outlet-page']);

const nestedOutlet = await element(by.css('app-nested-outlet'));
const backButton = await nestedOutlet.$('ion-back-button');
await backButton.click();

await testTabTitle('Tab 2 - Page 1');
});
})
});

async function testState(count: number, tab: string) {
@@ -1,5 +1,8 @@
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>
NESTED OUTLET
</ion-title>
@@ -9,5 +9,6 @@ <h1>Welcome to Tab 2</h1>
<p>
<ion-button routerLink="/tabs/account" id="goto-tab1-page1">Go to Tab 1 - Page 1</ion-button>
<ion-button routerLink="/tabs/account/nested/12" id="goto-tab1-page2">Go to Tab 1 - Page 2</ion-button>
<ion-button routerLink="/nested-outlet/page" id="goto-nested-page1">Go to nested</ion-button>
</p>
</ion-content>

0 comments on commit 52e5a8d

Please sign in to comment.
You can’t perform that action at this time.