Skip to content

Commit

Permalink
feat: display error/maintenance page only if the error still exists o…
Browse files Browse the repository at this point in the history
…therwise route to the home page
  • Loading branch information
SGrueber committed Sep 7, 2022
1 parent ed7694e commit 09f0073
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app/core/guards/error-status.guard.ts
Original file line number Diff line number Diff line change
@@ -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)));
}
}
3 changes: 3 additions & 0 deletions src/app/pages/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,6 +24,7 @@ const routes: Routes = [
{
path: 'error',
loadChildren: () => import('./error/error-page.module').then(m => m.ErrorPageModule),
canActivate: [ErrorStatusGuard],
data: {
meta: {
title: 'seo.title.error',
Expand All @@ -33,6 +35,7 @@ const routes: Routes = [
{
path: 'maintenance',
loadChildren: () => import('./maintenance/maintenance-page.module').then(m => m.MaintenancePageModule),
canActivate: [ErrorStatusGuard],
data: {
meta: {
title: 'seo.title.maintenance',
Expand Down

0 comments on commit 09f0073

Please sign in to comment.