1import { provideHttpClient } from '@angular/common/http'; 2import { ApplicationConfig } from '@angular/core'; 3import { provideRouter } from '@angular/router'; 4import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; 5 6import { routes } from './app.routes'; 7import { ACCESS_TOKEN, SERVICE_PORT } from '../service/goldens.service'; 8import { ProgressTracker } from '../util/progress'; 9import { Preferences } from '../util/preferences'; 10import { 11 APP_BASE_HREF, 12 LocationStrategy, 13 PathLocationStrategy, 14 PlatformLocation, 15} from '@angular/common'; 16import { Inject, Injectable, Optional } from '@angular/core'; 17import { UrlSerializer } from '@angular/router'; 18 19const urlParams = new URLSearchParams(window.location.search); 20const token = urlParams.get('token'); 21const port = urlParams.get('port'); 22 23@Injectable() 24export class PreserveQueryParamsPathLocationStrategy extends PathLocationStrategy { 25 private get search(): string { 26 return this.platformLocation?.search ?? ''; 27 } 28 29 constructor( 30 private platformLocation: PlatformLocation, 31 private urlSerializer: UrlSerializer, 32 @Optional() @Inject(APP_BASE_HREF) _baseHref?: string 33 ) { 34 super(platformLocation, _baseHref); 35 } 36 37 override prepareExternalUrl(internal: string): string { 38 const path = super.prepareExternalUrl(internal); 39 const urlTree = this.urlSerializer.parse(path); 40 41 const nextQueryParams = urlTree.queryParams; 42 const existingURLSearchParams = new URLSearchParams(this.search); 43 // const existingQueryParams = Object.fromEntries( 44 // existingURLSearchParams.entries(), 45 // ); 46 urlTree.queryParams = { ...existingURLSearchParams, ...nextQueryParams }; 47 48 return urlTree.toString(); 49 } 50} 51 52export const appConfig: ApplicationConfig = { 53 providers: [ 54 provideRouter(routes), 55 provideHttpClient(), 56 provideAnimationsAsync(), 57 ProgressTracker, 58 Preferences, 59 { provide: ACCESS_TOKEN, useValue: token }, 60 { provide: SERVICE_PORT, useValue: port }, 61 { 62 provide: LocationStrategy, 63 useClass: PreserveQueryParamsPathLocationStrategy, 64 }, 65 ], 66}; 67