import { Injectable , StaticProvider , Inject } from '@angular/core' ; import { ɵBrowserPlatformLocation , PlatformLocation , LocationChangeEvent , LocationChangeListener , DOCUMENT , } from '@angular/common' ; declare const Zone ; @ Injectable ( ) export class SingleSpaPlatformLocation extends ɵBrowserPlatformLocation { private skipNextPopState = false ; private readonly source = 'Window.addEventListener:popstate' ; pushState ( state , title , url ) { this . skipNextPopState = true ; super . pushState ( state , title , url ) ; } replaceState ( state , title , url ) { this . skipNextPopState = true ; super . replaceState ( state , title , url ) ; } onPopState ( fn ) { const zone = Zone . current ; fn = zone . wrap ( fn , this . source ) ; const onPopStateListener = ( event ) => { const popStateEventWasDispatchedBySingleSpa = ! ! ( event as unknown as { singleSpa : boolean ; } ) . singleSpa ; if ( this . skipNextPopState && popStateEventWasDispatchedBySingleSpa ) { this . skipNextPopState = false ; } else { fn ( event ) ; } } ; return super . onPopState ( onPopStateListener ) ; } } /**
 * The `PlatformLocation` class is an "injectee" of the `PathLocationStrategy`,
 * which creates `Subject` internally for listening on `popstate` events. We want
 * to provide this class in the most top injector that's used during bootstrapping.
 */ export function getSingleSpaExtraProviders ( ) { return [ { provide : SingleSpaPlatformLocation , deps : [ [ new Inject ( DOCUMENT ) ] ] , } , { provide : PlatformLocation , useExisting : SingleSpaPlatformLocation , } , ] ; }