router-upgrade.umd.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/router'), require('@angular/upgrade/static')) :
  8. typeof define === 'function' && define.amd ? define('@angular/router/upgrade', ['exports', '@angular/common', '@angular/core', '@angular/router', '@angular/upgrade/static'], factory) :
  9. (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));
  10. }(this, function (exports, common, core, router, _static) { 'use strict';
  11. /**
  12. * @license
  13. * Copyright Google Inc. All Rights Reserved.
  14. *
  15. * Use of this source code is governed by an MIT-style license that can be
  16. * found in the LICENSE file at https://angular.io/license
  17. */
  18. var ɵ0 = locationSyncBootstrapListener;
  19. /**
  20. * @description
  21. *
  22. * Creates an initializer that in addition to setting up the Angular
  23. * router sets up the ngRoute integration.
  24. *
  25. * ```
  26. * @NgModule({
  27. * imports: [
  28. * RouterModule.forRoot(SOME_ROUTES),
  29. * UpgradeModule
  30. * ],
  31. * providers: [
  32. * RouterUpgradeInitializer
  33. * ]
  34. * })
  35. * export class AppModule {
  36. * ngDoBootstrap() {}
  37. * }
  38. * ```
  39. *
  40. * @publicApi
  41. */
  42. var RouterUpgradeInitializer = {
  43. provide: core.APP_BOOTSTRAP_LISTENER,
  44. multi: true,
  45. useFactory: ɵ0,
  46. deps: [_static.UpgradeModule]
  47. };
  48. /**
  49. * @internal
  50. */
  51. function locationSyncBootstrapListener(ngUpgrade) {
  52. return function () { setUpLocationSync(ngUpgrade); };
  53. }
  54. /**
  55. * @description
  56. *
  57. * Sets up a location synchronization.
  58. *
  59. * History.pushState does not fire onPopState, so the Angular location
  60. * doesn't detect it. The workaround is to attach a location change listener
  61. *
  62. * @publicApi
  63. */
  64. function setUpLocationSync(ngUpgrade, urlType) {
  65. if (urlType === void 0) { urlType = 'path'; }
  66. if (!ngUpgrade.$injector) {
  67. 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 ");
  68. }
  69. var router$1 = ngUpgrade.injector.get(router.Router);
  70. var location = ngUpgrade.injector.get(common.Location);
  71. ngUpgrade.$injector.get('$rootScope')
  72. .$on('$locationChangeStart', function (_, next, __) {
  73. var url;
  74. if (urlType === 'path') {
  75. url = resolveUrl(next);
  76. }
  77. else if (urlType === 'hash') {
  78. // Remove the first hash from the URL
  79. var 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. var path = location.normalize(url.pathname);
  86. router$1.navigateByUrl(path + url.search + url.hash);
  87. });
  88. }
  89. /**
  90. * Normalize and parse 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. */
  107. var anchor;
  108. function 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. }
  121. /**
  122. * @license
  123. * Copyright Google Inc. All Rights Reserved.
  124. *
  125. * Use of this source code is governed by an MIT-style license that can be
  126. * found in the LICENSE file at https://angular.io/license
  127. */
  128. // This file only reexports content of the `src` folder. Keep it that way.
  129. /**
  130. * @license
  131. * Copyright Google Inc. All Rights Reserved.
  132. *
  133. * Use of this source code is governed by an MIT-style license that can be
  134. * found in the LICENSE file at https://angular.io/license
  135. */
  136. /**
  137. * Generated bundle index. Do not edit.
  138. */
  139. exports.RouterUpgradeInitializer = RouterUpgradeInitializer;
  140. exports.locationSyncBootstrapListener = locationSyncBootstrapListener;
  141. exports.setUpLocationSync = setUpLocationSync;
  142. exports.ɵ0 = ɵ0;
  143. Object.defineProperty(exports, '__esModule', { value: true });
  144. }));
  145. //# sourceMappingURL=router-upgrade.umd.js.map