From 93a57e6724abdf4d59d1663f8c5ad9659f2a910c Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Wed, 26 Jun 2024 11:26:50 +0200 Subject: [PATCH] Add optional altOptions to componentRouteSwap (#9821) --- libs/angular/src/utils/component-route-swap.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/angular/src/utils/component-route-swap.ts b/libs/angular/src/utils/component-route-swap.ts index 1a2db317d6a..1a45671d2be 100644 --- a/libs/angular/src/utils/component-route-swap.ts +++ b/libs/angular/src/utils/component-route-swap.ts @@ -26,27 +26,31 @@ import { Route, Routes } from "@angular/router"; * @param defaultComponent - The default component to render. * @param altComponent - The alternate component to render when the condition is met. * @param shouldSwapFn - The async function to determine if the alternate component should be rendered. - * @param options - The shared route options to apply to both components. + * @param options - The shared route options to apply to the default component, and to the alt component if altOptions is not provided. + * @param altOptions - The alt route options to apply to the alt component. */ export function componentRouteSwap( defaultComponent: Type, altComponent: Type, shouldSwapFn: () => Promise, options: Route, + altOptions?: Route, ): Routes { const defaultRoute = { ...options, component: defaultComponent, }; + const selectedAltOptions = altOptions ?? options; + const altRoute: Route = { - ...options, + ...selectedAltOptions, component: altComponent, canMatch: [ async () => { return await shouldSwapFn(); }, - ...(options.canMatch ?? []), + ...(selectedAltOptions.canMatch ?? []), ], };