From 25e0c0409da6544a1173f8cba880aa88def89b9c Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sun, 6 Mar 2016 17:05:30 -0600 Subject: [PATCH] fix(stateQueueManager): Use `location: true` for url-matched transitions closes #2455 --- src/state/stateQueueManager.ts | 2 +- test/stateSpec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/state/stateQueueManager.ts b/src/state/stateQueueManager.ts index a1d10462c..62204d084 100644 --- a/src/state/stateQueueManager.ts +++ b/src/state/stateQueueManager.ts @@ -82,7 +82,7 @@ export class StateQueueManager { $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) { if ($state.$current.navigable !== state || !equalForKeys($match, $stateParams)) { - $state.transitionTo(state, $match, { inherit: true, location: false }); + $state.transitionTo(state, $match, { inherit: true }); } }]); } diff --git a/test/stateSpec.js b/test/stateSpec.js index b8df3f5e1..944e4ad0a 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -2027,3 +2027,23 @@ describe('otherwise and state redirects', function() { expect($state.current.name).toBe("loginPage") })); }); + + +describe('hook redirects from .otherwise()', function() { + beforeEach(module(function ($stateProvider, $urlRouterProvider) { + $urlRouterProvider.otherwise('/home'); + $stateProvider + .state('home', { url: '/home', template: 'home' }) + .state('loginPage', { url: '/login', template: 'login' }); + })); + + // Test for #2455 + it("should go to the redirect-to target state and url", inject(function($transitions, $q, $state, $location) { + $transitions.onBefore({ to: 'home' }, function() { + return $state.target('loginPage', {}, { location: true }); + }); + $q.flush(); + expect($state.current.name).toBe("loginPage"); + expect($location.path()).toBe('/login'); + })); +});