1 page html with 2 different path and 2 two different guard in angular, rxjx

41 Views Asked by At

Good morning, in my layout I have this dynamic path. When the user presses on the 2 menu items relating to the final part of the path ":subject" it changes to "hospital" or "home" creating 2 different APIs. The problem is that the first CercaOspedaleGuard guard must be activated only if the html page has hospital in the path and CercaCasaGuad only if the path contains the value house. I tried to create a dynamic guard that combined the 2 but I couldn't.

,
              {
                path: 'domus/:soggetto' , loadChildren:()=> import('../features/domus/domus.routes').then((m)=>m.DOMUS_ROUTES),
                data:{breadcrumb: 'Domus'},
                canActivate: [CercaOspedaleGuard, CercaCasaGuard]
              },

thi'is example of myguard

import {inject} from '@angular/core';
import {Router,} from '@angular/router';
import {Store} from "@ngrx/store";
import {map} from "rxjs/operators";
import {selectIsSetCercaCercaOspedaleActive} from "../store";


export const CercaOspedaleGuard = () => {
  const store = inject(Store);
  const router = inject(Router);

  return store.select(selectIsSetCercaCercaOspedaleActive).pipe(
      map( (isSetCercaCercaOspedaleActive: boolean) => {
          // console.log('CercaOspedaleGuard:isSetCercaOspedaleActive:',isSetCercaOspedaleActive);
          if(!isSetCercaOspedaleActive){
            return router.createUrlTree(['/servizi/cerca-ospedale']);
        }
        return true;
      })
  );
};

Could you advise me? The guards taken individually or in pairs work, but I can't get only 1 of the 2 to work based on the path. I can separate the path and create two different html page, but i don't want

0

There are 0 best solutions below