1 | /**
|
2 | * @license Angular v8.0.2
|
3 | * (c) 2010-2019 Google LLC. https://angular.io/
|
4 | * License: MIT
|
5 | */
|
6 |
|
7 | import { Location } from '@angular/common';
|
8 | import { APP_BOOTSTRAP_LISTENER } from '@angular/core';
|
9 | import { Router } from '@angular/router';
|
10 | import { UpgradeModule } from '@angular/upgrade/static';
|
11 |
|
12 | /**
|
13 | * @license
|
14 | * Copyright Google Inc. All Rights Reserved.
|
15 | *
|
16 | * Use of this source code is governed by an MIT-style license that can be
|
17 | * found in the LICENSE file at https://angular.io/license
|
18 | */
|
19 | var ɵ0 = locationSyncBootstrapListener;
|
20 | /**
|
21 | * @description
|
22 | *
|
23 | * Creates an initializer that in addition to setting up the Angular
|
24 | * router sets up the ngRoute integration.
|
25 | *
|
26 | * ```
|
27 | * @NgModule({
|
28 | * imports: [
|
29 | * RouterModule.forRoot(SOME_ROUTES),
|
30 | * UpgradeModule
|
31 | * ],
|
32 | * providers: [
|
33 | * RouterUpgradeInitializer
|
34 | * ]
|
35 | * })
|
36 | * export class AppModule {
|
37 | * ngDoBootstrap() {}
|
38 | * }
|
39 | * ```
|
40 | *
|
41 | * @publicApi
|
42 | */
|
43 | var RouterUpgradeInitializer = {
|
44 | provide: APP_BOOTSTRAP_LISTENER,
|
45 | multi: true,
|
46 | useFactory: ɵ0,
|
47 | deps: [UpgradeModule]
|
48 | };
|
49 | /**
|
50 | * @internal
|
51 | */
|
52 | function locationSyncBootstrapListener(ngUpgrade) {
|
53 | return function () { setUpLocationSync(ngUpgrade); };
|
54 | }
|
55 | /**
|
56 | * @description
|
57 | *
|
58 | * Sets up a location synchronization.
|
59 | *
|
60 | * History.pushState does not fire onPopState, so the Angular location
|
61 | * doesn't detect it. The workaround is to attach a location change listener
|
62 | *
|
63 | * @publicApi
|
64 | */
|
65 | function setUpLocationSync(ngUpgrade, urlType) {
|
66 | if (urlType === void 0) { urlType = 'path'; }
|
67 | if (!ngUpgrade.$injector) {
|
68 | throw new Error("\n RouterUpgradeInitializer can be used only after UpgradeModule.bootstrap has been called.\n Remove RouterUpgradeInitializer and call setUpLocationSync after UpgradeModule.bootstrap.\n ");
|
69 | }
|
70 | var router = ngUpgrade.injector.get(Router);
|
71 | var location = ngUpgrade.injector.get(Location);
|
72 | ngUpgrade.$injector.get('$rootScope')
|
73 | .$on('$locationChangeStart', function (_, next, __) {
|
74 | var url;
|
75 | if (urlType === 'path') {
|
76 | url = resolveUrl(next);
|
77 | }
|
78 | else if (urlType === 'hash') {
|
79 | // Remove the first hash from the URL
|
80 | var hashIdx = next.indexOf('#');
|
81 | url = resolveUrl(next.substring(0, hashIdx) + next.substring(hashIdx + 1));
|
82 | }
|
83 | else {
|
84 | throw 'Invalid URLType passed to setUpLocationSync: ' + urlType;
|
85 | }
|
86 | var path = location.normalize(url.pathname);
|
87 | router.navigateByUrl(path + url.search + url.hash);
|
88 | });
|
89 | }
|
90 | /**
|
91 | * Normalize and parse a URL.
|
92 | *
|
93 | * - Normalizing means that a relative URL will be resolved into an absolute URL in the context of
|
94 | * the application document.
|
95 | * - Parsing means that the anchor's `protocol`, `hostname`, `port`, `pathname` and related
|
96 | * properties are all populated to reflect the normalized URL.
|
97 | *
|
98 | * While this approach has wide compatibility, it doesn't work as expected on IE. On IE, normalizing
|
99 | * happens similar to other browsers, but the parsed components will not be set. (E.g. if you assign
|
100 | * `a.href = 'foo'`, then `a.protocol`, `a.host`, etc. will not be correctly updated.)
|
101 | * We work around that by performing the parsing in a 2nd step by taking a previously normalized URL
|
102 | * and assigning it again. This correctly populates all properties.
|
103 | *
|
104 | * See
|
105 | * https://github.com/angular/angular.js/blob/2c7400e7d07b0f6cec1817dab40b9250ce8ebce6/src/ng/urlUtils.js#L26-L33
|
106 | * for more info.
|
107 | */
|
108 | var anchor;
|
109 | function resolveUrl(url) {
|
110 | if (!anchor) {
|
111 | anchor = document.createElement('a');
|
112 | }
|
113 | anchor.setAttribute('href', url);
|
114 | anchor.setAttribute('href', anchor.href);
|
115 | return {
|
116 | // IE does not start `pathname` with `/` like other browsers.
|
117 | pathname: "/" + anchor.pathname.replace(/^\//, ''),
|
118 | search: anchor.search,
|
119 | hash: anchor.hash
|
120 | };
|
121 | }
|
122 |
|
123 | /**
|
124 | * @license
|
125 | * Copyright Google Inc. All Rights Reserved.
|
126 | *
|
127 | * Use of this source code is governed by an MIT-style license that can be
|
128 | * found in the LICENSE file at https://angular.io/license
|
129 | */
|
130 | // This file only reexports content of the `src` folder. Keep it that way.
|
131 |
|
132 | /**
|
133 | * @license
|
134 | * Copyright Google Inc. All Rights Reserved.
|
135 | *
|
136 | * Use of this source code is governed by an MIT-style license that can be
|
137 | * found in the LICENSE file at https://angular.io/license
|
138 | */
|
139 |
|
140 | /**
|
141 | * Generated bundle index. Do not edit.
|
142 | */
|
143 |
|
144 | export { RouterUpgradeInitializer, locationSyncBootstrapListener, setUpLocationSync, ɵ0 };
|
145 | //# sourceMappingURL=upgrade.js.map
|