diff --git a/src/dsr.js b/src/dsr.js index bedb0b9..b8f5876 100644 --- a/src/dsr.js +++ b/src/dsr.js @@ -129,7 +129,7 @@ angular.module('ct.ui.router.extras.dsr').service("$deepStateRedirect", [ '$root // update Last-SubState¶ms 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) }; } }); diff --git a/test/dsrSpec.js b/test/dsrSpec.js index c8b4adc..4f729fb 100644 --- a/test/dsrSpec.js +++ b/test/dsrSpec.js @@ -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' } ]; } @@ -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();