Skip to content
This repository was archived by the owner on Sep 20, 2020. It is now read-only.

Commit 9c4be9f

Browse files
fix(previous): Allow previous state to track states without URLs.
Closes #175
1 parent b53c1ef commit 9c4be9f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/previous.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ angular.module('ct.ui.router.extras.previous', [ 'ct.ui.router.extras.core', 'ct
88
// Check if the fromState is navigable before tracking it.
99
// Root state doesn't get decorated with $$state(). Doh.
1010
var fromState = from.state && from.state.$$state && from.state.$$state();
11-
if (fromState && fromState.navigable) {
11+
if (fromState) {
1212
lastPrevious = previous;
1313
previous = $transition$.from;
14-
} else {
14+
1515
$transition$.promise.then(commit)['catch'](revert);
1616
function commit() { lastPrevious = null; }
1717
function revert() { previous = lastPrevious; }

test/previousSpec.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function getPreviousMockStates() {
88
states.push({ name: 'aside2', url: '/aside2'});
99

1010
// Root of main app states
11-
states.push({ name: 'top', url: '/' });
11+
states.push({ name: 'top' });
1212

1313
// Personnel tab
1414
states.push({ name: 'top.people', url: 'people' });
@@ -59,6 +59,15 @@ describe("$previousState", function () {
5959
expect($previousState.get()).toBeNull();
6060
}));
6161

62+
// Test for #175
63+
it("should not capture root state (or non-navigable states)", inject(function($rootScope) {
64+
testGo("top", { entered: 'top' });
65+
testGo("top.cust", { entered: 'top.cust' });
66+
var prev = $previousState.get();
67+
expect(prev).toBeDefined();
68+
expect(prev.state.name).toBe("top");
69+
}));
70+
6271

6372
describe('.go()', function () {
6473
it("should transition back to the previous state", function () {
@@ -73,15 +82,15 @@ describe("$previousState", function () {
7382
describe('.get()', function() {
7483
// Test for #120
7584
it("should not return current state, after a transition is cancelled", inject(function($rootScope) {
76-
testGo("top", { entered: 'top' });
77-
testGo("top.people.managerlist", { entered: ['top.people', 'top.people.managerlist'] });
85+
testGo("top.people", { entered: [ 'top', 'top.people' ] });
86+
testGo("top.people.managerlist", { entered: ['top.people.managerlist'] });
7887

7988
var transitionNum = 0;
8089
$rootScope.$on("$stateChangeStart", function(evt) { if (transitionNum++ === 0) { evt.preventDefault(); } });
8190

8291
testGo("top.inv.storelist", undefined, { redirect: 'top.people.managerlist'}); // Cancelled, so we're still at original state
8392

84-
expect($previousState.get().state.name).toBe("top");
93+
expect($previousState.get().state.name).toBe("top.people");
8594
}))
8695
});
8796

0 commit comments

Comments
 (0)