import { ComponentFactory, ComponentFactoryResolver } from '@angular/core'; import { Location } from '@angular/common'; import { App } from '../components/app/app'; import { convertToViews, DIRECTION_BACK, isNav, isTab, isTabs, NavLink, NavSegment } from './nav-util'; import { ModuleLoader } from '../util/module-loader'; import { isArray, isPresent } from '../util/util'; import { Nav } from '../components/nav/nav'; import { NavController } from './nav-controller'; import { Tab } from '../components/tabs/tab'; import { Tabs } from '../components/tabs/tabs'; import { UrlSerializer } from './url-serializer'; import { ViewController } from './view-controller'; /** * @hidden */ export class DeepLinker { /** @internal */ _segments: NavSegment[] = []; /** @internal */ _history: string[] = []; /** @internal */ _indexAliasUrl: string; constructor( public _app: App, public _serializer: UrlSerializer, public _location: Location, public _moduleLoader: ModuleLoader, public _baseCfr: ComponentFactoryResolver ) {} /** * @internal */ init() { // scenario 1: Initial load of all navs from the initial browser URL const browserUrl = normalizeUrl(this._location.path()); console.debug(`DeepLinker, init load: ${browserUrl}`); // update the Path from the browser URL this._segments = this._serializer.parse(browserUrl); // remember this URL in our internal history stack this._historyPush(browserUrl); // listen for browser URL changes this._location.subscribe((locationChg: { url: string }) => { this._urlChange(normalizeUrl(locationChg.url)); }); } /** * The browser's location has been updated somehow. * @internal */ _urlChange(browserUrl: string) { // do nothing if this url is the same as the current one if (!this._isCurrentUrl(browserUrl)) { if (this._isBackUrl(browserUrl)) { // scenario 2: user clicked the browser back button // scenario 4: user changed the browser URL to what was the back url was // scenario 5: user clicked a link href that was the back url console.debug(`DeepLinker, browser urlChange, back to: ${browserUrl}`); this._historyPop(); } else { // scenario 3: user click forward button // scenario 4: user changed browser URL that wasn't the back url // scenario 5: user clicked a link href that wasn't the back url console.debug(`DeepLinker, browser urlChange, forward to: ${browserUrl}`); this._historyPush(browserUrl); } // get the app's root nav const appRootNav =