Skip to content

Commit 25e0c04

Browse files
fix(stateQueueManager): Use location: true for url-matched transitions
closes #2455
1 parent 5d1f50f commit 25e0c04

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/state/stateQueueManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class StateQueueManager {
8282

8383
$urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
8484
if ($state.$current.navigable !== state || !equalForKeys($match, $stateParams)) {
85-
$state.transitionTo(state, $match, { inherit: true, location: false });
85+
$state.transitionTo(state, $match, { inherit: true });
8686
}
8787
}]);
8888
}

test/stateSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -2027,3 +2027,23 @@ describe('otherwise and state redirects', function() {
20272027
expect($state.current.name).toBe("loginPage")
20282028
}));
20292029
});
2030+
2031+
2032+
describe('hook redirects from .otherwise()', function() {
2033+
beforeEach(module(function ($stateProvider, $urlRouterProvider) {
2034+
$urlRouterProvider.otherwise('/home');
2035+
$stateProvider
2036+
.state('home', { url: '/home', template: 'home' })
2037+
.state('loginPage', { url: '/login', template: 'login' });
2038+
}));
2039+
2040+
// Test for #2455
2041+
it("should go to the redirect-to target state and url", inject(function($transitions, $q, $state, $location) {
2042+
$transitions.onBefore({ to: 'home' }, function() {
2043+
return $state.target('loginPage', {}, { location: true });
2044+
});
2045+
$q.flush();
2046+
expect($state.current.name).toBe("loginPage");
2047+
expect($location.path()).toBe('/login');
2048+
}));
2049+
});

0 commit comments

Comments
 (0)