1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.PushStateLocationService = void 0;
|
17 | var baseLocationService_1 = require("./baseLocationService");
|
18 | var common_1 = require("../common");
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var PushStateLocationService = (function (_super) {
|
25 | __extends(PushStateLocationService, _super);
|
26 | function PushStateLocationService(router) {
|
27 | var _this = _super.call(this, router, true) || this;
|
28 | _this._config = router.urlService.config;
|
29 | common_1.root.addEventListener('popstate', _this._listener, false);
|
30 | return _this;
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | PushStateLocationService.prototype._getBasePrefix = function () {
|
49 | return common_1.stripLastPathElement(this._config.baseHref());
|
50 | };
|
51 | PushStateLocationService.prototype._get = function () {
|
52 | var _a = this._location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
|
53 | search = common_1.splitQuery(search)[1];
|
54 | hash = common_1.splitHash(hash)[1];
|
55 | var basePrefix = this._getBasePrefix();
|
56 | var exactBaseHrefMatch = pathname === this._config.baseHref();
|
57 | var startsWithBase = pathname.substr(0, basePrefix.length) === basePrefix;
|
58 | pathname = exactBaseHrefMatch ? '/' : startsWithBase ? pathname.substring(basePrefix.length) : pathname;
|
59 | return pathname + (search ? '?' + search : '') + (hash ? '#' + hash : '');
|
60 | };
|
61 | PushStateLocationService.prototype._set = function (state, title, url, replace) {
|
62 | var basePrefix = this._getBasePrefix();
|
63 | var slash = url && url[0] !== '/' ? '/' : '';
|
64 | var fullUrl = url === '' || url === '/' ? this._config.baseHref() : basePrefix + slash + url;
|
65 | if (replace) {
|
66 | this._history.replaceState(state, title, fullUrl);
|
67 | }
|
68 | else {
|
69 | this._history.pushState(state, title, fullUrl);
|
70 | }
|
71 | };
|
72 | PushStateLocationService.prototype.dispose = function (router) {
|
73 | _super.prototype.dispose.call(this, router);
|
74 | common_1.root.removeEventListener('popstate', this._listener);
|
75 | };
|
76 | return PushStateLocationService;
|
77 | }(baseLocationService_1.BaseLocationServices));
|
78 | exports.PushStateLocationService = PushStateLocationService;
|
79 |
|
\ | No newline at end of file |