1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.registerRedirectToHook = void 0;
|
4 | var predicates_1 = require("../common/predicates");
|
5 | var coreservices_1 = require("../common/coreservices");
|
6 | var targetState_1 = require("../state/targetState");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var 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 | };
|
34 | exports.registerRedirectToHook = function (transitionService) {
|
35 | return transitionService.onStart({ to: function (state) { return !!state.redirectTo; } }, redirectToHook);
|
36 | };
|
37 |
|
\ | No newline at end of file |