mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
93219: Support Router in InitService
For Router to work properly, APP_BASE_HREF must be resolved _before_ the APP_INITIALIZER factory is called (otherwise Angular will attempt to initialize APP_BASE_HREF too soon) To fix this we add a pre-initialization hook to APP_CONFIG so BrowserInitService can resolve it before APP_INITIALIZER
This commit is contained in:
@@ -31,10 +31,17 @@ export class BrowserInitService extends InitService {
|
||||
super(store, correlationIdService, dspaceTransferState);
|
||||
}
|
||||
|
||||
public init(): () => Promise<boolean> {
|
||||
// this method must be called before the callback because APP_BASE_HREF depends on it
|
||||
this.loadAppConfigFromSSR();
|
||||
protected static resolveAppConfig(
|
||||
transferState: TransferState,
|
||||
) {
|
||||
if (transferState.hasKey<AppConfig>(APP_CONFIG_STATE)) {
|
||||
const appConfig = transferState.get<AppConfig>(APP_CONFIG_STATE, new DefaultAppConfig());
|
||||
// extend environment with app config for browser
|
||||
extendEnvironmentWithAppConfig(environment, appConfig);
|
||||
}
|
||||
}
|
||||
|
||||
protected init(): () => Promise<boolean> {
|
||||
return async () => {
|
||||
await this.transferAppState();
|
||||
this.checkAuthenticationToken();
|
||||
@@ -43,12 +50,4 @@ export class BrowserInitService extends InitService {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
private loadAppConfigFromSSR(): void {
|
||||
if (this.transferState.hasKey<AppConfig>(APP_CONFIG_STATE)) {
|
||||
const appConfig = this.transferState.get<AppConfig>(APP_CONFIG_STATE, new DefaultAppConfig());
|
||||
// extend environment with app config for browser
|
||||
extendEnvironmentWithAppConfig(environment, appConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user