Skip to content

Commit

Permalink
fix(redirectTo): Do not puke when redirectTo returns undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Nov 1, 2016
1 parent 223f635 commit bde9c0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/hooks/redirectTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<any> result, trans.params(), trans.options());
if (result['state'] || result['params'])
Expand Down
7 changes: 3 additions & 4 deletions src/params/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export interface ParamDeclaration {
*/
squash: (boolean|string);
/**
* @hidden
* @internalapi
*
* An array of [[Replace]] objects.
Expand All @@ -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[];
/**
Expand Down
11 changes: 11 additions & 0 deletions test/hooksSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bde9c0f

Please sign in to comment.