@@ -21,7 +21,10 @@ import { LocaleService } from '../../app/core/locale/locale.service';
2121import { HeadTagService } from '../../app/core/metadata/head-tag.service' ;
2222import { CorrelationIdService } from '../../app/correlation-id/correlation-id.service' ;
2323import { InitService } from '../../app/init.service' ;
24- import { isNotEmpty } from '../../app/shared/empty.util' ;
24+ import {
25+ isEmpty ,
26+ isNotEmpty ,
27+ } from '../../app/shared/empty.util' ;
2528import { MenuService } from '../../app/shared/menu/menu.service' ;
2629import { ThemeService } from '../../app/shared/theme-support/theme.service' ;
2730import { Angulartics2DSpace } from '../../app/statistics/angulartics/dspace-provider' ;
@@ -30,6 +33,7 @@ import {
3033 APP_CONFIG_STATE ,
3134 AppConfig ,
3235} from '../../config/app-config.interface' ;
36+ import { BuildConfig } from '../../config/build-config.interface' ;
3337import { environment } from '../../environments/environment' ;
3438
3539/**
@@ -41,7 +45,7 @@ export class ServerInitService extends InitService {
4145 protected store : Store < AppState > ,
4246 protected correlationIdService : CorrelationIdService ,
4347 protected transferState : TransferState ,
44- @Inject ( APP_CONFIG ) protected appConfig : AppConfig ,
48+ @Inject ( APP_CONFIG ) protected appConfig : BuildConfig ,
4549 protected translate : TranslateService ,
4650 protected localeService : LocaleService ,
4751 protected angulartics2DSpace : Angulartics2DSpace ,
@@ -68,9 +72,7 @@ export class ServerInitService extends InitService {
6872 return async ( ) => {
6973 this . checkAuthenticationToken ( ) ;
7074 this . saveAppConfigForCSR ( ) ;
71- if ( this . appConfig . ui . transferState ) {
72- this . saveAppState ( ) ;
73- }
75+ this . saveAppState ( ) ;
7476 this . initCorrelationId ( ) ;
7577
7678 this . checkEnvironment ( ) ;
@@ -92,14 +94,16 @@ export class ServerInitService extends InitService {
9294 * @private
9395 */
9496 private saveAppState ( ) {
95- this . transferState . onSerialize ( InitService . NGRX_STATE , ( ) => {
96- let state ;
97- this . store . pipe ( take ( 1 ) ) . subscribe ( ( saveState : any ) => {
98- state = saveState ;
99- } ) ;
97+ if ( this . appConfig . ssr . transferState && ( isEmpty ( this . appConfig . rest . ssrBaseUrl ) || this . appConfig . ssr . replaceRestUrl ) ) {
98+ this . transferState . onSerialize ( InitService . NGRX_STATE , ( ) => {
99+ let state ;
100+ this . store . pipe ( take ( 1 ) ) . subscribe ( ( saveState : any ) => {
101+ state = saveState ;
102+ } ) ;
100103
101- return state ;
102- } ) ;
104+ return state ;
105+ } ) ;
106+ }
103107 }
104108
105109 private saveAppConfigForCSR ( ) : void {
0 commit comments