exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

root.routes.ts (951B)


      1 import { inject } from '@angular/core';
      2 import { Route, Routes } from '@angular/router';
      3 import { CartService } from './services/cart.service';
      4 import { NotificationService } from './services/notification.service';
      5 
      6 export const routes: Routes = [
      7   {
      8     path: '',
      9     redirectTo: 'products',
     10     pathMatch: 'full',
     11   },
     12   {
     13     path: 'products',
     14     loadChildren: () => import('./products/products.routes').then((m) => m.PRODUCT_ROUTES),
     15   },
     16   {
     17     path: 'checkout',
     18     loadComponent: () => import('./cart/checkout.component').then((m) => m.CheckoutComponent),
     19     canActivate: [
     20       () => {
     21         const isEmpty = inject(CartService).isEmpty();
     22         if (isEmpty) {
     23           inject(NotificationService).show(
     24             'Your cart is empty. Please add items before proceeding to checkout.',
     25             'danger',
     26           );
     27         }
     28         return !isEmpty;
     29       },
     30     ],
     31   },
     32   {
     33     path: '**',
     34     redirectTo: 'products',
     35   },
     36 ];