1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 14:23:32 +00:00

Add optional altOptions to componentRouteSwap (#9821)

This commit is contained in:
Bernd Schoolmann
2024-06-26 11:26:50 +02:00
committed by GitHub
parent 3f44eadb5f
commit 93a57e6724

View File

@@ -26,27 +26,31 @@ import { Route, Routes } from "@angular/router";
* @param defaultComponent - The default component to render. * @param defaultComponent - The default component to render.
* @param altComponent - The alternate component to render when the condition is met. * @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 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( export function componentRouteSwap(
defaultComponent: Type<any>, defaultComponent: Type<any>,
altComponent: Type<any>, altComponent: Type<any>,
shouldSwapFn: () => Promise<boolean>, shouldSwapFn: () => Promise<boolean>,
options: Route, options: Route,
altOptions?: Route,
): Routes { ): Routes {
const defaultRoute = { const defaultRoute = {
...options, ...options,
component: defaultComponent, component: defaultComponent,
}; };
const selectedAltOptions = altOptions ?? options;
const altRoute: Route = { const altRoute: Route = {
...options, ...selectedAltOptions,
component: altComponent, component: altComponent,
canMatch: [ canMatch: [
async () => { async () => {
return await shouldSwapFn(); return await shouldSwapFn();
}, },
...(options.canMatch ?? []), ...(selectedAltOptions.canMatch ?? []),
], ],
}; };