1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.UrlRouter = void 0;
|
4 | var common_1 = require("../common");
|
5 | var urlRule_1 = require("./urlRule");
|
6 | function appendBasePath(url, isHtml5, absolute, baseHref) {
|
7 | if (baseHref === '/')
|
8 | return url;
|
9 | if (isHtml5)
|
10 | return common_1.stripLastPathElement(baseHref) + url;
|
11 | if (absolute)
|
12 | return baseHref.slice(1) + url;
|
13 | return url;
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var UrlRouter = (function () {
|
24 |
|
25 | function UrlRouter(/** @internal */ router) {
|
26 | var _this = this;
|
27 | this.router = router;
|
28 |
|
29 |
|
30 | this.sync = function (evt) { return _this.router.urlService.sync(evt); };
|
31 |
|
32 | this.listen = function (enabled) { return _this.router.urlService.listen(enabled); };
|
33 |
|
34 | this.deferIntercept = function (defer) { return _this.router.urlService.deferIntercept(defer); };
|
35 |
|
36 | this.match = function (urlParts) { return _this.router.urlService.match(urlParts); };
|
37 |
|
38 |
|
39 | this.initial = function (handler) {
|
40 | return _this.router.urlService.rules.initial(handler);
|
41 | };
|
42 |
|
43 | this.otherwise = function (handler) {
|
44 | return _this.router.urlService.rules.otherwise(handler);
|
45 | };
|
46 |
|
47 | this.removeRule = function (rule) { return _this.router.urlService.rules.removeRule(rule); };
|
48 |
|
49 | this.rule = function (rule) { return _this.router.urlService.rules.rule(rule); };
|
50 |
|
51 | this.rules = function () { return _this.router.urlService.rules.rules(); };
|
52 |
|
53 | this.sort = function (compareFn) { return _this.router.urlService.rules.sort(compareFn); };
|
54 |
|
55 | this.when = function (matcher, handler, options) { return _this.router.urlService.rules.when(matcher, handler, options); };
|
56 | this.urlRuleFactory = new urlRule_1.UrlRuleFactory(router);
|
57 | }
|
58 |
|
59 | UrlRouter.prototype.update = function (read) {
|
60 | var $url = this.router.locationService;
|
61 | if (read) {
|
62 | this.location = $url.url();
|
63 | return;
|
64 | }
|
65 | if ($url.url() === this.location)
|
66 | return;
|
67 | $url.url(this.location, true);
|
68 | };
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | UrlRouter.prototype.push = function (urlMatcher, params, options) {
|
80 | var replace = options && !!options.replace;
|
81 | this.router.urlService.url(urlMatcher.format(params || {}), replace);
|
82 | };
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | UrlRouter.prototype.href = function (urlMatcher, params, options) {
|
103 | var url = urlMatcher.format(params);
|
104 | if (url == null)
|
105 | return null;
|
106 | options = options || { absolute: false };
|
107 | var cfg = this.router.urlService.config;
|
108 | var isHtml5 = cfg.html5Mode();
|
109 | if (!isHtml5 && url !== null) {
|
110 | url = '#' + cfg.hashPrefix() + url;
|
111 | }
|
112 | url = appendBasePath(url, isHtml5, options.absolute, cfg.baseHref());
|
113 | if (!options.absolute || !url) {
|
114 | return url;
|
115 | }
|
116 | var slash = !isHtml5 && url ? '/' : '';
|
117 | var cfgPort = cfg.port();
|
118 | var port = (cfgPort === 80 || cfgPort === 443 ? '' : ':' + cfgPort);
|
119 | return [cfg.protocol(), '://', cfg.host(), port, slash, url].join('');
|
120 | };
|
121 | Object.defineProperty(UrlRouter.prototype, "interceptDeferred", {
|
122 |
|
123 | get: function () {
|
124 | return this.router.urlService.interceptDeferred;
|
125 | },
|
126 | enumerable: false,
|
127 | configurable: true
|
128 | });
|
129 | return UrlRouter;
|
130 | }());
|
131 | exports.UrlRouter = UrlRouter;
|
132 |
|
\ | No newline at end of file |