Skip to content

Commit

Permalink
fix: deactivation path, activation path and node listener for same ro…
Browse files Browse the repository at this point in the history
…ute names with different params

Fixes #27
  • Loading branch information
troch committed Sep 15, 2015
1 parent 91e3163 commit fa985d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions modules/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ function transitionPath(toState, fromState) {
let toStateIds = nameToIDs(toState.name)
let maxI = Math.min(fromStateIds.length, toStateIds.length)

for (i = 0; i < maxI; i += 1) {
if (fromStateIds[i] !== toStateIds[i]) break
if (fromState && fromState.name === toState.name) i = Math.max(maxI - 1, 0)
else {
for (i = 0; i < maxI; i += 1) {
if (fromStateIds[i] !== toStateIds[i]) break
}
}

let toDeactivate = fromStateIds.slice(i).reverse()
Expand Down
8 changes: 6 additions & 2 deletions tests/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ function testRouter(useHash) {
router.addNodeListener('users', listeners.node);
router.navigate('users.view', {id: 1}, {}, function () {
expect(listeners.node).toHaveBeenCalled();
router.removeNodeListener('users', listeners.node);
done();
router.navigate('users.view', {id: 1}, {}, function() {
router.navigate('users.view', {id: 2}, {}, function(err, state) {
expect(listeners.node.calls.count()).toBe(2);
done();
})
});
});
});
});
Expand Down

0 comments on commit fa985d2

Please sign in to comment.