Browse Source

fix(core): rotue reuse problem

#4019
pull/4021/head
mehmet-erim 7 years ago
parent
commit
df07a8a872
  1. 23
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts

23
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -1,4 +1,4 @@
import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core'; import { Injectable, Injector, NgZone, Optional, SkipSelf } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { Actions, ofActionSuccessful, Store } from '@ngxs/store'; import { Actions, ofActionSuccessful, Store } from '@ngxs/store';
import { noop, Observable } from 'rxjs'; import { noop, Observable } from 'rxjs';
@ -27,7 +27,7 @@ export class LocalizationService {
constructor( constructor(
private actions: Actions, private actions: Actions,
private store: Store, private store: Store,
private router: Router, private injector: Injector,
private ngZone: NgZone, private ngZone: NgZone,
@Optional() @Optional()
@SkipSelf() @SkipSelf()
@ -42,19 +42,22 @@ export class LocalizationService {
this.languageChange.subscribe(({ payload }) => this.registerLocale(payload)); this.languageChange.subscribe(({ payload }) => this.registerLocale(payload));
} }
setRouteReuse(reuse: ShouldReuseRoute) { /**
this.router.routeReuseStrategy.shouldReuseRoute = reuse; *
} * @deprecated To be deleted in v2.9
*/
setRouteReuse(reuse: ShouldReuseRoute) {}
registerLocale(locale: string) { registerLocale(locale: string) {
const { shouldReuseRoute } = this.router.routeReuseStrategy; const router = this.injector.get(Router);
this.setRouteReuse(() => false); const { shouldReuseRoute } = router.routeReuseStrategy;
this.router.navigated = false; router.routeReuseStrategy.shouldReuseRoute = () => false;
router.navigated = false;
return registerLocale(locale).then(() => { return registerLocale(locale).then(() => {
this.ngZone.run(async () => { this.ngZone.run(async () => {
await this.router.navigateByUrl(this.router.url).catch(noop); await router.navigateByUrl(router.url).catch(noop);
this.setRouteReuse(shouldReuseRoute); router.routeReuseStrategy.shouldReuseRoute = shouldReuseRoute;
}); });
}); });
} }

Loading…
Cancel
Save