diff --git a/src/app/core/guards/error-status.guard.ts b/src/app/core/guards/error-status.guard.ts new file mode 100644 index 00000000000..ccbecfef33c --- /dev/null +++ b/src/app/core/guards/error-status.guard.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, Router } from '@angular/router'; +import { map } from 'rxjs'; + +import { AppFacade } from 'ish-core/facades/app.facade'; + +@Injectable({ providedIn: 'root' }) +export class ErrorStatusGuard implements CanActivate { + constructor(private appFacade: AppFacade, private router: Router) {} + canActivate() { + return this.appFacade.generalError$.pipe(map(error => (!error ? this.router.parseUrl('/home') : true))); + } +} diff --git a/src/app/pages/app-routing.module.ts b/src/app/pages/app-routing.module.ts index 3fb99465cef..d13e6a687cc 100644 --- a/src/app/pages/app-routing.module.ts +++ b/src/app/pages/app-routing.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { AuthGuard } from 'ish-core/guards/auth.guard'; +import { ErrorStatusGuard } from 'ish-core/guards/error-status.guard'; import { IdentityProviderInviteGuard } from 'ish-core/guards/identity-provider-invite.guard'; import { IdentityProviderLoginGuard } from 'ish-core/guards/identity-provider-login.guard'; import { IdentityProviderLogoutGuard } from 'ish-core/guards/identity-provider-logout.guard'; @@ -33,6 +34,7 @@ const routes: Routes = [ { path: 'maintenance', loadChildren: () => import('./maintenance/maintenance-page.module').then(m => m.MaintenancePageModule), + canActivate: [ErrorStatusGuard], data: { meta: { title: 'seo.title.maintenance',