mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(test): rename project to feat upcoming challenges
This commit is contained in:
20
apps/testing-router-outlet/src/app/book.guard.ts
Normal file
20
apps/testing-router-outlet/src/app/book.guard.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Router } from '@angular/router';
|
||||
import { availableBooks } from './book.model';
|
||||
|
||||
export const bookGuard = (
|
||||
route: ActivatedRouteSnapshot,
|
||||
router = inject(Router)
|
||||
) => {
|
||||
const searchParam = route.queryParams?.['book'].toLowerCase();
|
||||
|
||||
const isBookAvailable =
|
||||
!!searchParam &&
|
||||
availableBooks.some(
|
||||
(b) =>
|
||||
b.author.toLowerCase().includes(searchParam) ||
|
||||
b.name.toLowerCase().includes(searchParam)
|
||||
);
|
||||
|
||||
return isBookAvailable || router.parseUrl('no-result');
|
||||
};
|
||||
Reference in New Issue
Block a user