blob: 0f6d0bb12811e1413565e4fe8f74b29fc5079bb1 [file] [log] [blame]
{"version":3,"file":"router-upgrade.umd.js","sources":["../../../../../../packages/router/upgrade/src/upgrade.ts","../../../../../../packages/router/upgrade/public_api.ts","../../../../../../packages/router/upgrade/index.ts","../../../../../../packages/router/upgrade/upgrade.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Location} from '@angular/common';\nimport {APP_BOOTSTRAP_LISTENER, ComponentRef, InjectionToken} from '@angular/core';\nimport {Router} from '@angular/router';\nimport {UpgradeModule} from '@angular/upgrade/static';\n\n/**\n * @description\n *\n * Creates an initializer that in addition to setting up the Angular\n * router sets up the ngRoute integration.\n *\n * ```\n * @NgModule({\n * imports: [\n * RouterModule.forRoot(SOME_ROUTES),\n * UpgradeModule\n * ],\n * providers: [\n * RouterUpgradeInitializer\n * ]\n * })\n * export class AppModule {\n * ngDoBootstrap() {}\n * }\n * ```\n *\n * @publicApi\n */\nexport const RouterUpgradeInitializer = {\n provide: APP_BOOTSTRAP_LISTENER,\n multi: true,\n useFactory: locationSyncBootstrapListener as(ngUpgrade: UpgradeModule) => () => void,\n deps: [UpgradeModule]\n};\n\n/**\n * @internal\n */\nexport function locationSyncBootstrapListener(ngUpgrade: UpgradeModule) {\n return () => { setUpLocationSync(ngUpgrade); };\n}\n\n/**\n * @description\n *\n * Sets up a location synchronization.\n *\n * History.pushState does not fire onPopState, so the Angular location\n * doesn't detect it. The workaround is to attach a location change listener\n *\n * @publicApi\n */\nexport function setUpLocationSync(ngUpgrade: UpgradeModule, urlType: 'path' | 'hash' = 'path') {\n if (!ngUpgrade.$injector) {\n 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 `);\n }\n\n const router: Router = ngUpgrade.injector.get(Router);\n const location: Location = ngUpgrade.injector.get(Location);\n\n ngUpgrade.$injector.get('$rootScope')\n .$on('$locationChangeStart', (_: any, next: string, __: string) => {\n let url;\n if (urlType === 'path') {\n url = resolveUrl(next);\n } else if (urlType === 'hash') {\n // Remove the first hash from the URL\n const hashIdx = next.indexOf('#');\n url = resolveUrl(next.substring(0, hashIdx) + next.substring(hashIdx + 1));\n } else {\n throw 'Invalid URLType passed to setUpLocationSync: ' + urlType;\n }\n const path = location.normalize(url.pathname);\n router.navigateByUrl(path + url.search + url.hash);\n });\n}\n\n/**\n * Normalize and parse a URL.\n *\n * - Normalizing means that a relative URL will be resolved into an absolute URL in the context of\n * the application document.\n * - Parsing means that the anchor's `protocol`, `hostname`, `port`, `pathname` and related\n * properties are all populated to reflect the normalized URL.\n *\n * While this approach has wide compatibility, it doesn't work as expected on IE. On IE, normalizing\n * happens similar to other browsers, but the parsed components will not be set. (E.g. if you assign\n * `a.href = 'foo'`, then `a.protocol`, `a.host`, etc. will not be correctly updated.)\n * We work around that by performing the parsing in a 2nd step by taking a previously normalized URL\n * and assigning it again. This correctly populates all properties.\n *\n * See\n * https://github.com/angular/angular.js/blob/2c7400e7d07b0f6cec1817dab40b9250ce8ebce6/src/ng/urlUtils.js#L26-L33\n * for more info.\n */\nlet anchor: HTMLAnchorElement|undefined;\nfunction resolveUrl(url: string): {pathname: string, search: string, hash: string} {\n if (!anchor) {\n anchor = document.createElement('a');\n }\n\n anchor.setAttribute('href', url);\n anchor.setAttribute('href', anchor.href);\n\n return {\n // IE does not start `pathname` with `/` like other browsers.\n pathname: `/${anchor.pathname.replace(/^\\//, '')}`,\n search: anchor.search,\n hash: anchor.hash\n };\n}\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport * from './src/upgrade';\n\n// This file only reexports content of the `src` folder. Keep it that way.\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n// This file is not used to build this module. It is only used during editing\n// by the TypeScript language service and during build for verification. `ngc`\n// replaces this file with production index.ts when it rewrites private symbol\n// names.\n\nexport * from './public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["APP_BOOTSTRAP_LISTENER","UpgradeModule","router","Router","Location"],"mappings":";;;;;;;;;;;;IAAA;;;;;;;AAQA,aA+Bc,6BAAwE;IA1BtF;;;;;;;;;;;;;;;;;;;;;;;AAuBA,QAAa,wBAAwB,GAAG;QACtC,OAAO,EAAEA,2BAAsB;QAC/B,KAAK,EAAE,IAAI;QACX,UAAU,IAA0E;QACpF,IAAI,EAAE,CAACC,qBAAa,CAAC;KACtB,CAAC;IAEF;;;AAGA,aAAgB,6BAA6B,CAAC,SAAwB;QACpE,OAAO,cAAQ,iBAAiB,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IAED;;;;;;;;;;AAUA,aAAgB,iBAAiB,CAAC,SAAwB,EAAE,OAAiC;QAAjC,wBAAA,EAAA,gBAAiC;QAC3F,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,+MAGb,CAAC,CAAC;SACN;QAED,IAAMC,QAAM,GAAW,SAAS,CAAC,QAAQ,CAAC,GAAG,CAACC,aAAM,CAAC,CAAC;QACtD,IAAM,QAAQ,GAAa,SAAS,CAAC,QAAQ,CAAC,GAAG,CAACC,eAAQ,CAAC,CAAC;QAE5D,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC;aAChC,GAAG,CAAC,sBAAsB,EAAE,UAAC,CAAM,EAAE,IAAY,EAAE,EAAU;YAC5D,IAAI,GAAG,CAAC;YACR,IAAI,OAAO,KAAK,MAAM,EAAE;gBACtB,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CA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