From feb69fa4bc3971982ccdd9d04ab04b8df1b55fd8 Mon Sep 17 00:00:00 2001 From: illfixit <66363651+illfixit@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:58:43 +0100 Subject: [PATCH] test: refactored route-config-service --- .../src/app/app-routing.module.ts | 22 +++++++++---------- .../routes/route-config-service.ts | 20 ++++++++++++----- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/authority-portal-frontend/src/app/app-routing.module.ts b/authority-portal-frontend/src/app/app-routing.module.ts index 6bf29ec55..24adba9bc 100644 --- a/authority-portal-frontend/src/app/app-routing.module.ts +++ b/authority-portal-frontend/src/app/app-routing.module.ts @@ -74,17 +74,6 @@ export const LOADING_ROUTES: Routes = [ }, ]; -export const FEATURE_HOME_ROUTE: Routes = [ - { - path: 'home', - component: HomePageComponent, - data: { - requiresRole: ['USER'] satisfies UserRoleDto[], - }, - canActivate: [requiresRole], - }, -]; - const REDIRECT_TO_HOME: string[] = [ '', 'registration/pending', @@ -110,6 +99,17 @@ export const HOME_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({ pathMatch: 'full', })); +export const FEATURE_HOME_ROUTE: Routes = [ + { + path: 'home', + component: HomePageComponent, + data: { + requiresRole: ['USER'] satisfies UserRoleDto[], + }, + canActivate: [requiresRole], + }, +]; + export const AUTHORITY_PORTAL_ROUTES: Routes = [ // participant own connector registration { diff --git a/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts b/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts index 6103dfa77..6e956e17b 100644 --- a/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts +++ b/authority-portal-frontend/src/app/core/global-state/routes/route-config-service.ts @@ -82,14 +82,22 @@ export class RouteConfigService { } // Change routes - const routes = this.mapping[nextPageSet]; + const routes = [...this.mapping[nextPageSet]]; if (nextPageSet === 'AUTHORITY_PORTAL') { - const apRouteChildren = routes.find((r) => r.path === '')?.children; - if (this.activeFeatureSet.isHomePageEnabled()) { - apRouteChildren?.push(...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE); - } else { - apRouteChildren?.push(...CATALOG_REDIRECTS); + const rootRouteIndex = routes.findIndex((r) => r.path === ''); + + if (rootRouteIndex !== -1) { + const rootRoute = routes[rootRouteIndex]; + const existingChildren = rootRoute.children || []; + const newChildren = this.activeFeatureSet.isHomePageEnabled() + ? [...existingChildren, ...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE] + : [...existingChildren, ...CATALOG_REDIRECTS]; + + routes[rootRouteIndex] = { + ...rootRoute, + children: newChildren, + }; } }