source: trip-planner-front/node_modules/@angular/router/esm2015/upgrade/src/upgrade.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 12.2 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Location } from '@angular/common';
9import { APP_BOOTSTRAP_LISTENER } from '@angular/core';
10import { Router } from '@angular/router';
11import { UpgradeModule } from '@angular/upgrade/static';
12const ɵ0 = locationSyncBootstrapListener;
13/**
14 * Creates an initializer that sets up `ngRoute` integration
15 * along with setting up the Angular router.
16 *
17 * @usageNotes
18 *
19 * <code-example language="typescript">
20 * @NgModule({
21 * imports: [
22 * RouterModule.forRoot(SOME_ROUTES),
23 * UpgradeModule
24 * ],
25 * providers: [
26 * RouterUpgradeInitializer
27 * ]
28 * })
29 * export class AppModule {
30 * ngDoBootstrap() {}
31 * }
32 * </code-example>
33 *
34 * @publicApi
35 */
36export const RouterUpgradeInitializer = {
37 provide: APP_BOOTSTRAP_LISTENER,
38 multi: true,
39 useFactory: ɵ0,
40 deps: [UpgradeModule]
41};
42/**
43 * @internal
44 */
45export function locationSyncBootstrapListener(ngUpgrade) {
46 return () => {
47 setUpLocationSync(ngUpgrade);
48 };
49}
50/**
51 * Sets up a location change listener to trigger `history.pushState`.
52 * Works around the problem that `onPopState` does not trigger `history.pushState`.
53 * Must be called *after* calling `UpgradeModule.bootstrap`.
54 *
55 * @param ngUpgrade The upgrade NgModule.
56 * @param urlType The location strategy.
57 * @see `HashLocationStrategy`
58 * @see `PathLocationStrategy`
59 *
60 * @publicApi
61 */
62export function setUpLocationSync(ngUpgrade, urlType = 'path') {
63 if (!ngUpgrade.$injector) {
64 throw new Error(`
65 RouterUpgradeInitializer can be used only after UpgradeModule.bootstrap has been called.
66 Remove RouterUpgradeInitializer and call setUpLocationSync after UpgradeModule.bootstrap.
67 `);
68 }
69 const router = ngUpgrade.injector.get(Router);
70 const location = ngUpgrade.injector.get(Location);
71 ngUpgrade.$injector.get('$rootScope')
72 .$on('$locationChangeStart', (_, next, __) => {
73 let url;
74 if (urlType === 'path') {
75 url = resolveUrl(next);
76 }
77 else if (urlType === 'hash') {
78 // Remove the first hash from the URL
79 const hashIdx = next.indexOf('#');
80 url = resolveUrl(next.substring(0, hashIdx) + next.substring(hashIdx + 1));
81 }
82 else {
83 throw 'Invalid URLType passed to setUpLocationSync: ' + urlType;
84 }
85 const path = location.normalize(url.pathname);
86 router.navigateByUrl(path + url.search + url.hash);
87 });
88}
89/**
90 * Normalizes and parses a URL.
91 *
92 * - Normalizing means that a relative URL will be resolved into an absolute URL in the context of
93 * the application document.
94 * - Parsing means that the anchor's `protocol`, `hostname`, `port`, `pathname` and related
95 * properties are all populated to reflect the normalized URL.
96 *
97 * While this approach has wide compatibility, it doesn't work as expected on IE. On IE, normalizing
98 * happens similar to other browsers, but the parsed components will not be set. (E.g. if you assign
99 * `a.href = 'foo'`, then `a.protocol`, `a.host`, etc. will not be correctly updated.)
100 * We work around that by performing the parsing in a 2nd step by taking a previously normalized URL
101 * and assigning it again. This correctly populates all properties.
102 *
103 * See
104 * https://github.com/angular/angular.js/blob/2c7400e7d07b0f6cec1817dab40b9250ce8ebce6/src/ng/urlUtils.js#L26-L33
105 * for more info.
106 */
107let anchor;
108function resolveUrl(url) {
109 if (!anchor) {
110 anchor = document.createElement('a');
111 }
112 anchor.setAttribute('href', url);
113 anchor.setAttribute('href', anchor.href);
114 return {
115 // IE does not start `pathname` with `/` like other browsers.
116 pathname: `/${anchor.pathname.replace(/^\//, '')}`,
117 search: anchor.search,
118 hash: anchor.hash
119 };
120}
121export { ɵ0 };
122//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBncmFkZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL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