Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.

Commit 980126d

Browse files
authored
Merge pull request #210 from UltimateSoftware/master
fix(history): fixes Back Button issue (#122). Issue occurs when switc…
2 parents 55b0ada + 7ffa039 commit 980126d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

js/angular/service/history.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
282282
var viewIds = Object.keys(viewHistory.views);
283283
viewIds.forEach(function(viewId) {
284284
var view = viewHistory.views[viewId];
285-
if ( view.backViewId === switchToView.viewId ) {
285+
if ((view.backViewId === switchToView.viewId) && (view.historyId !== switchToView.historyId)) {
286286
view.backViewId = null;
287287
}
288288
});

test/unit/angular/service/history.unit.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,4 +1547,57 @@ describe('Ionic History', function() {
15471547

15481548
}));
15491549

1550+
it('should not remove backView references from Views in the same history stack', inject(function($state, $ionicHistory) {
1551+
1552+
var tab1Container = {};
1553+
var tab2Container = {};
1554+
ionicHistory.registerHistory(tab1Container);
1555+
ionicHistory.registerHistory(tab2Container);
1556+
1557+
// register tab1, view1
1558+
$state.go('tabs.tab1view1');
1559+
rootScope.$apply();
1560+
var tab1view1Reg = ionicHistory.register(tab1Container, false);
1561+
1562+
// register tab2, view1
1563+
$state.go('tabs.tab2view1');
1564+
rootScope.$apply();
1565+
var tab2view1Reg = ionicHistory.register(tab2Container, false);
1566+
1567+
// register tab2, view2
1568+
$state.go('tabs.tab2view2');
1569+
rootScope.$apply();
1570+
var tab2view2Reg = ionicHistory.register(tab2Container, false);
1571+
var tab2view2 = ionicHistory.getViewById(tab2view2Reg.viewId);
1572+
expect(tab2view2.backViewId).toEqual(tab2view1Reg.viewId);
1573+
1574+
// go back to tab2, view1
1575+
$state.go('tabs.tab2view1');
1576+
rootScope.$apply();
1577+
tab2view1Reg = ionicHistory.register(tab2Container, false);
1578+
1579+
// register tab1, view1
1580+
$state.go('tabs.tab1view1');
1581+
rootScope.$apply();
1582+
tab1view1Reg = ionicHistory.register(tab1Container, false);
1583+
1584+
// go to tab1, view 2
1585+
// register tab1, view2
1586+
$state.go('tabs.tab1view2');
1587+
rootScope.$apply();
1588+
var tab1view2Reg = ionicHistory.register(tab1Container, false);
1589+
currentView = ionicHistory.currentView();
1590+
expect(currentView.backViewId).toEqual(tab1view1Reg.viewId);
1591+
1592+
// register tab2, view1
1593+
$state.go('tabs.tab2view1');
1594+
rootScope.$apply();
1595+
tab2view1Reg = ionicHistory.register(tab2Container, false);
1596+
currentView = ionicHistory.currentView();
1597+
expect(currentView.backViewId).toEqual(tab1view2Reg.viewId);
1598+
expect(tab2view2.historyId).toEqual(currentView.historyId);
1599+
expect(tab2view2.backViewId).toEqual(currentView.viewId);
1600+
1601+
}));
1602+
15501603
});

0 commit comments

Comments
 (0)