router-upgrade.umd.js 5.1 KB

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