123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @license Angular v6.0.9
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { APP_BOOTSTRAP_LISTENER } from '@angular/core';
  7. import { Router } from '@angular/router';
  8. import { UpgradeModule } from '@angular/upgrade/static';
  9. /**
  10. * @license
  11. * Copyright Google Inc. All Rights Reserved.
  12. *
  13. * Use of this source code is governed by an MIT-style license that can be
  14. * found in the LICENSE file at https://angular.io/license
  15. */
  16. /**
  17. * @description
  18. *
  19. * Creates an initializer that in addition to setting up the Angular
  20. * router sets up the ngRoute integration.
  21. *
  22. * ```
  23. * @NgModule({
  24. * imports: [
  25. * RouterModule.forRoot(SOME_ROUTES),
  26. * UpgradeModule
  27. * ],
  28. * providers: [
  29. * RouterUpgradeInitializer
  30. * ]
  31. * })
  32. * export class AppModule {
  33. * ngDoBootstrap() {}
  34. * }
  35. * ```
  36. *
  37. * @experimental
  38. */
  39. var RouterUpgradeInitializer = {
  40. provide: APP_BOOTSTRAP_LISTENER,
  41. multi: true,
  42. useFactory: locationSyncBootstrapListener,
  43. deps: [UpgradeModule]
  44. };
  45. /**
  46. * @internal
  47. */
  48. function locationSyncBootstrapListener(ngUpgrade) {
  49. return function () { setUpLocationSync(ngUpgrade); };
  50. }
  51. /**
  52. * @description
  53. *
  54. * Sets up a location synchronization.
  55. *
  56. * History.pushState does not fire onPopState, so the Angular location
  57. * doesn't detect it. The workaround is to attach a location change listener
  58. *
  59. * @experimental
  60. */
  61. function setUpLocationSync(ngUpgrade) {
  62. if (!ngUpgrade.$injector) {
  63. 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 ");
  64. }
  65. var router = ngUpgrade.injector.get(Router);
  66. var url = document.createElement('a');
  67. ngUpgrade.$injector.get('$rootScope')
  68. .$on('$locationChangeStart', function (_, next, __) {
  69. url.href = next;
  70. router.navigateByUrl(url.pathname + url.search + url.hash);
  71. });
  72. }
  73. /**
  74. * @license
  75. * Copyright Google Inc. All Rights Reserved.
  76. *
  77. * Use of this source code is governed by an MIT-style license that can be
  78. * found in the LICENSE file at https://angular.io/license
  79. */
  80. // This file only reexports content of the `src` folder. Keep it that way.
  81. /**
  82. * @license
  83. * Copyright Google Inc. All Rights Reserved.
  84. *
  85. * Use of this source code is governed by an MIT-style license that can be
  86. * found in the LICENSE file at https://angular.io/license
  87. */
  88. /**
  89. * Generated bundle index. Do not edit.
  90. */
  91. export { RouterUpgradeInitializer, locationSyncBootstrapListener, setUpLocationSync };
  92. //# sourceMappingURL=upgrade.js.map