UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.registerRedirectToHook = void 0;
4var predicates_1 = require("../common/predicates");
5var coreservices_1 = require("../common/coreservices");
6var targetState_1 = require("../state/targetState");
7/**
8 * A [[TransitionHookFn]] that redirects to a different state or params
9 *
10 * Registered using `transitionService.onStart({ to: (state) => !!state.redirectTo }, redirectHook);`
11 *
12 * See [[StateDeclaration.redirectTo]]
13 */
14var redirectToHook = function (trans) {
15 var redirect = trans.to().redirectTo;
16 if (!redirect)
17 return;
18 var $state = trans.router.stateService;
19 function handleResult(result) {
20 if (!result)
21 return;
22 if (result instanceof targetState_1.TargetState)
23 return result;
24 if (predicates_1.isString(result))
25 return $state.target(result, trans.params(), trans.options());
26 if (result['state'] || result['params'])
27 return $state.target(result['state'] || trans.to(), result['params'] || trans.params(), trans.options());
28 }
29 if (predicates_1.isFunction(redirect)) {
30 return coreservices_1.services.$q.when(redirect(trans)).then(handleResult);
31 }
32 return handleResult(redirect);
33};
34exports.registerRedirectToHook = function (transitionService) {
35 return transitionService.onStart({ to: function (state) { return !!state.redirectTo; } }, redirectToHook);
36};
37//# sourceMappingURL=redirectTo.js.map
\No newline at end of file