Skip to content

Commit bde9c0f

Browse files
fix(redirectTo): Do not puke when redirectTo returns undefined
Closes angular-ui/ui-router#3117
1 parent 223f635 commit bde9c0f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/hooks/redirectTo.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ const redirectToHook: TransitionHookFn = (trans: Transition) => {
1717
let redirect = trans.to().redirectTo;
1818
if (!redirect) return;
1919

20-
function handleResult(result: any) {
21-
let $state = trans.router.stateService;
20+
let $state = trans.router.stateService;
2221

22+
function handleResult(result: any) {
23+
if (!result) return;
2324
if (result instanceof TargetState) return result;
2425
if (isString(result)) return $state.target(<any> result, trans.params(), trans.options());
2526
if (result['state'] || result['params'])

src/params/interface.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ export interface ParamDeclaration {
190190
*/
191191
squash: (boolean|string);
192192
/**
193-
* @hidden
194193
* @internalapi
195194
*
196195
* An array of [[Replace]] objects.
@@ -199,13 +198,13 @@ export interface ParamDeclaration {
199198
* or empty string `""`. If the transition is started, and the parameter value is equal to one of the "to"
200199
* values, then the parameter value is replaced with the "from" value.
201200
*
202-
* @example
203-
* ```
204-
*
201+
* #### Example:
202+
* ```js
205203
* replace: [
206204
* { from: undefined, to: null },
207205
* { from: "", to: null }
208206
* ]
207+
* ```
209208
*/
210209
replace: Replace[];
211210
/**

test/hooksSpec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ describe("hooks", () => {
106106
})
107107
})
108108

109+
// Test for #3117
110+
it("should not redirect if the redirectTo: function returns undefined", (done) => {
111+
find(states, s => s.name === 'A').redirectTo = function() {};
112+
init();
113+
114+
$state.go('A').then(() => {
115+
expect(router.globals.current.name).toBe('A');
116+
done()
117+
})
118+
})
119+
109120
it("should not redirect if the redirectTo: function returns something other than a string, { state, params}, TargetState (or promise for)", (done) => {
110121
find(states, s => s.name === 'A').redirectTo = () => new Promise((resolve) => {
111122
setTimeout(() => resolve(12345), 50)

0 commit comments

Comments
 (0)