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

Commit

Permalink
fix(dsr): Use state.includes instead of state.name.indexOf to determi…
Browse files Browse the repository at this point in the history
…ne if a dsr state is my ancestor

Closes #208
  • Loading branch information
christopherthielen committed Jun 18, 2015
1 parent 45c535a commit 89565f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ angular.module('ct.ui.router.extras.dsr').service("$deepStateRedirect", [ '$root
// update Last-SubState&params for each DSR that this transition matches.
var cfg = getConfig($state.get(dsrState));
var key = getParamsString(toParams, cfg.params);
if (name == dsrState || name.indexOf(dsrState + ".") != -1) {
if (toState.$$state().includes[dsrState]) {
lastSubstate[dsrState][key] = { state: name, params: angular.copy(toParams) };
}
});
Expand Down
13 changes: 12 additions & 1 deletion test/dsrSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ function getDSRStates () {
{ name: 'p6.child3'},
{ name: 'p7', url: '/p7/:param', dsr: { default: {}, fn: p7DSRFunction } },
{ name: 'p7.child1'},
{ name: 'p7.child2'}
{ name: 'p7.child2'},
{ name: 'p8', dsr: true },
{ name: 'p8child1', parent: 'p8' },
{ name: 'p8child2', parent: 'p8' }
];
}

Expand Down Expand Up @@ -95,6 +98,14 @@ describe('deepStateRedirect', function () {
}));
});

describe("with child substates configured using {parent: parentState}", function() {
it("should remember and redirect to the last deepest state", function() {
testGo("p8child1");
testGo("other");
testGo("p8", undefined, { redirect: 'p8child1'} );
});
});

describe('with configured params', function () {
it("should redirect only when params match", inject(function($state, $q) {
$state.go("p1", { param1: "foo", param2: "foo2" } ); $q.flush();
Expand Down

0 comments on commit 89565f4

Please sign in to comment.