Skip to content

Commit

Permalink
fix: set 404 status when route is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Jul 14, 2020
1 parent 39b4091 commit 29570b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/app/core/guards/not-found-status.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';

import { HttpStatusCodeService } from 'ish-core/utils/http-status-code/http-status-code.service';

@Injectable({ providedIn: 'root' })
export class NotFoundStatusGuard implements CanActivate {
constructor(private httpStatusCodeService: HttpStatusCodeService) {}

canActivate(): boolean {
this.httpStatusCodeService.setStatusAndRedirect(404);
return false;
}
}
3 changes: 2 additions & 1 deletion src/app/pages/app-last-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { NotFoundStatusGuard } from 'ish-core/guards/not-found-status.guard';
import { matchCategoryRoute } from 'ish-core/routing/category/category.route';
import { matchProductRoute } from 'ish-core/routing/product/product.route';

Expand All @@ -13,7 +14,7 @@ const routes: Routes = [
matcher: matchCategoryRoute,
loadChildren: () => import('./category/category-page.module').then(m => m.CategoryPageModule),
},
{ path: '**', redirectTo: '/error' },
{ path: '**', children: [], canActivate: [NotFoundStatusGuard] },
];

@NgModule({
Expand Down

0 comments on commit 29570b4

Please sign in to comment.