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