diff --git a/src/state.js b/src/state.js index b4c26ffdf..f73e886e7 100644 --- a/src/state.js +++ b/src/state.js @@ -111,7 +111,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { // Register the state in the global state list and with $urlRouter if necessary. if (!state['abstract'] && url) { $urlRouterProvider.when(url, ['$match', function ($match) { - $state.transitionTo(state, $match, false); + if ($state.$current.navigable != state) $state.transitionTo(state, $match, false); }]); } states[name] = state; diff --git a/test/stateSpec.js b/test/stateSpec.js index f9398f42c..0a3337497 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -38,7 +38,8 @@ describe('state', function () { .state('home.item', { url: "front/:id" }) .state('about', { url: "/about" }) .state('about.person', { url: "/:person" }) - .state('about.person.item', { url: "/:id" }); + .state('about.person.item', { url: "/:id" }) + .state('about.sidebar', {}); $provide.value('AppInjectable', AppInjectable); })); @@ -160,7 +161,7 @@ describe('state', function () { '$stateChangeSuccess(C,A);'); })); - it('aborts pending transitions even when going back to the curren state', inject(function ($state, $q) { + it('aborts pending transitions even when going back to the current state', inject(function ($state, $q) { initStateTo(A); logEvents = true; @@ -191,6 +192,11 @@ describe('state', function () { 'D.onExit;' + 'A.onEnter;'); })); + + it('doesn\'t transition to parent state when child has no URL', inject(function ($state, $q) { + $state.transitionTo('about.sidebar'); $q.flush(); + expect($state.current.name).toEqual('about.sidebar'); + })); });