From bde9c0f819b953569e6c18c99966637340df3a7f Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Tue, 1 Nov 2016 16:59:45 -0500 Subject: [PATCH] fix(redirectTo): Do not puke when redirectTo returns undefined Closes https://github.com/angular-ui/ui-router/issues/3117 --- src/hooks/redirectTo.ts | 5 +++-- src/params/interface.ts | 7 +++---- test/hooksSpec.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/hooks/redirectTo.ts b/src/hooks/redirectTo.ts index 25cecc35..6a0519d9 100644 --- a/src/hooks/redirectTo.ts +++ b/src/hooks/redirectTo.ts @@ -17,9 +17,10 @@ const redirectToHook: TransitionHookFn = (trans: Transition) => { let redirect = trans.to().redirectTo; if (!redirect) return; - function handleResult(result: any) { - let $state = trans.router.stateService; + let $state = trans.router.stateService; + function handleResult(result: any) { + if (!result) return; if (result instanceof TargetState) return result; if (isString(result)) return $state.target( result, trans.params(), trans.options()); if (result['state'] || result['params']) diff --git a/src/params/interface.ts b/src/params/interface.ts index cc8c2814..be9a13c2 100644 --- a/src/params/interface.ts +++ b/src/params/interface.ts @@ -190,7 +190,6 @@ export interface ParamDeclaration { */ squash: (boolean|string); /** - * @hidden * @internalapi * * An array of [[Replace]] objects. @@ -199,13 +198,13 @@ export interface ParamDeclaration { * or empty string `""`. If the transition is started, and the parameter value is equal to one of the "to" * values, then the parameter value is replaced with the "from" value. * - * @example - * ``` - * + * #### Example: + * ```js * replace: [ * { from: undefined, to: null }, * { from: "", to: null } * ] + * ``` */ replace: Replace[]; /** diff --git a/test/hooksSpec.ts b/test/hooksSpec.ts index 107340fa..51d4c399 100644 --- a/test/hooksSpec.ts +++ b/test/hooksSpec.ts @@ -106,6 +106,17 @@ describe("hooks", () => { }) }) + // Test for #3117 + it("should not redirect if the redirectTo: function returns undefined", (done) => { + find(states, s => s.name === 'A').redirectTo = function() {}; + init(); + + $state.go('A').then(() => { + expect(router.globals.current.name).toBe('A'); + done() + }) + }) + it("should not redirect if the redirectTo: function returns something other than a string, { state, params}, TargetState (or promise for)", (done) => { find(states, s => s.name === 'A').redirectTo = () => new Promise((resolve) => { setTimeout(() => resolve(12345), 50)