fix(ui): avoid CSS transition on page navigation (#1833)
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { afterNextRender, inject, Injectable, Injector } from '@angular/core';
|
||||||
|
import { NavigationEnd, Router } from '@angular/router';
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class NavigationTransitionGuard {
|
||||||
|
private readonly root = inject(DOCUMENT).documentElement;
|
||||||
|
private readonly injector = inject(Injector);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
inject(Router).events.subscribe((event) => {
|
||||||
|
if (event instanceof NavigationEnd) {
|
||||||
|
this.root.classList.add('route-settling');
|
||||||
|
afterNextRender(() => this.release(), { injector: this.injector });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private release(): void {
|
||||||
|
getComputedStyle(this.root).getPropertyValue('opacity');
|
||||||
|
setTimeout(() => this.root.classList.remove('route-settling'), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -173,3 +173,9 @@ hr {
|
|||||||
transition-duration: 0.01ms !important;
|
transition-duration: 0.01ms !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.route-settling *,
|
||||||
|
html.route-settling *::before,
|
||||||
|
html.route-settling *::after {
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { RxStompService } from './app/shared/websocket/rx-stomp.service';
|
|||||||
import { rxStompServiceFactory } from './app/shared/websocket/rx-stomp-service-factory';
|
import { rxStompServiceFactory } from './app/shared/websocket/rx-stomp-service-factory';
|
||||||
import { provideRouter, RouteReuseStrategy } from '@angular/router';
|
import { provideRouter, RouteReuseStrategy } from '@angular/router';
|
||||||
import { CustomReuseStrategy } from './app/core/custom-reuse-strategy';
|
import { CustomReuseStrategy } from './app/core/custom-reuse-strategy';
|
||||||
|
import { NavigationTransitionGuard } from './app/core/navigation-transition-guard';
|
||||||
import { providePrimeNG } from 'primeng/config';
|
import { providePrimeNG } from 'primeng/config';
|
||||||
import { bootstrapApplication } from '@angular/platform-browser';
|
import { bootstrapApplication } from '@angular/platform-browser';
|
||||||
import { AppComponent } from './app/app.component';
|
import { AppComponent } from './app/app.component';
|
||||||
@@ -41,6 +42,9 @@ bootstrapApplication(AppComponent, {
|
|||||||
const startup = inject(StartupService);
|
const startup = inject(StartupService);
|
||||||
return Promise.resolve(initializeAuth()).then(() => startup.load());
|
return Promise.resolve(initializeAuth()).then(() => startup.load());
|
||||||
}),
|
}),
|
||||||
|
provideAppInitializer(() => {
|
||||||
|
inject(NavigationTransitionGuard);
|
||||||
|
}),
|
||||||
provideHttpClient(withInterceptors([AuthInterceptorService])),
|
provideHttpClient(withInterceptors([AuthInterceptorService])),
|
||||||
provideRouter(routes),
|
provideRouter(routes),
|
||||||
DialogService,
|
DialogService,
|
||||||
|
|||||||
Reference in New Issue
Block a user