Skip to content

Commit 2874694

Browse files
committed
Fixing issue with child states without URLs
1 parent cf32719 commit 2874694

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
111111
// Register the state in the global state list and with $urlRouter if necessary.
112112
if (!state['abstract'] && url) {
113113
$urlRouterProvider.when(url, ['$match', function ($match) {
114-
$state.transitionTo(state, $match, false);
114+
if ($state.$current.navigable != state) $state.transitionTo(state, $match, false);
115115
}]);
116116
}
117117
states[name] = state;

test/stateSpec.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('state', function () {
3838
.state('home.item', { url: "front/:id" })
3939
.state('about', { url: "/about" })
4040
.state('about.person', { url: "/:person" })
41-
.state('about.person.item', { url: "/:id" });
41+
.state('about.person.item', { url: "/:id" })
42+
.state('about.sidebar', {});
4243

4344
$provide.value('AppInjectable', AppInjectable);
4445
}));
@@ -160,7 +161,7 @@ describe('state', function () {
160161
'$stateChangeSuccess(C,A);');
161162
}));
162163

163-
it('aborts pending transitions even when going back to the curren state', inject(function ($state, $q) {
164+
it('aborts pending transitions even when going back to the current state', inject(function ($state, $q) {
164165
initStateTo(A);
165166
logEvents = true;
166167

@@ -191,6 +192,11 @@ describe('state', function () {
191192
'D.onExit;' +
192193
'A.onEnter;');
193194
}));
195+
196+
it('doesn\'t transition to parent state when child has no URL', inject(function ($state, $q) {
197+
$state.transitionTo('about.sidebar'); $q.flush();
198+
expect($state.current.name).toEqual('about.sidebar');
199+
}));
194200
});
195201

196202

0 commit comments

Comments
 (0)