Merge branch 'fix-mutliple-api-calls-on-route-change-7.6' into fix-mutliple-api-calls-on-route-change

This commit is contained in:
Art Lowel
2023-09-22 12:01:24 +02:00
2 changed files with 8 additions and 2 deletions

View File

@@ -63,16 +63,18 @@ describe('ServerCheckGuard', () => {
});
describe(`listenForRouteChanges`, () => {
it(`should invalidate the root cache on every NavigationStart event`, () => {
it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => {
testScheduler.run(() => {
guard.listenForRouteChanges();
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1);
eventSubject.next(new NavigationStart(1,''));
eventSubject.next(new NavigationEnd(1,'', ''));
eventSubject.next(new NavigationStart(2,''));
eventSubject.next(new NavigationEnd(2,'', ''));
eventSubject.next(new NavigationStart(3,''));
});
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3);
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4);
});
});
});

View File

@@ -52,6 +52,10 @@ export class ServerCheckGuard implements CanActivateChild {
* operation, the cached version is used.
*/
listenForRouteChanges(): void {
// we'll always be too late for the first NavigationStart event with the router subscribe below,
// so this statement is for the very first route operation
this.rootDataService.invalidateRootCache();
this.router.events.pipe(
filter(event => event instanceof NavigationStart),
).subscribe(() => {